[email protected]
[Top] [All Lists]

Re: [Haskell-cafe] help in tree folding

Subject: Re: [Haskell-cafe] help in tree folding
From: "Luke Palmer"
Date: Tue, 6 May 2008 08:31:26 -0600
On Tue, May 6, 2008 at 6:20 AM, patrik osgnach <[email protected]> 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)

Functions like this are very abstract, but are also quite nice in that
there's basically only one way to write them given the types.

What have you tried so far?  This function needs to be recursive, so
what arguments should it give to its recursive calls, and where should
it plug the results?

It also helps, as you're writing, to keep meticulous track of the the
types of everything you have and the type you need, and that will tell
you what you need to write next.

Haskell-Cafe mailing list
[email protected]
<Prev in Thread] Current Thread [Next in Thread>