Double semicolon peculiarity

That value isn’t seen interactively – the examples given immediately after that part of the text are all of files. I doubt the value myself; the effect for someone learning OCaml is that inserting ;; makes syntax errors go away:

let () = print_endline "hi"

print_endline "there"

let s = "!" in print_endline s

first error: “Syntax error” on line 5, at the in. A mistake with let ... in ... is always the worst, as far as OCaml error messages go.

let () = print_endline "hi"

print_endline "there"
;;
let s = "!" in print_endline s

second error, line 1, at print_endline: This function has type string -> unit. It is applied to too many arguments [meaning the folllowing print_endline and "there"]; maybe you forgot a ‘;’

result:

let () = print_endline "hi"
;;
print_endline "there"
;;
let s = "!" in print_endline s

which would look a little better with ;; at the end of the previous lines, but still good style would be

let () =
  print_endline "hi";
  print_endline "there";
  print_endline "!"

which is completely different.

I came up with these rules to follow that fixed my wanting to use ;; in source files:

  1. don’t use “let … in” in toplevel code
  2. write “let () =\n do_this ();\n do_that ()” instead of
    "do_this (); do_that ()" in toplevel code
  3. treat ; like an infix operator rather than a terminator or an
    optional separator. Type it in expectation of a right-hand-side.

‘toplevel’ meaning, not as part of the body of some other expression.