caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Parameterizing multiple modules using functors
@ 2003-08-18 14:40 Yaron Minsky
  2003-08-18 14:53 ` Yaron Minsky
  2003-08-21 14:36 ` Xavier Leroy
  0 siblings, 2 replies; 4+ messages in thread
From: Yaron Minsky @ 2003-08-18 14:40 UTC (permalink / raw)
  To: caml-list

I've asked this question before, but never quite got a satisfactory
answer.  I'm hoping something has changed between now and then (maybe with
3.07?).

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?

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.

Is there any non-awful way to achieve this?  The absence of this kind of
feature makes the entire functor system seem much less attractive for
adding any large-scale genericity.

Yaron


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Parameterizing multiple modules using functors
  2003-08-18 14:40 [Caml-list] Parameterizing multiple modules using functors Yaron Minsky
@ 2003-08-18 14:53 ` Yaron Minsky
  2003-08-21 14:36 ` Xavier Leroy
  1 sibling, 0 replies; 4+ messages in thread
From: Yaron Minsky @ 2003-08-18 14:53 UTC (permalink / raw)
  To: caml-list

For what it's worth, last time I brought this up, it was mentioned that
some solutions have been proposed to this problem in the Standard ML
world:

http://cm.bell-labs.com/cm/cs/who/blume/pub.html

Also, here's a link to the previous discussion on google groups.

http://www.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=fa.ianr5dv.10n67hi%40ifi.uio.no&rnum=40&prev=/groups%3Fq%3Dgroup:fa.caml%2Bauthor:yminsky%2540cs.cornell.edu%26start%3D30%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3Dfa.ianr5dv.10n67hi%2540ifi.uio.no%26rnum%3D40

y

> I've asked this question before, but never quite got a satisfactory
> answer.  I'm hoping something has changed between now and then (maybe
> with 3.07?).
>
> 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?
>
> 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.
>
> Is there any non-awful way to achieve this?  The absence of this kind of
> feature makes the entire functor system seem much less attractive for
> adding any large-scale genericity.
>
> Yaron
>
>
> -------------------
> 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Parameterizing multiple modules using functors
  2003-08-18 14:40 [Caml-list] Parameterizing multiple modules using functors Yaron Minsky
  2003-08-18 14:53 ` Yaron Minsky
@ 2003-08-21 14:36 ` Xavier Leroy
  2003-08-21 21:34   ` Yaron Minsky
  1 sibling, 1 reply; 4+ messages in thread
From: Xavier Leroy @ 2003-08-21 14:36 UTC (permalink / raw)
  To: Yaron Minsky; +Cc: caml-list

> 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Parameterizing multiple modules using functors
  2003-08-21 14:36 ` Xavier Leroy
@ 2003-08-21 21:34   ` Yaron Minsky
  0 siblings, 0 replies; 4+ messages in thread
From: Yaron Minsky @ 2003-08-21 21:34 UTC (permalink / raw)
  To: Caml List 

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-08-21 21:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-18 14:40 [Caml-list] Parameterizing multiple modules using functors Yaron Minsky
2003-08-18 14:53 ` Yaron Minsky
2003-08-21 14:36 ` Xavier Leroy
2003-08-21 21:34   ` Yaron Minsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).