caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: coste@irit.fr
To: caml-list@inria.fr
Subject: [Caml-list] reuse of abstract types
Date: Mon, 7 May 2012 20:15:53 +0200	[thread overview]
Message-ID: <sympa.1336411128.30880.441@inria.fr> (raw)
In-Reply-To: 

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

             reply	other threads:[~2012-05-07 18:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-07 18:15 coste [this message]
2012-05-07 20:37 ` Gabriel Scherer
2012-05-08  9:53   ` rossberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sympa.1336411128.30880.441@inria.fr \
    --to=coste@irit.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).