fork(8) download
  1. data Tree a = Node a (Tree a) (Tree a) | Tip
  2.  
  3. flatten :: Tree a -> [a]
  4. flatten x = (flatten' x) []
  5.  
  6. flatten' :: Tree a -> [a] -> [a]
  7. flatten' (Node x left right) l = (flatten' left (x:(flatten' right l)))
  8. flatten' Tip l = l
  9.  
  10. main =
  11. putStrLn $ show $ flatten $
  12. (Node 2 (Node 1 Tip Tip) (Node 4 (Node 3 Tip Tip) Tip))
Success #stdin #stdout 0.02s 3592KB
stdin
Standard input is empty
stdout
[1,2,3,4]