List of protected keyword in OCaml

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:

The list is in the manual: .

1 Like

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?

They aren’t keywords, that’s why.

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.

1 Like