caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] reuse of abstract types
@ 2012-05-07 18:15 coste
  2012-05-07 20:37 ` Gabriel Scherer
  0 siblings, 1 reply; 3+ messages in thread
From: coste @ 2012-05-07 18:15 UTC (permalink / raw)
  To: caml-list

Hello,
While using the module system to abstract types, I often encounter the problem
to reuse in a signature an abstract type declared in another signature. Let's
take an example.
I have a module M, which declares an abstract type t, with operations using
this type.

module type MT = sig
  type t
  val f : t ->	....
end

Now I want to design a module Q, with operations using type t. To refer to t in
the signature of Q, I am obliged to declare a module Mt : MT inside the
signature

module type QT = sig
  module Mt : MT
  val g : Mt.t -> .... 
end

Now the module M itself, before Q, because of sharing constraint in Q:

module M : MT = struct
  type t = int
  let f x =  ....
end

And finally the module Q, which must contain a module Mt to respect its
signature:

module Q  : (QT with type Mt.t = M.t) = struct
  module Mt = M
  let g x = ....
end

As generally my modules are functors I will probably rather write the module
QF:

module QF (Mx:MT) :  (QT with type Mt.t = Mx.t) = struct
  module Mt = Mx
  let g x = ...
end

And finally instanciate QF:

module Q2 = QF (M)

The declaration of Mt in QT and QF is here only to reference the type t. It
seems natural that QF be parameterized by Mx:MT as it will certainly use
operations of M, but what seems artificial is the declaration of Mt in the
signature QT (and hence in the functor QF). Intuitively, I would say that  the
signature QT refers to the type t declared in the signature MT, not in the
structure M.
Is there a simpler way to do this ? I suspect my solution is too complicate,
but I couldn't find better...

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

end of thread, other threads:[~2012-05-08  9:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-07 18:15 [Caml-list] reuse of abstract types coste
2012-05-07 20:37 ` Gabriel Scherer
2012-05-08  9:53   ` rossberg

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