List of protected keyword in OCaml

ocaml

#1

Yesterday I had an error with the statement “let val = …” which is obviously false and I replaced by the correct “let ranval = …”.

What is the list of protected keywords in OCaml? A google search does not return anything and it seems legitimate to have such a list.

For other languages such as C++, the list can be found easily: https://en.cppreference.com/w/cpp/keyword


#2

The list is in the manual: http://caml.inria.fr/pub/docs/manual-ocaml/lex.html#sec84 .


#3

Hmmm, the manual seems to suggest that keywords can’t be overridden, and while it’s true for almost all the keywords on the list, I know for a fact that one can rebind + and *

So, while

let and x y = x && y

Isn’t valid OCaml

let ( + ) x y = x +. y

Is valid OCaml

Is the manual incorrect in this section? Should a clause be added to explain some exceptions to this rule?


#4

They aren’t keywords, that’s why.


#5

You can rebind the value of the function ( + ) associated to the keyword + but you cannot make + a non-operator, nor override its meanings as a covariance annotation in

type +'a t = A

The manual warning concerns more word-like keywords, for instance then which can be confused with a normal identifier.