hkust-taco / mlscript

The MLscript programming language. Functional and object-oriented; structurally typed and sound; with powerful type inference. Soon to have full interop with TypeScript!
https://hkust-taco.github.io/mlscript
MIT License
171 stars 26 forks source link

Introduce comma operator and use `,`/`;` instead of `;`/`;;` #204

Closed LPTK closed 9 months ago

LPTK commented 9 months ago

The use of the ;; statement separator and a ; sequencing operator, which was inspired by OCaml, just felt too weird an unnatural. Let's go back to something most programmers will more likely already be familiar with.

A nice thing with the comma operator is that it gives us a way of succinctly but clearly discarding return values, by writing foo(123), () instead of let _ = foo(123) in () or discard(foo(123)).

A cons is that the meaning of the comma kind of becomes overloaded.

Another cons is that because we want to be consistent, we want to parse if ... then foo(), 1 else bar(), 2 as if ... then (foo(), 1) else (bar(), 2), but this means if-then-elses now need parentheses when used in an argument list, as in baz(A , (if ... then B1 else B2), C).

The PR also makes a couple of improvements here and there.

LPTK commented 9 months ago

Oh that's a good catch. We currently allow trailing commas in parenthesis sections but not outside of them...

We do want trailing commas as they're very convenient. Scala has them but forces a new line right afterwards. Maybe we could do that and only in argument positions...