Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data BinTree a = Leaf | Node a (BinTree a) (BinTree a)
  2.  
  3. collapse :: BinTree a -> (a -> b -> b -> b) -> b -> b
  4. collapse (Leaf) _ x = x
  5. collapse (Node a left right) f x = f a (collapse left f x) (collapse right f x)
  6.  
  7. treeToList :: BinTree a -> [a]
  8. treeToList t = collapse t helper []
  9.     where
  10.         helper x y z = [x] ++ y ++ z
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement