Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] choosing modules at runtime
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-09-24 (10:08)
From: Markus Mottl <markus@o...>
Subject: Re: [Caml-list] choosing modules at runtime
On Tuesday, 24 Sep 2002, Henri Dubois-Ferriere wrote:
> At runtime , depending on some command-line parameters, I will choose one 
> of the module implementations (they use different algorithms internally). 
> Am I missing something obvious here? Of course what I would conceptually 
> like to do would be something like
> let Mod = if (use algorithm 1) then M_1 else if (use alg 2) then M_2 ..
> and then be able to call Mod.run_algo(), but that probably belies that I 
> am still thinking in an OO manner...

What you are actually looking for is first class modules, i.e. modules,
which can be passed around at runtime. This topic has already popped up a
couple of times in the past, especially since Claudio Russo implemented
them along the lines of his PhD-thesis for Moscow ML. Here is a link to
the start of such a thread:

Unfortunately, I haven't heard of any efforts to integrate this extension
into the main distribution of OCaml. I do indeed have quite a few
sources that would benefit from first class modules. Parameterization
of algorithms can be quite painful without.

E.g., I have a large number of modules implementing various machine
learning heuristics that all have their own concrete types and algorithms
but match the same signature. Depending on some command-line arguments
I'd like to use some of them as arguments to a functor to instantiate a
machine learning system. If I didn't use some absolutely awful workarounds
(extracting functions from modules and passing tuples of them around just
to recreate the modules elsewhere), I'd even suffer from combinatorial
explosion, because I'd have to consider the Cartesian product of all
possible functor applications.

I'd really highly appreciate some extensions to the module system that
make such things simpler...

Best regards,
Markus Mottl

Markus Mottl                                   
Austrian Research Institute
for Artificial Intelligence        
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: