I am ploughing through Learn You a Haskell for Great Good, and I have reached up to section 8.4, "Derived Instances". In this section, there's the following data type declaration:
data Person = Person { firstName :: String
, lastName :: String
, age :: Int
} deriving (Eq)
While trying
*Main> mikeD == Person {firstName = "Michael", lastname = "Diamond", age = 43}
I got the following error:
<interactive>:55:41:
`lastname' is not a (visible) field of constructor `Person'
By correcting lastname
to lastName
I removed the error.
Question:
In the error message the word (visible)
hints to me that there must be the possibility of declaring a field as hidden / invisible. Is this correct or not? If it is, how can I declare a field in the constructor as hidden, and what are the general scenarios where one would need to declare hidden fields? If you could explain this by giving a simple example of their use, that would be appreciated.
Note: I could not find any reference to/details about hidden or invisible field in LYAH.
module MyModule (DT(C1, int))
only exportsint
, but notstr
. Also note that yourDT(C1)
does not export any of the fields, soint
andstr
are invisible in your code sample. – Comparable