[Haskell-beginners] Empty or Tree?

Aditya Manthramurthy aditya.mmy at gmail.com
Sat Mar 10 11:57:50 CET 2012


I think this is because "Tree" is a data type and not a data constructor.
According to your definition of Tree, Empty and Node are the constructors.

Node a (Node b (Node c Empty Empty) (Node d Empty Empty)) (Node e (Node f
Empty Empty) (Node g Empty Empty))

is a valid tree if a, b, c, d, e, f, g are integers.

Hope this helps.

--
Aditya.

On 10 March 2012 15:58, bahadýr altan <doaltan at yahoo.co.uk> wrote:

> Hello everyone. I'm trying to write a code which works on binary trees.
> When I write code like this  with a tree with empty nodes :
>
> data Tree  =  Empty | Node  Integer Tree Tree
>
> function Node a (Node b Empty Empty)  (Node c Empty Empty)
>
> it works fine.
> But when I try to create a more generic code like this  which could  work
> with trees who don't have empty nodes in grandchild level :
>
> function Node a (Node b Tree Tree)  (Node c Tree Tree )
>
> I get this error : Undefined data constructor "Tree"
>
> Can you help me with creating more generic code please?
> Thanks
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120310/9588e1d2/attachment.htm>


More information about the Beginners mailing list