Can I have two mutually recursive compilation units /
structures / signatures / functors?
Currently not in the stable langage. However there
exists an OCaml
extension (which is subject to change or removal at
any time) which adresses some of these problems.
How do I express sharing constraints between modules?
Use manifest type specifications in the arguments of the
functor. For instance, assume defined the following
signatures:
module type S1 = sig ... type t ... end module type S2 = sig ... type u ... endTo define a functor
F
that takes two arguments
X:S1
and Y:S2
such that X.t
and Y.u
are the same, write:
module F (X: S1) (Y: S2 with type u = X.t) = struct ... endIndeed, internally this expands to
module F (X: S1) (Y: sig ... type u = X.t ... end) = struct ... end
Compilation units are forced to be modules. What if I want
to make a unit with a functor or a signature instead?
In OCaml, functors and signatures (module types)
can be components of modules. So, just make the functor or
signature be a component of a compilation unit. A good
example is the module
Set
from the standard
library.