> Bob Howard wrote:
>
> Ok my last post was a bit of a silly question on my behalf, but this
> has be stumped.
>
> data BTree Integer = Leaf Integer | Node Integer (BTree Integer)
> (BTree Integer)
> mkTree :: Integer -> BTree
> mkTree 0 = Leaf 0
> mkTree int = Node int (mkTree (int - 1)) (mkTree (int -1))
>
> Forgetting anyother problems that may be in this code, can anyone tell
> me why I get this error when I compile this.
> ERROR "Btree.hs" (line 2): Illegal left hand side in datatype
> definition
> Bob
The "data BTree Integer" is not syntactically correct. The format is
like "data <TypeName> <polyVar1> <polyVar2> ... <polyVarN> = ...", where
polyVar is a polymorphic type variable. Type variables must start with a
lower-case letter. I suspect that what you eventually want is something
like this:
data BTree a = Leaf a | Node a (BTree a)
However, just to get things working, you can remove the type variable
and use:
data BTree = Leaf Integer | Node Integer (BTree Integer)
- Michael Hobbs