[Haskell-beginners] Type Tree variables

Ozgur Akgun ozgurakgun at gmail.com
Sun Mar 11 15:47:59 CET 2012


Hi,

Please reply to the list so others can contribute.

On 11 March 2012 14:42, bahadýr altan <doaltan at yahoo.co.uk> wrote:

> I'm sorry if I mislead you, I think I didn't mention my problem clearly
> there. I'm actually stuck in the position of declaring subtrees, I couldn't
> find a solution to that.
>
> My function is like
>
> f :: Tree -> Tree
>
> And my tree structure is like
>
> data Tree = Empty | Branch Integer Tree Tree
>
> And When I write this which I learned from you :
> (c1, c2, d1, d2, e1, e2 :: Tree)
>
> I get error. If you tell me How should I solve that I'd appreciate.
>

Hence I was suggesting to think about the types of the pattern variables.

f (Branch x (Branch y y1 y2) (Branch z z1 z2)) = (x,y,y1,y2,z,z1,z2)

This definition will work, and return a 7-tuple given a Tree. Try to load
this into ghci and see what the type of f is (:t f).
One hint: y and y1 aren't of the same type.

Ozgur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120311/73dfbcad/attachment.htm>


More information about the Beginners mailing list