[Haskell-beginners] newtype record syntax

Tom Doris tomdoris at gmail.com
Wed Jul 14 05:39:23 EDT 2010


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?

The only docs I can find that cover this are in the language report itself:

>|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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100714/54093699/attachment.html


More information about the Beginners mailing list