Programming problems and weird error messages
Can I have two mutually recursive compilation units / structures /
signatures / functors?
No, unfortunately. This would raise serious typing and compilation
problems. Some workarounds are explained in the user manual.
How do I express sharing constraints?
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 ... end
To define a functor F
that takes two arguments
X:S1
and Y:S2
such that X.t
and
Y.u
share, write:
module F (X: S1) (Y: S2 with type u = X.t) =
struct ... end
Internally, this expands to
module F (X: S1) (Y: sig ... type u = X.t ... end) =
struct ... end
On this form, it is clear that F
can only be applied to
structures A
and B
that meet the
specifications, i.e. such that B.u
is provably equivalent
to A.t
. Moreover, given the declaration of the functor
argument Y
, the body of the functor can assume that
B.u = A.t
. Therefore, this works exactly like a sharing
constraint.
Compilation units are forced to be structure. What if I want to make
a unit with a functor or a signature instead?
In Objective Caml, functors and signatures (module types) can be
components of structures. 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.
It says this expression has type t but is here used with
type t
. I'm confused. Isn't this the same type?
It is the same type name, but not necessarily the same type.
Two type constructors can have the same name, but
actually represent different types. See the user manual.
What is this business about type variables that cannot be
generalized?
The simplest solution to the long-standing problem of polymorphic
references. See the
user manual.
A more detailed
explanation
(in the context of Caml Light 0.7) can be found in the Caml FAQ, and
in the Caml mailing
list.
Caml -
Objective Caml -
Projet Cristal -
Homepages -
Contact the Caml maintainers
Author: Xavier Leroy --
Last modified: 1999/02/09