caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] choosing modules at runtime
@ 2002-09-24  8:48 Henri Dubois-Ferriere
  2002-09-24  9:36 ` Andreas Rossberg
                   ` (4 more replies)
  0 siblings, 5 replies; 17+ messages in thread
From: Henri Dubois-Ferriere @ 2002-09-24  8:48 UTC (permalink / raw)
  To: caml-list

Say I have a module signature M which is implemented by module structs 
M_1, M_2, M_3, .. M_N.

At runtime , depending on some command-line parameters, I will choose one 
of the module implementations (they use different algorithms internally). 

This means my main code will be littered with things like

if (use algorithm 1) then
M_1.run_algo()
else if (use algorithm 2) then
M_2.run_algo() ...

each time I use a function from the signature M. Of course I could do a 
shorthand hack like

let run_algo = 
  if (use algorithm 1) then
  M_1.run_algo
  else if (use algorithm 2) then
  M_2.run_algo ...

and then simply call run_algo from then on. (But this needs to be done for 
every function/value that the signature M exports).

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...

Thanks for any hints on the matter.

Henri

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 17+ messages in thread
* RE: [Caml-list] choosing modules at runtime
@ 2002-09-24 10:40 Sebastien.deMentendeHorne
  2002-09-24 11:00 ` Markus Mottl
  0 siblings, 1 reply; 17+ messages in thread
From: Sebastien.deMentendeHorne @ 2002-09-24 10:40 UTC (permalink / raw)
  To: markus; +Cc: caml-list

Hmmm, by the way, if a plugin architecture is needed, are we facing the same
problem ?

I did look at OCaml some weeks ago for an application which is at the moment
written in C++ and that needs a plugin architecture.
There are virtual classes on one side for specifying the interface of the
plugin (in ocaml, I think it would be module signatures) and concrete
classes that inherits from the virtual ones and that implements in different
ways the same signature (module implementations in ocaml). The algorithms
are generic as they are written for the virtual classes.
The loading of the different implementation is done dynamically and
dispatching of methods is done via polymorphism.

Is first class modules the elegant solution for this plugin framework (OCaml
not useful here)?
Does Ocaml offer another solution for this problem ?

Best regards,

Sébastien de Menten               |    ELECTRABEL 
Tel:  ++32 10 48 51 76            |    Risk Asset and Liability Management, 
Fax:  ++32 10 48 51 09            |    Place de l'université, 16, 4ème étage

Gsm:  ++32 478 789 444            |    B-1348 Louvain-la-Neuve, BELGIUM 



-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 17+ messages in thread
* RE: [Caml-list] choosing modules at runtime
@ 2002-09-24 11:09 Sebastien.deMentendeHorne
  2002-09-24 11:41 ` Markus Mottl
  0 siblings, 1 reply; 17+ messages in thread
From: Sebastien.deMentendeHorne @ 2002-09-24 11:09 UTC (permalink / raw)
  To: markus; +Cc: caml-list



> 
> On Tue, 24 Sep 2002, Sebastien.deMentendeHorne@electrabel.com wrote:
> > Hmmm, by the way, if a plugin architecture is needed, are 
> we facing the same
> > problem ?
> 
> It depends. In most cases higher-order modules (i.e. 
> functors) are perfect
> tools for creating plugin architectures. Problems only sometimes arise
> when "plugins" are dynamically selected or even generated, 
> e.g. depending
> on some command-line switches. Then they can become somewhat 
> cumbersome
> to use. In such cases first-class modules would be fine.
> 
I looked at functors and they suffered of staticity.
The plugin we use are dynamically (runtime) selected and they should/could
be even generated at runtime, compiled, loaded and selected... I think that
plugins are most often used in a dynamic way so definitely, first-class
modules would be great.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2002-10-02 20:59 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-24  8:48 [Caml-list] choosing modules at runtime Henri Dubois-Ferriere
2002-09-24  9:36 ` Andreas Rossberg
2002-09-24 10:37   ` Markus Mottl
2002-09-24 10:08 ` Markus Mottl
2002-09-24 10:18 ` Olivier Andrieu
2002-09-24 17:24   ` Sven LUTHER
2002-09-24 10:42 ` Yamagata Yoriyuki
2002-09-24 12:43 ` Alessandro Baretta
2002-09-24 12:55   ` Maxence Guesdon
2002-09-24 10:40 Sebastien.deMentendeHorne
2002-09-24 11:00 ` Markus Mottl
2002-09-24 11:09 Sebastien.deMentendeHorne
2002-09-24 11:41 ` Markus Mottl
2002-09-30  7:28   ` John Max Skaller
2002-10-02 13:04     ` Alessandro Baretta
2002-10-02 13:28       ` Dave Mason
2002-10-02 20:57         ` Chris Hecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).