Home     About     Download     Resources     Contact us

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

Browse thread
[Caml-list] Functorizing large collections of modules
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2002-03-18 (04:09) From: Yaron M. Minsky Subject: [Caml-list] Functorizing large collections of modules
```I'm doing some work where I need a bunch of modules that use the same
module ZZp for doing arithmetic module a given prime P.  I wrote a
functor MakeZZp that takes a prime p and returns a module for doing
modular arithmetic over that prime.

Here's the problem.  I have a bunch of modules that depend on ZZp, and I
would like them all to be able to reference the same instance of ZZp.
One way of doing would be simply to functorize each and every one of
them separately by ZZp.  Then, every time one of these modules
references another, the argument of ZZp would have to be passed on.
Thus, rather than referencing Foo, you'd reference Foo.M(ZZp).

This seems messy and kind of silly.  Conceptually what I want is a
single structure like this:

module Library(ZZp:ZZpSig) =
struct

module Foo =
struct ... end

module Bar =
struct ... end

...

end

That way, all the interior modules (Foo, Bar) get to reference the same
ZZp, without having to functorize the individual modules.  So, what I'd
like is to be able to do this without sticking the modules Foo and Bar
into the same single large unmanageable file.

So, is there any way of doing this?  Or am I just going about it wrong.
Another solution, of course, would be to use no functors at all, and
have a single module ZZp where the parameter (the prime) is mutable. But
that seems both messy and less flexible.

y

--
|--------/            Yaron M. Minsky              \--------|
|--------\ http://www.cs.cornell.edu/home/yminsky/ /--------|

Open PGP --- KeyID B1FFD916 (new key as of Dec 4th)
Fingerprint: 5BF6 83E1 0CE3 1043 95D8 F8D5 9F12 B3A9 B1FF D916

-------------------
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

```