data Tree x = Leaf x | Node x [Tree x] dfs tree limit | limit == 0 = [] case tree of Leaf x -> [x] Node x children -> x : traverse children (limit - 1) traverse children limit | limit == 0 = [] case children of [] -> [] x : rest -> where result = dfs x limit example_tree = Node 0 [ Node 1 [Leaf 2, Leaf 3], Node 4 [Node 5 [Leaf 6]], Leaf 7 ] main = do
Standard input is empty