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 QAA28485; Thu, 21 Aug 2003 16:37:12 +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 QAA25935 for ; Thu, 21 Aug 2003 16:37:11 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h7LEaqf16838; Thu, 21 Aug 2003 16:36:52 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA00301; Thu, 21 Aug 2003 16:36:51 +0200 (MET DST) Date: Thu, 21 Aug 2003 16:36:51 +0200 From: Xavier Leroy To: Yaron Minsky Cc: caml-list@inria.fr Subject: Re: [Caml-list] Parameterizing multiple modules using functors Message-ID: <20030821163651.A25351@pauillac.inria.fr> References: <21795.141.155.88.179.1061217600.squirrel@minsky-primus.homeip.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <21795.141.155.88.179.1061217600.squirrel@minsky-primus.homeip.net>; from yminsky@cs.cornell.edu on Mon, Aug 18, 2003 at 10:40:00AM -0400 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 functors:01 functor:01 struct:01 sub-modules:01 approaches:01 literate:01 instantiated:02 signatures:02 modules:02 module:03 explicit:03 awful:03 arguments:03 compilation:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Here's the issue. Consider a project consisting of multiple modules with > lots of interdependencies. Imagine then that I want to add some > flexibility to the system by abstracting out some of the structure of the > system using a functor. Thus, I start out with modules A, B, C, and I > want to parameterize all these modules, let's say by the same module X. > So what I want is a version of the program where I can use A.F(X) intead > of A, B.F(X) instead of B, and so on. The problem is that I want to allow > references between these modules. Thus, B.F(X) needs access to A.F(X), > and C.F(X) needs access to both A.F(X) and B.F(X). The question is, is > there a reasonable way to achieve this? There are two approaches, but I'm not sure you'll find them "reasonable". One is as you described: > I can think of an unreasonable way. I can write the relevant functors so > that they can be embedded in a unified module U as follows: > > module U = > struct > module A = A.F(X) > module B = B.F(A,X) > module C = C.F(A,B,X) > end > > In other words, B and C and require in their functors explicit arguments > corresponding to the other modulse they need. This works, but it's > awfully ugly, not least because you have to write down some awful module > signatures in B and C to make this work. The other is to write: module F (X: SIGX) = struct module A = ... module B = ... module C = ... end This way, B and C automatically reference A as instantiated for X. You do lose separate compilation of A, B and C, though. You can still put A, B and C in separate files and generate the code above from the files, perhaps with the use of a literate programming tool, but the generated file will have to be recompiled entirely every time one of the sub-modules change. - Xavier Leroy ------------------- 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