You need explicit type annotations when GADTs are involved:
abigail :: Person abigail = let x :: Person x Name = "Abigail" x Age = 27 in x
Without this, the GHC roughly sees
let x Name = "Abigail"
and says: "OK, x is a function from the type Name , that is, PersonField String to the type "Abigail" , ie String . In the next line
let x Name = "Abigail" x Age = 27
Now the GHC detects x to accept also a PersonField Int and return a number. This is due to a previously entered type, causing a type error.
With an explicit type annotation, type inference will not try to infer the wrong type for x : it was provided by the user. Instead, only type checking will be performed.
source share