Separate module compilation in ocaml

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

ocamlc -c a.ml
ocamlc -c b.ml
ocamlc a.cmo b.cmo -o executable

With an interface file a.mli for A, one can decouple the build further:

ocamlc -c a.mli
ocamlc -c b.ml &
ocamlc -c a.ml &
wait
ocamlc a.cmo b.cmo -o executable

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.

In addition, if you compile a.ml with the -i flag, you’ll get as output a sample suitable for use as a.mli, viz

ocamlc -i -c a.ml

If you put that output in a.mli then

ocamlc -c a.mli
ocamlc -c b.ml

should work fine. This is the sense in which a.ml and b.ml are separatel-compilable, as octachron explained above.