I read the following in the OCaml manual (in section 9.2) :
-c option to ocamlc : Compile only. Suppress the linking phase of the compilation. Source code files are turned into compiled files, but no executable file is produced. This option is useful to compile modules separately.
However, if in a very minimal example I have two files a.ml and b.ml and the code inside b.ml calls values defined in a.ml, if I do ocamlc -c b.ml then I get the Error message Unbound module A. I am required to do ocamlc -c a.ml b.ml in the correct order.
The way I see it, the compilation of the B module is not independent or separate from the compilation of the A module at all, since you need a.ml to compile b.ml.
What does the manual mean then by “compile modules separately” ?
In your example, you don’t need a.ml to compile b.ml but a.cmi, the compiled interface for the file a.ml( and optionally the cmx file for optimisation purpose). For instance, the following build sequence works
As an additional consequence, if you compile a.ml and b.ml, then change A without changing the exposed types (or without changing the .mli), you don’t need to recompile B.
In more details: the typing of a module depends on the typing of its dependencies, but the compilation doesn’t.