OCaml Common Pitfalls Forgetting parentheses around function arguments


A common mistake is to forget surrounding compound function arguments with parentheses, leading to type errors.

# string_of_int 1+1;;

Error: This expression has type string but an expression was expected of type int

This is because of the precedence. In fact, the above evaluates to

# (string_of_int 1) + 1;;

which is wrong. A correct syntax would be

# string_of_int (1+1);;

- : string = "2"