[Haskell-cafe] help in tree folding
Brent Yorgey
byorgey at gmail.com
Tue May 6 10:42:56 EDT 2008
On Tue, May 6, 2008 at 8:20 AM, patrik osgnach <patrik.osgnach at gmail.com>
wrote:
> Hi. I'm learning haskell but i'm stuck on a generic tree folding exercise.
> i must write a function of this type
> treefoldr::(Eq a,Show a)=>(a->b->c)->c->(c->b->b)->b->Tree a->c
> Tree has type
> data (Eq a,Show a)=>Tree a=Void | Node a [Tree a] deriving (Eq,Show)
> as an example treefoldr (:) [] (++) [] (Node '+' [Node '*' [Node 'x' [],
> Node 'y' []], Node 'z' []])
> must return "+∗xyz"
> any help?
> (sorry for my bad english)
>
Having a (Tree a) parameter, where Tree is defined as an algebraic data
type, also immediately suggests that you should do some pattern-matching to
break treefoldr down into cases:
treefoldr f y g z Void = ?
treefoldr f y g z (Node x t) = ?
-Brent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080506/b395260e/attachment.htm
More information about the Haskell-Cafe
mailing list