Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Xavier Leroy <xleroy@pauillac.inria.fr>
To: Guy.Cousineau@ens.fr
Cc: caml-list@pauillac.inria.fr
Subject: Re: CSL modules
Date: Mon, 4 Mar 1996 15:05:49 +0100 (MET)	[thread overview]
Message-ID: <199603041405.PAA26261@pauillac.inria.fr> (raw)
In-Reply-To: <9603011524.AA08384@aubepine.ens.fr> from "Guy.Cousineau@ens.fr" at Mar 1, 96 04:24:32 pm


> I would like to build a fonctor F such that  C=F(A,B)  "reexports"
> the  types and variables of A and B but with tb now being an abstract type.
> and ta remaining a concrete type .
> Moreover, I want C.xa to be a value of type C.ta and not a value of
> type A.ta which would be easy. The reason for that is that I do not
> want the users of my programs to see modules A and B but only module
> C.

This is easily done using a signature constraint to specify exactly
how much of C should remain visible:

module type SIGA =
  sig
    type ta = A | B of int
    val xa : ta
  end
module type SIGB =
  sig
    type tb = C | D of string
    val xb : tb
  end
module type SIGC =
  sig
    type ta = A | B of int      (* concrete *)
    type tb                     (* abstract *)
    val xa : ta
    val xb : tb
  end
module F(A: SIGA)(B: SIGB) =
  (struct
     type ta = A.ta = A | B of int
     type tb = B.tb
     let xa = A.xa
     let xb = B.xb
   end : SIGC)
module C = F(A)(B)

Notice the type definition "type ta = A.ta = A | B of int", which
keeps C.ta compatible with A.ta while re-exporting the constructors A
and B, which are now part of C. An alternate definition would be:

module type SIGC =
  sig
    type ta = A.ta              (* concrete *)
    type tb                     (* abstract *)
    val xa : ta
    val xb : tb
  end
module F(A: SIGA)(B: SIGB) =
  (struct
     type ta = A.ta
     type tb = B.tb
     let xa = A.xa
     let xb = B.xb
   end : SIGC)
module C = F(A)(B)

It is also correct, but not as good because A is not completely
hidden: the constructors of C.ta still come from A, not C. 

- Xavier Leroy





  reply	other threads:[~1996-03-04 18:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-03-01 15:24 Guy.Cousineau
1996-03-04 14:05 ` Xavier Leroy [this message]
1996-03-05  9:03   ` Wolfgang Lux
1996-03-06  9:28     ` Xavier Leroy
1996-03-05  9:55   ` Christophe Raffalli

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=199603041405.PAA26261@pauillac.inria.fr \
    --to=xleroy@pauillac.inria.fr \
    --cc=Guy.Cousineau@ens.fr \
    --cc=caml-list@pauillac.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