also another situation.
a little similar like this
the code
let a = "This "
let b = " is "
let c = " a string"
print_string (a ^ b ^ c)
when compile it
☯~/code/ocaml☯ ocamlc -o e e.ml
File "e.ml", line 3, characters 8-19:
3 | let c = " a string"
^^^^^^^^^^^
Error: This expression has type string
This is not a function; it cannot be applied.
if i added ;; on each expression end, then the problem is gone.
You are correct you need to add a ;; to let the compiler know where the expression ends. Since there is no semicolon, the compiler thinks that you must be trying to call a function given by the previous expression.
type weeks = Mon | Tue | Wed | Thu | Fri | Sat | Sun
let day_of_week w =
match w with
| Mon -> 1
| Tue -> 2
| Wed -> 3
| Thu -> 4
| Fri -> 5
| Sat -> 6
| Sun -> 7
;;
print_int (day_of_week Fri)
should be what you want (the whitespace doesn’t matter and is probably what confused you in the original example)