Reasonml semicolons in pattern matching


#1

Why reasonml does not uses semicolons in pattern matching with one expression like here

switch (inter) {
| Interval(low, high) => printf(“Interval %d - %d”, low, high)
| Empty => print_string(“Empty interval”)
};

But forces its use here

if (env1) {
Ok; } else {Nothing;
};

Personally I think semicolon in reason does not make sense, it makes sense in OCaml and Rust where its use is to finish a sentence with side effect, but in reason basically you have to put them kinda everywhere


#2

Which version of BuckleScript are you using? Omission of semi-colons shouldn’t throw errors thanks to refmt. Maybe you need to update your bs-platform to the latest version. You can see in this repl that you can omit the semi-colons.

Maybe one reason the way semi-colons are used in Reason is to make it familiar for developers with Javascript background? This excerpt from Cheng Lou’s keynote at ReasonConf gives a 30 seconds explanation on this matter.


#3

if (env1) { Ok; } would parse fine without the semicolon, but it prints with one to make it easier to add further expressions to the block.