[Haskell-beginners] newtype record syntax

Tom Doris tomdoris at gmail.com
Wed Jul 14 07:41:52 EDT 2010


Yes, makes sense, I always thought of the projection functions as being
secondary. Thanks

On 14 July 2010 11:00, Brent Yorgey <byorgey at seas.upenn.edu> wrote:

> On Wed, Jul 14, 2010 at 10:39:23AM +0100, Tom Doris wrote:
> > 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?
>
> Yes, the reason this notation is used is that it corresponds exactly
> to defining a record containing one field.  Declaring field names in a
> record really just gives you some projection functions to get the
> fields out (and also some pattern-matching magic); declaring a field
> name in a newtype gives you a projection function to unwrap the
> newtype.
>
> Does that help?
>
> -Brent
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100714/e88edef4/attachment-0001.html


More information about the Beginners mailing list