I have defined a module in a file mod.ml as follows:
module Area = struct
...
let test : unit =
Print.printf "haha"
...
end;;
Print.printf "hehe";;
Area.test
It seems that without ;; after end, I can not compile the code by ocamlc. But it looks strange to me to have ;; in a Ocaml file, do I have to keep them?
After generating mod by ocamlc, I launch mod, it prints hahahehe. It seems that haha is printed by the definition of let test : unit ... instead of its call Area.test. What I except as a result is hehehaha or hahahehehaha. Could anyone explain why it is not what I expected?
I never use
;;in my source files, I think of it as part of the top-level interface. For your code I would probably write:For what it’s worth,
Area.testas you have defined it is not a function, it’s just a unit value with a side effect during its computation. In my code here I’ve changed it to a function of typeunit -> unit.