Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: Lifting over record syntax (Anthony Clayden) ---------------------------------------------------------------------- Message: 1 Date: Wed, 31 Oct 2018 22:52:21 +1300 From: Anthony Clayden <anthony_clay...@clear.net.nz> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Lifting over record syntax Message-ID: <CAM7nRYShhpw9Upj=semm0snsd3fmtuxavmocpzqt6ad+uc2...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" On Tue, 30 Oct 2018 at 4:20 PM, Anthony Clayden wrote: > > data Person = Person {name::String, age::Int} deriving Show > > > > > Now, I can create maybe-people like in applicative style: > > > > Person <$> Just "John Doe" <*> Nothing > > ... field labels for building records only work > in very restricted syntactic positions, ... > > To tease out that remark a little: Data constructor `Person` is first-class; we could go person' = Person person' <$> Just "John Doe" <*> Nothing But the following two are nothing like equivalent; so record syntax is not even referentially transparent: Person{ name = "Jane Roe", age = 37 } -- builds a Person record person'{ name = "Jane Roe", age = 37 } In the second, the token preceding the `{ ... }` is not a data constructor (because it starts lower case), so is taken to be a variable/expression denoting a value of type `Person`; and this is datatype update syntax. Why of type `Person`? Because field labels `name` and `age` come from there, and under H98 records, they can be associated only with a single type. Then `person'` is the wrong type, and you'll get a type error. Although both look like a name (of function type) adjacent to a term { in braces}, neither is function application. AntC -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20181031/c96560eb/attachment-0001.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 124, Issue 16 ******************************************