I am trying to define a multi-way tree data type in ghci. Each node has a key and a value. Here is the related code:
data Tree k v = Empty |
N {key::k,
value::v} [Tree k v]
deriving (Show, Eq)
Here is corresponding output from Ghci:
Not in scope: `key'
Not in scope: `value'
I checked the syntax of the record by defining the tree node record separately using the following code:
data Node k v = Node { key::k
, value::v}
deriving (Show, Eq)
This works as expected. What is causing my Tree data type definition to throw this error? Am I missing something related to record syntax when used to define an alternate value constructor?
keyandvalueare now functions that might override any other definition. This is why you usually seetreeValueinstead of justvalue.