I am using Ocaml in the Bachelor introduction to programming class at ENS Rennes. I am encouraging my students to use an Abstract Data Types (ADT) approach with compiled modules and opaque data-types.
Each module is thus made of two parts: a signature
adt.mli part and an implementation part
adt.ml. The documentation at https://caml.inria.fr/pub/docs/manual-ocaml/moduleexamples.html is quite clear when those two files are located in the same directory.
However, they are now working on a project with several modules, respectively developed by separate groups. The groups share the interfaces
adt.mli in a
Interfaces repository, but not the implementation codes.
The question is then the procedure for one group to make
adt.cma. I first instructed them to do
$ ocamlc -c ../Interfaces/adt.mli $ ocamlc -c adt.ml
Unfortunately, it does not work, as the
adt.cmi file is left in the
Interfaces repository, and it is not found on compiling
adt.ml. Instead, the default
adt.cmi file is rebuilt in the current directory.
I then tried
$ ocamlc -c ../Interfaces/adt.mli adt.ml
Surprisingly enough, it works!
Could somebody provide me with an explanation, so that I can tell my students?
Also, is it possible to tell
ocamlc -c adt.ml to look for the
adt.cmi file in another directory instead of rebuilding a local one?