From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA01845; Wed, 25 Sep 2002 10:18:07 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA01841 for ; Wed, 25 Sep 2002 10:18:07 +0200 (MET DST) Received: from mel-rto6.wanadoo.fr (smtp-out-6.wanadoo.fr [193.252.19.25]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g8P8I6505278 for ; Wed, 25 Sep 2002 10:18:06 +0200 (MET DST) Received: from mel-rta9.wanadoo.fr (193.252.19.69) by mel-rto6.wanadoo.fr (6.5.007) id 3D760C2500BC6241; Wed, 25 Sep 2002 10:17:56 +0200 Received: from iliana (80.9.196.109) by mel-rta9.wanadoo.fr (6.5.007) id 3D801204007BA0BF; Wed, 25 Sep 2002 10:17:56 +0200 Received: from luther by iliana with local (Exim 3.35 #1 (Debian)) id 17ttQU-0000ID-00; Tue, 24 Sep 2002 19:24:46 +0200 Date: Tue, 24 Sep 2002 19:24:31 +0200 To: Olivier Andrieu Cc: Henri DF , caml-list@inria.fr Subject: Re: [Caml-list] choosing modules at runtime Message-ID: <20020924172431.GA1116@iliana> References: <15760.15369.277146.734347@akasha.ijm.jussieu.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <15760.15369.277146.734347@akasha.ijm.jussieu.fr> User-Agent: Mutt/1.4i From: Sven LUTHER Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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