Browse thread
[Caml-list] choosing modules at runtime
[
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: | Sven LUTHER <luther@d...> |
| Subject: | Re: [Caml-list] choosing modules at runtime |
On Tue, Sep 24, 2002 at 12:18:49PM +0200, Olivier Andrieu wrote: > Henri Dubois-Ferriere [Tuesday 24 September 2002] : > > > > 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() ... > > You could use local modules : > > if (use algorithm 1) then > let module M = M_1 in > M.run_algo() ... > else if (use algorithm 2) then > let module M = M_2 in > M.run_algo() ... > > the point is that the blocks under the `let module .. = ' are the > same, so you can copy/paste them. You could use some preprocessing > treatment to make it look better. But some sort of syntactic sugar could be added to ocaml in order to handle this properly, could it not ? Friendly, Sven Luther ------------------- 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