OCaml syntax proposal--generalised do..done



Hi all,

A few months ago @cakeplus proposed a neat OCaml syntax that generalises a couple of special cases and doesn’t introduce any new keywords: https://github.com/ocaml/ocaml/pull/1122

The proposal is to make do EXPR done a first-class syntactic element which desugars to EXPR : unit. do EXPR done already exists in OCaml as the body of for and while loops which must always have type unit, so factoring it out into first-class syntax makes a lot of sense. The PR has a couple of nice use cases.

Unfortunately the PR was recently closed due to lack of interest so I want to encourage folks to take a look and see if you like it (or not).



I’m not sure if adding additional construct for expressions is worthwhile.
We already have parenthesis and begin-end, and many OCaml programmers prefer to avoid begin-end.
Note also that having for or while loop without do-done part is meaningless.


I don’t think we lose anything by adding this construct, and it might make some code easier to read, so I’m for adding this.

On a related note, I’m curisous as to how much code would actually benefit from this. Personally, I write very little code consisting of large blocks of unit-returning statements, unless I’m using something like Buffer to construct a large text block.


Backwards compability seems to be a possible issue: https://github.com/ocaml/ocaml/pull/1122#issuecomment-327016951


I have no opinion about the proposal, but I have written a bit of code using Owl’s plplot interface, sometimes in a loop. This design of plplot and Owl’s (easier) interface to it requires involves sequences of imperative calls to configure the graphics setup for a plot. My guess is that graphics often involves many imperative calls.


Not necessarily.


(link is broken because it used http:/ instead of http://)

Fixed link: vg