purescript / purescript

A strongly-typed language that compiles to JavaScript
https://www.purescript.org
Other
8.57k stars 564 forks source link

Cannot mix puns and labels in update syntax #1790

Closed user471 closed 8 years ago

user471 commented 8 years ago
foo = 1
x = {foo, bar : 2}
y = x {foo, bar = 2}
Unable to parse module:
   unexpected {
   expecting no indentation or end of input
garyb commented 8 years ago

Puns don't work in update syntax and are not ever intended to do so, as it's ambiguous.

x { foo, bar } would be passing a new record to x, x { foo, bar = 2 } would be modifying x.

user471 commented 8 years ago

Could PureScript have less ambiguous update syntax? Elm

{ x | foo = 1}

F#

{x with foo = 1}

maybe just add optional keyword?

x with {foo = 1}
garyb commented 8 years ago

Yeah, maybe. I quite like the elm version as it's similar to the types (and doesn't unnecessarily reserve a word). If/when we have record constraints it might be useful as a way of differentiating between adding a field to a record and updating a field too.

user471 commented 8 years ago

Should I open a new issue?

garyb commented 8 years ago

Yes please :smile: