Browse thread
[Caml-list] choosing modules at runtime
- Henri Dubois-Ferriere
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Henri Dubois-Ferriere <henridf@l...> |
| Subject: | [Caml-list] choosing modules at runtime |
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