* Q: Q: Module system and separate compilatioQ:
@ 1996-03-21 12:10 Jocelyn Serot
1996-03-26 16:04 ` Xavier Leroy
0 siblings, 1 reply; 2+ messages in thread
From: Jocelyn Serot @ 1996-03-21 12:10 UTC (permalink / raw)
To: caml-list
Hello,
First of all, thanks to W. Lux and C. Boos for their clever answers to my last
questions about the interaction between the module system and the file system.
What i had not realized - it seems - is that the module language is
_implicitely_ spoken within the file system and that functor application
takes place automatically during the linking phase.
There seems to be a situation where _explicit_ functor application
is useful: when you have defined two distincts implementation for module
Foo (both matching the signature defined in foo.mli).
With the "all in same file, with explicit module declaration" approach , you
can write:
module type Bar = sig ... end
module type Foo = sig ... end
module Foo1 : Foo = struct ... (* 1st impl *) ... end
module Foo2 : Foo = struct ... (* Another impl *) ... end
module MakeBar(M: Foo) = (struct ... let double = ... Foo.add ... end : Bar)
and then _choose_ to build a Bar implementation using either Foo1
module Bar = MakeBar(Foo1)
or Foo2
module Bar = MakeBar(Foo2)
How can you translate the same approach with the signatures and implementations
for Foo and Bar being in distinct files (that is: foo.mli, foo1.ml, foo2.ml,
bar.mli and bar.ml) ?
It seems that you have to copy foo.mli to foo1.mli and foo2.mli to express
that these implementations both match the signature required by Bar.
But then, you have to recompile bar.ml, replacing all occurence of
Foo.member by Foo1.member or Foo2.member. In other words, there seems to be
no way of choosing the Foo implementation at link-time..
Am i right or still missing the point ?... :-)
Thanks again for you patience..
--
E-mail: Jocelyn.Serot@lasmea.univ-bpclermont.fr .............................
S-mail: LASMEA - URA 1793 CNRS, Universite Blaise Pascal, 63177 Aubiere cedex
Tel: (33) 73.40.73.30 - Fax: (33) 73.40.72.62 ...............................
.... http://wwwlasmea.univ-bpclermont.fr/Personnel/Jocelyn.Serot/Welcome.html
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Q: Q: Module system and separate compilatioQ:
1996-03-21 12:10 Q: Q: Module system and separate compilatioQ: Jocelyn Serot
@ 1996-03-26 16:04 ` Xavier Leroy
0 siblings, 0 replies; 2+ messages in thread
From: Xavier Leroy @ 1996-03-26 16:04 UTC (permalink / raw)
To: Jocelyn Serot; +Cc: caml-list
> First of all, thanks to W. Lux and C. Boos for their clever answers
> to my last questions about the interaction between the module system
> and the file system. What i had not realized - it seems - is that
> the module language is _implicitely_ spoken within the file system
> and that functor application takes place automatically during the
> linking phase.
This is essentially correct: compilation units (files) are special
cases of structures (module-class objects). However, you can still do explicit
parameterization and explicit functor applications in a context of
separate compilation. That's because all module-class objects,
including functors, structures, and module types, can be components of
structures, hence components of compilation units.
> With the "all in same file, with explicit module declaration" approach , you
> can write:
>
> module type Bar = sig ... end
>
> module type Foo = sig ... end
>
> module Foo1 : Foo = struct ... (* 1st impl *) ... end
>
> module Foo2 : Foo = struct ... (* Another impl *) ... end
>
> module MakeBar(M: Foo) = (struct ... let double = ... Foo.add ... end : Bar)
>
> and then _choose_ to build a Bar implementation using either Foo1
>
> module Bar = MakeBar(Foo1)
>
> or Foo2
>
> module Bar = MakeBar(Foo2)
>
> How can you translate the same approach with the signatures and
> implementations for Foo and Bar being in distinct files (that is:
> foo.mli, foo1.ml, foo2.ml, bar.mli and bar.ml) ?
I would have the following compilation units:
* "foosig" contains the module type Foo
e.g. foosig.ml: module type Foo = sig ... end
and if you wish, foosig.mli with the same contents.
* "foo1" and "foo2" containing the two implementations
foo1.ml: module Foo = struct ... end
foo1.mli: module Foo : Foosig.Foo
foo2.ml: module Foo = struct ... end
foo2.mli: module Foo : Foosig.Foo
* "bar" containing the MakeBar functor and the Bar modtype
bar.ml: module type Bar = ...
module Make(M: Foosig.Foo) = ...
bar.mli: module type Bar = ...
module Make(M: Foosig.Foo): Bar
* "main1" and "main2" that choose between the two implementations
and starts up the whole program
main1.ml: module Bar = Bar.Make(Foo1.Foo) let _ = Bar.doit(); exit 0
main2.ml: module Bar = Bar.Make(Foo2.Foo) let _ = Bar.doit(); exit 0
Then, link-time configuration is achieved by linking either main1 or
main2 with the remainder of the compilation units.
So, it can be done. I'm not saying this is completely satisfactory,
and more support for link-time configuration could be desirable. On
the other hand, I'd hate to add a third language just for controlling
the linker...
- Xavier Leroy
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1996-03-27 12:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-03-21 12:10 Q: Q: Module system and separate compilatioQ: Jocelyn Serot
1996-03-26 16:04 ` Xavier Leroy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox