Hi
I've defined a Tree data type in Haskell and an associated 'size' method which calculates the number of elements in the tree. This worked before, however I have updated the Tree data type to use named fields as in the following definition:
data Tree a = Empty
| Leaf {value::a}
| Node {left :: (Tree a), value :: a, right :: (Tree a)}
deriving (Eq, Ord, Show)
I've found (by playing around in GHCi) that I can access a named field using the function (left n) for example. However, when I try to use this function I get an error:
size :: Tree a -> Int
size Empty = 0
size (Leaf l) = 1
size (Node n) = size (left n) + 1 + size (right n)
GHCi simply says "Not in scope: left" and the equivalent for right. The Tree definition is in a module called Tree and the size definition is in a module called Main, but with the non-named fields I never had a problem with scope when it came to accessing variables from the Tree datatype.