<div><div dir="auto">On Tue, 30 Oct 2018 at 4:20 PM, Anthony Clayden wrote:</div><br></div><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" style="font-size:1rem"><br></div><div dir="auto" style="font-size:1rem">> <span style="white-space:pre-wrap;background-color:rgb(255,255,255);font-size:1rem">data Person = Person {name::String, age::Int} deriving Show</span></div><pre style="white-space:pre-wrap;background-color:rgb(255,255,255)"><div dir="auto" style="color:rgb(49,49,49);font-size:1rem;word-spacing:1px">>
> Now, I can create maybe-people like in applicative style:
>
> Person <$> Just "John Doe" <*> Nothing
<br></div><div dir="auto" style="color:rgb(49,49,49);font-size:1rem;word-spacing:1px"><br></div><div dir="auto" style="color:rgb(49,49,49);font-size:1rem;word-spacing:1px">... field labels for building records only work</div><div dir="auto" style="color:rgb(49,49,49);font-size:1rem;word-spacing:1px">in very restricted syntactic positions, ...</div></pre></blockquote><div dir="auto"><br></div><div dir="auto">To tease out that remark a little:</div><div dir="auto"><br></div><div dir="auto">Data constructor `Person` is first-class; we could go</div><div dir="auto"><br></div><div dir="auto">person' = Person</div><div dir="auto"><br></div><div dir="auto">person' <$> Just "John Doe" <*> Nothing</div><div dir="auto"><br></div><div dir="auto">But the following two are nothing like equivalent; so record syntax is not even referentially transparent:</div><div dir="auto"><br></div><div dir="auto">Person{ name = "Jane Roe", age = 37 } -- builds a Person record</div><div dir="auto"><br></div><div dir="auto">person'{ name = "Jane Roe", age = 37 }</div><div dir="auto"><br></div><div dir="auto">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.</div><div dir="auto"><br></div><div dir="auto">Then `person'` is the wrong type, and you'll get a type error.</div><div dir="auto"><br></div><div dir="auto">Although both look like a name (of function type) adjacent to a term { in braces}, neither is function application.</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">AntC</div></div></div>