Version française
Home     About     Download     Resources     Contact us    
Browse thread
Q: Q: Module system and separate compilatioQ:
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jocelyn Serot <Jocelyn.Serot@l...>
Subject: Q: Q: Module system and separate compilatioQ:


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,,,
bar.mli and ?
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, 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: .............................
S-mail: LASMEA - URA 1793 CNRS, Universite Blaise Pascal, 63177 Aubiere cedex
Tel: (33) - Fax: (33) ...............................