Can someone give an explanation of the use of record syntax in newtype declarations that helps one understand how it's meant to be interpreted? I understand the "facts" according to the language definition, but I just don't see why this notation was used; does it have any relationship with records?
>|A newtype declaration may use field-naming syntax, though of course there may only be one field. Thus:
>| newtype Age = Age { unAge :: Int }
>|brings into scope both a constructor and a de-constructor:
>| Age :: Int -> Age
>| unAge :: Age -> Int
I understand what this says, I just don't understand why Haskell does it this way - unAge ends up defining a function, using the notation used to declare a field in a record, and the type of the function is inferred from the type of the field and the constructor - it just seems a bit barmy. I'd appreciate anyone who can help, or a reference to some docs that make sense of this.
Thanks
t