| 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)
| ...
| 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
Yes. The parameters in a datatype definition are supposed to be type
variables, not type constants like Integer. If you only need BTrees
with Integer values in them, then you don't need a parameter --- use:
data BTree = Leaf Integer | Node Integer BTree BTree
and then mkTree will be a function of type Integer -> BTree.
If you want a parameter, use:
data BTree a = Leaf a | Node a (BTree a) (BTree a)
and then mkTree will be a function of type Integer -> BTree Integer.
(or Num a => a -> BTree a, in its most general form.)
All the best,
Mark