9065Re: "ocaml_beginners":: Re: Circular dependencies between modules
- Dec 1, 2007Thanks Remi !
> Well, there are two kind of dependency:If two.ml uses several one.ml components, so they appear in this order :
> - a module may need a type that is defined in another module
> - a module may need a value (a "let") that is defined in another
> There can be circular dependency in type only if they are defined in
> the same "type ... and ... and ..." declaration
> There can be circular dependency in value only if they are defined in
> the same "let rec ... and .. and" (but there, on can cheat by using
> reference or mutable field, that will be put to the correct value
> before been used).
one.ml two.ml in the Makefile, a cheat to access a two.ml component
inside one.ml would be :
to define a reference to None inside one.ml,
to reinitalize this reference, at runtime from two.ml, with Some copy of
this wanted two.ml component.
'option' use causes the things to be heavier but otherwise they would
become not only ugly but even unsafe.
But maybe I'm wrong and there is a better way...
> .ml / .mli separation can only help you in the case where the circularThanks for these accurate explanations.
> dependency come from two different kind of dependency: say the module
> One use a type defined in module Two when module Two use a value
> defined in module One : you do a one.ml, two.mli and a two.ml. As Two.mli
> define only type, it do not need one.ml to be defined to compile. As
> One depend only on a type of Two, one.ml only need two.mli to be
> compiled to compile. And then two.ml can compile: everything else is
- << Previous post in topic Next post in topic >>