Skip to content
Yotam Barnoy edited this page May 24, 2016 · 1 revision

OCaml Syntax

Inspired by Reason, this is an attempt to improve OCaml syntax without removing the `OCaml-ness' of the language.

if...end

One of the problems with the current syntax is that semicolons cause parsing ambiguity at the end of if expressions. This can cause bugs, especially in imperative code. You start off by having

if x=3
then do_this ();

Later on, you go back and change it to

if x=3
then do_this (); do_that ()

Except that the then expression only covers the first statement and not the second one, which always runs. Eventually, you need to make almost every if expression into

if x = 3
then begin do_this (); do_that () end

which is overly wordy.

To fix this, we suggest the following syntax:

if x = 3
then do_this ()
end

as well as

if x = 3
then do_this ()
else do_that ()
end
Clone this wiki locally