caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Manipulating Modules Modularly
@ 2014-10-21  8:52 Arnaud Spiwack
  2014-10-21 12:26 ` Leo White
  0 siblings, 1 reply; 6+ messages in thread
From: Arnaud Spiwack @ 2014-10-21  8:52 UTC (permalink / raw)
  To: OCaML Mailing List

[-- Attachment #1: Type: text/plain, Size: 1663 bytes --]

Dear all,

Here is a puzzle I run way to often in (yesterday was one of these) and
have not good solution to.

Suppose I have a module signature such as monoids:

module type M = sig  type t  val u:t  val p:t->t->t  end

And a functor:

module type ME = sig  type t  val ps:t list -> t  end
module ME (M:M) : ME with type t := M.t

All good and well. I now want to reuse my functor for list, which are a
monoid. But I can only get:

module type TYPE = sig type t end
module LEF (T:TYPE) : ME with type t = T.t list

By the way, I have no intuition why I cannot use a := (substitution) above
and am stuck with a type definition.

But that's not my question. What I really want is a module

module LE : ME with type t := 'a list

There are two problems here. First, I don't know how to define the
signature (which, expanded would be   sig val ps : 'a list list -> 'a list)
without copying. Second I don't know how to do write the module LE itself,
without boilerplate proportional to the number of function in the signature.

With local modules it is reasonably easy to implement LE without modifying
ME, by re-exporting every function as a function which instantiates LEF
(though I guess [u] would only work because list is covariant). But I would
rather the module LE to extend automatically as I extend the signature of
ME.

The thing is, this is just the commutation between forall-s and product-s.
So provided the functor instantiation is pure, then it is always possible
to do that. But I don't know of any modular way to do it.

So here's my question: how do you/would you solve this problem. If the
solution is compatible with 3.12, it's a plus.



/Arnaud

[-- Attachment #2: Type: text/html, Size: 1991 bytes --]

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

end of thread, other threads:[~2014-10-22  9:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-21  8:52 [Caml-list] Manipulating Modules Modularly Arnaud Spiwack
2014-10-21 12:26 ` Leo White
2014-10-21 12:47   ` Leo White
2014-10-21 13:19     ` Arnaud Spiwack
2014-10-21 14:52       ` Leo White
2014-10-22  9:51         ` Arnaud Spiwack

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