-----------------------------------------------------------------------------
-- Tree data type.
-data Tree a = Leaf | Node (Tree a, a, Tree a) deriving (Show)
+data Tree a = Leaf | Node (Tree a) a (Tree a) deriving (Show)
-- Return the elements inorder, as a list.
fringe t = gather t [] where
gather Leaf ns = ns
- gather (Node (l, x, r)) ns = gather l (x : gather r ns)
+ gather (Node l x r) ns = gather l (x : gather r ns)
-- Answer whether two trees have the same fringe.
sameFringe t tt = fringe t == fringe tt -- trivial!
case r of
Just '(' -> do
step; left <- tree; c <- anytok "no data"; right <- tree; delim ')'
- return $ Node (left, c, right)
+ return $ Node left c right
_ -> return Leaf
-----------------------------------------------------------------------------