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 MAA10759; Tue, 24 Sep 2002 12:18:57 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA11057 for ; Tue, 24 Sep 2002 12:18:56 +0200 (MET DST) Received: from shiva.jussieu.fr (shiva.jussieu.fr [134.157.0.129]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g8OAItD04501 for ; Tue, 24 Sep 2002 12:18:55 +0200 (MET DST) Received: from akasha.ijm.jussieu.fr (akasha.ijm.jussieu.fr [134.157.173.57]) by shiva.jussieu.fr (8.12.5/jtpda-5.4) with ESMTP id g8OAIsjR035583 ; Tue, 24 Sep 2002 12:18:54 +0200 (CEST) Received: by akasha.ijm.jussieu.fr (Postfix, from userid 11004) id 7A0153CAC3; Tue, 24 Sep 2002 12:18:49 +0200 (CEST) From: Olivier Andrieu MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15760.15369.277146.734347@akasha.ijm.jussieu.fr> Date: Tue, 24 Sep 2002 12:18:49 +0200 To: Henri DF Cc: caml-list@inria.fr Subject: Re: [Caml-list] choosing modules at runtime In-Reply-To: References: X-Mailer: VM 7.07 under Emacs 20.7.1 X-Antivirus: scanned by sophie at shiva.jussieu.fr Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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. -- Olivier ------------------- 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