Reputation: 49
I defined the tree type with record syntax way.
data Tree a = Null | Node a {lTree:: Tree a, rTree :: Tree a}
However, when I load it, it shows an error:
• Record syntax is illegal here: {lTree :: Tree a, rTree :: Tree a}
• In the type ‘{lTree :: Tree a, rTree :: Tree a}’
In the definition of data constructor ‘Node’
In the data declaration for ‘Tree’
|
2 | data Tree a = Null | Node a {lTree:: Tree a, rTree :: Tree a}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Upvotes: 2
Views: 774
Reputation: 477814
The a
should also be part of the record syntax, for example:
data Tree a = Null | Node {valTree :: a, lTree:: Tree a, rTree :: Tree a}
You can not "mix" record syntax with positional syntax as is specified by the Haskell grammar in the Haskell '98 report:
constr -> con [!] atype1 ... [!] atypek (arity con = k, k>=0) | (btype | ! atype) conop (btype | ! atype) (infix conop) | con { fielddecl1 , ... , fielddecln } (n>=0)
Upvotes: 10