Can any one help in understanding Use of ; and ;; in ocaml

I believe ;; is used to indicate as the end of the program, please correct me if I’m wrong.
and I didnt get when to use ;
I see the usage of ; at the end of printf any printing statements in Ocaml code.

Can anyone help me to understand this better.

Here’s how I think about it:

  • ; — used as a separator between list elements and record fields, i.e [ 0; 1 ] and { a = 0; b = 1 }, and can also be used after f x instead of let () = f x in ....

  • ;; — used in the REPL at the end of one or more lines to signal execution, and can be used in source code at the level of module elements, i.e. struct f x;; ...end instead of struct let () = f x ...end.

If the explanation above is still puzzling, then consider that ; in expressions is mainly syntactic sugar for let () = ... in and the reason you have ;; at all is that let is used without in at the level of module elements.

Hi, you can find the explanations here: