Version française
Home     About     Download     Resources     Contact us    

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

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 <yminsky@c...>
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) = 

  module Foo = 
  struct ... end

  module Bar =
  struct ... 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.


|--------/            Yaron M. Minsky              \--------|
|--------\ /--------|

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

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: