Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "John F. Hughes" <jfh@cs.brown.edu>
To: <caml-list@inria.fr>
Subject: A second functor question
Date: Fri, 19 Nov 2004 23:14:49 -0500	[thread overview]
Message-ID: <20041120041446.JDEC13256.lakermmtao10.cox.net@SPIKESHOMEPC> (raw)

I'd like to write a signature like this:

module type P = 
  sig
     type t
     val foo : t -> t
     val z:int
  end;;

And make two modules matching that signature:

module P1 : P = 
   struct
      type t = int
      let foo x:t = x
      let z = 1
   end;;

module P2 : P = 
   struct 
      type t = int
      let foo x:t = x
      let z = 2 
   end;;

I now want to apply a functor to those two modules...but a functor
wants a single module, so I make a signature for a "joined" type:

module type COMBINE =
   sig
      module A : P
      module B : P
   end;;
 with A.t = B.t;;

and create a module of that type:

module C : COMBINE = 
   struct
      module A = P1 
      module B = P2
   end;;

And now I can write a functor:

module Fun = 
   functor (Z : COMBINE) -> 
     struct
        let f x:Z.A.t = Z.B.foo x 
     end;;

This will fail because Z.B.foo expects a B.t, but is being handed an
A.t. 

I'd like it to work. In other words, I'd like a way to promise to the
type system
that A.t and B.t (within a COMBINE) are always the same. I tried

module type COMBINE =
   sig
      module A : P
      module B : P
   end with A.t = B.t

I tried telling it they were the same when I created the module C:

module C : COMBINE = 
   struct
      module A = P1 
      module B = P2
   end with A.t = B.t;;

Neither worked. Can someone suggest a way to make this work, or am I
asking too
much of the module system. (I used to be able to do this in ML, using
the 
"sharing type" construct, but...)

---John



             reply	other threads:[~2004-11-20  4:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-20  4:14 John F. Hughes [this message]
2004-11-20  7:45 ` [Caml-list] " Alain Frisch
2004-11-20 14:19 ` Christophe TROESTLER
2004-11-20 14:48 ` Andreas 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=20041120041446.JDEC13256.lakermmtao10.cox.net@SPIKESHOMEPC \
    --to=jfh@cs.brown.edu \
    --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