OCaml Syntax Sucks
let … = … in … is very confusing. When nested, you can't tell how it's nested.
let wafin fd ?pos ?len buf = let loc = "wafin" in let pos = gop ~loc pos in let len = gol buf ~pos len in csa ~loc buf ~pos ~len; uw fd buf ~pos ~len ;;
another problem is that you have global and local declaration with the same syntax, but no bracket to indicate scope. Example:
let … = …
let … = … in …
another problem is that function definition also uses the same syntax. Example:
let a = …→ ( variable, or function of no arg )
let a b = …→ ( function with 1 arg )
let a b c = …→ ( function with 2 args )
though the last point is consistent, because a 0 arity function without side-effect is just constant.
but the effect of all these is that in a ocaml source code you'll have nested let of the above. Quite confusing to read.
MetaLanguage has an “end”
In OCaml's parent language ML, it has a “end”, like this:
let … = … in … end
This is better in the sense that it more clearly indicates the begin and end points of the expression.
Not really better in practice because now it's more typing.
The advantage of clearer indication of nesting doesn't really apply, because in practice, the code is broken down to lines, with proper indentation.
History of OCaml Syntax, and The Next 700 Programming Languages
Here's the lineage of OCaml's syntax:
- ISWIM (1966)
- ML (1973)
- Caml (1985)
- OCaml (1996)
Note that OCaml syntax came from ML, and ML syntax came from a article describing an ideal language called ISWIM, described in the paper:
What Could be Better?
So, if we stick with OCaml/ML's style of syntax, what could be better for the “let” syntax?
That's a hard question, because ML syntax is really a odd ball. It somewhat wanted to be like English.
Then, we trace its history, indeed, in ISWIM, it seems to be one man's whim where it espouses a notation that's half English, half math notation, and intended to be the syntax for the next seven hundred languages.
Facebook Fix to OCaml Syntax
If we do not stick to OCaml style of syntax, then, there's 2 obvious possibilities. One is going with lisp. Another, is going with C-syntax.
See also: OCaml Tutorial
Ask me question on patreon