I would like to give two .ml sources files the same name in different directories in my source tree, but the OCaml documentation states that the a file A.ml is exported as a toplevel module A = struct … end. If I have two files X/A.ml and Y/A.ml, how can I refer to them both from B.ml?
Share
Modules can contain modules, i.e. you can have a hierarchy of modules.
From the B.ml point of view, you can see two modules named
X.AandY.A.They can even both have a function named
foo, those functions would be seen asX.A.fooandY.A.foo.Beware that if you
openboth modulesXandY, the moduleAfromYwill hide the moduleAfromX.That was from the namespace point of view. Now, about the source tree.
One way would be to have those files:
The file x.ml is automatically generated and contains just this:
Likewise for y.ml
There are several preprocessors able to include a file: cpp, camlp4, camlp5, camlmix…
This set of automatically generated files (and regenerated each time the source changes) is not very satisfiying, I will look at other answers.
You can also have a look at
ocamlc -pack, but when I tried it a long time ago there was a problem withocamldocunable to have x/a.ml and y/a.ml . So check this before you settle on a tool.