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 XAA21072; Thu, 21 Aug 2003 23:34:09 +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 XAA12609 for ; Thu, 21 Aug 2003 23:34:08 +0200 (MET DST) Received: from tisch.mail.mindspring.net (tisch.mail.mindspring.net [207.69.200.157]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h7LLY7T02633 for ; Thu, 21 Aug 2003 23:34:07 +0200 (MET DST) Received: from user-0ccekej.cable.mindspring.com ([24.199.81.211] helo=minsky-primus.homeip.net) by tisch.mail.mindspring.net with smtp (Exim 3.33 #1) id 19px4I-0000cp-00 for caml-list@inria.fr; Thu, 21 Aug 2003 17:34:06 -0400 Received: from 141.155.88.179 (SquirrelMail authenticated user yminsky) by minsky-primus.homeip.net with HTTP; Thu, 21 Aug 2003 17:34:06 -0400 (EDT) Message-ID: <60415.141.155.88.179.1061501646.squirrel@minsky-primus.homeip.net> Date: Thu, 21 Aug 2003 17:34:06 -0400 (EDT) Subject: Re: [Caml-list] Parameterizing multiple modules using functors From: "Yaron Minsky" To: "Caml List " In-Reply-To: <20030821163651.A25351@pauillac.inria.fr> References: <21795.141.155.88.179.1061217600.squirrel@minsky-primus.homeip.net> <20030821163651.A25351@pauillac.inria.fr> X-Priority: 3 Importance: Normal X-Mailer: SquirrelMail (version 1.2.11) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 functors:01 yaron:01 minsky:01 yminsky:01 cornell:01 functor:01 functors:01 struct:01 struct:01 sub-modules:01 bug:01 faq:01 faq:01 beginner's:01 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 ------------------- 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