> 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
If you want the BTree to contain only Integers, then just write:
> data BTree
> = Leaf Integer | Node Integer (BTree Integer) (BTree Integer)
> mkTree :: Integer -> BTree
If you want it to be polymorphic, then write:
> data BTree a
> = Leaf a | Node a (BTree a) (BTree a)
> mkTree :: Integer -> BTree Integer
You could also make mkTree polymorphic, but because you are doing
arithmetic on the argument, the type must be constrained to be a member
of the Num class, in which case you would write:
> mkTree :: Num a => a -> BTree a
-Paul