Reason: Use ruby style do...end instead of some braces

Created on 19 May 2016  路  3Comments  路  Source: reasonml/reason

I like a lot of what you've done with Reason, but I'm not fond of braces everywhere.

How about allowing certain braces to become do...end (I chose do, as in ruby, mostly because it's shorter than begin).

Examples:

let f => do
  ...
end
let x = switch do
  | ...
end

For if/then/else, it could be simplified slightly:

if x == 3 do
...
else
...
end

I think this would make the language much more palatable to functional language types such as myself.

Syntax

Most helpful comment

This isn't really what OCaml has.

  1. OCaml has a whole bunch of inconsistent keywords as you mention (struct...end, do...done etc). It also has a begin...end that translates into parentheses, and that you can use anywhere.
  2. OCaml never required begin...end, which is where the trouble started.

If you convert every brace optionally to do...end and require it in for loops, function definitions, scopes etc, you get just as uniform a syntax, but one that isn't nearly as littered with braces.

All 3 comments

That's what ocaml had, and it caused a ton of confusion around when to use begin block, when to use struct, and braces, etc. If we switch to do we'd have to switch it everywhere or otherwise we'd be shuffling around the old syntaxes and repeating the same mistake. I think this has been debated before and the decision is that if we wanted a uniform way of writing blocks, we'd go with braces, despite the compromise you mentioned.

Reason's still in its early days; ultimately individuals will be able to swap around their preferred syntax. Since this particular change isn't in the roadmap I'll close this issue. But we'll definitely keep this in mind, thanks.

This isn't really what OCaml has.

  1. OCaml has a whole bunch of inconsistent keywords as you mention (struct...end, do...done etc). It also has a begin...end that translates into parentheses, and that you can use anywhere.
  2. OCaml never required begin...end, which is where the trouble started.

If you convert every brace optionally to do...end and require it in for loops, function definitions, scopes etc, you get just as uniform a syntax, but one that isn't nearly as littered with braces.

Ah I see, sorry about that. @jordwalke has more opinion on it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shaneosullivan picture shaneosullivan  路  3Comments

gustavopinto picture gustavopinto  路  3Comments

ostera picture ostera  路  3Comments

rickyvetter picture rickyvetter  路  3Comments

kyldvs picture kyldvs  路  3Comments