From: Xavier Leroy <xavier.leroy@inria.fr>
To: Yaron Minsky <yminsky@cs.cornell.edu>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Parameterizing multiple modules using functors
Date: Thu, 21 Aug 2003 16:36:51 +0200 [thread overview]
Message-ID: <20030821163651.A25351@pauillac.inria.fr> (raw)
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
> 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
next prev parent reply other threads:[~2003-08-21 14:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-18 14:40 Yaron Minsky
2003-08-18 14:53 ` Yaron Minsky
2003-08-21 14:36 ` Xavier Leroy [this message]
2003-08-21 21:34 ` Yaron Minsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030821163651.A25351@pauillac.inria.fr \
--to=xavier.leroy@inria.fr \
--cc=caml-list@inria.fr \
--cc=yminsky@cs.cornell.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox