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 LAA10280; Tue, 24 Sep 2002 11:51:21 +0200 (MET DST) 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 LAA10515 for ; Tue, 24 Sep 2002 11:51:20 +0200 (MET DST) Received: from indyio.rz.uni-sb.de (indyio.rz.uni-sb.de [134.96.7.3]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g8O9pK508677 for ; Tue, 24 Sep 2002 11:51:20 +0200 (MET DST) Received: from mars.rz.uni-sb.de (IDENT:d6/sgdQZR2tcE+pmbASOFwNAaynJZcBF@mars.rz.uni-sb.de [134.96.7.4]) by indyio.rz.uni-sb.de (8.9.3/8.9.3) with ESMTP id LAA17222716 for ; Tue, 24 Sep 2002 11:51:19 +0200 (CEST) Received: from uni-sb.de (uni-sb.de [134.96.7.230]) by mars.rz.uni-sb.de (8.8.8/8.8.4/8.8.2) with ESMTP id LAA191334684 for ; Tue, 24 Sep 2002 11:51:19 +0200 (CEST) Received: from cs.uni-sb.de (cs.uni-sb.de [134.96.252.31]) by uni-sb.de (8.12.4/2002060500) with ESMTP id g8O9aWN20672 for ; Tue, 24 Sep 2002 11:36:32 +0200 (CEST) Received: from mail.cs.uni-sb.de (IDENT:Qidcg3HGJGKcduHlU0NQLuO30/futXzQ@mail.cs.uni-sb.de [134.96.254.200]) by cs.uni-sb.de (8.12.1/2002091900) with ESMTP id g8O9aVZ08558 for ; Tue, 24 Sep 2002 11:36:31 +0200 (CEST) Received: from ps.uni-sb.de (grizzly.ps.uni-sb.de [134.96.186.68]) by mail.cs.uni-sb.de (8.12.5/2002072200) with ESMTP id g8O9aUJ09454 for ; Tue, 24 Sep 2002 11:36:30 +0200 (CEST) X-Authentication-Warning: email: Host grizzly.ps.uni-sb.de [134.96.186.68] claimed to be ps.uni-sb.de Received: from ps.uni-sb.de (zoidberg.ps.uni-sb.de [134.96.186.121]) by ps.uni-sb.de (8.11.6/8.11.0) with ESMTP id g8O9aTP18009; Tue, 24 Sep 2002 11:36:29 +0200 Message-ID: <3D90321D.DEFBF3AA@ps.uni-sb.de> Date: Tue, 24 Sep 2002 11:36:29 +0200 From: Andreas Rossberg Organization: =?iso-8859-1?Q?Universit=E4t?= des Saarlandes X-Mailer: Mozilla 4.78 [en] (X11; U; Linux 2.4.9-21 i686) X-Accept-Language: de, en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] choosing modules at runtime References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Henri Dubois-Ferriere wrote: > > 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). It's not too bad, just do: let (algoA, algoB, algoC) = if (use algorithm 1) then (M_1.algoA, M_1.algoB, M_1.algoC) else if (use algorithm 2) then (M_2.algoA, M_2,algoB, M_2.algoC) ... But admittedly it still is somewhat annoying. > 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... No, you are right. Unfortunately, this either requires 1st-class modules, or if-then-else on the module level. (The latter can be partially faked by heroic use of higher-order functors, but you don't want to see that and it most likely does not apply to your particular problem, since the condition itself had to be expressible in the module language). Both is not (yet?) available in OCaml, and in very few other languages, for that matter (Moscow ML currently being the only MLish exception). Such a feature is not impossible to add, but represents a significant complication of the language that may not be considered worthwhile. - Andreas -- Andreas Rossberg, rossberg@ps.uni-sb.de "Computer games don't affect kids; I mean if Pac Man affected us as kids, we would all be running around in darkened rooms, munching magic pills, and listening to repetitive electronic music." - Kristian Wilson, Nintendo Inc. ------------------- 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