Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Alain Frisch <Alain.Frisch@inria.fr>
To: "John F. Hughes" <jfh@cs.brown.edu>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] A second functor question
Date: Sat, 20 Nov 2004 08:45:40 +0100	[thread overview]
Message-ID: <419EF624.30201@inria.fr> (raw)
In-Reply-To: <20041120041446.JDEC13256.lakermmtao10.cox.net@SPIKESHOMEPC>

John F. Hughes wrote:
> 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.

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

You need to keep the P1.t and P2.t fields public, otherwise the 
constraint cannot be checked:

module P1 = struct ... end;;
module P2 = struct ... end;;

or:

module P1 : P with type t = int = ...
module P2 : P with type t = int = ...

Btw, maybe you did it on purpose, but the type annotation in:

         let f x:Z.A.t = Z.B.foo x

is upon the result type of f, not its argument (in your case, it's the 
same).


Note also you don't need to combine the two structures in a single 
module, you can just define a functor with several arguments:

module Fun(A : P)(B : P with type t = A.t) = struct
   let f x = B.foo x
end


-- Alain


  reply	other threads:[~2004-11-20  7:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-20  4:14 John F. Hughes
2004-11-20  7:45 ` Alain Frisch [this message]
2004-11-20 14:19 ` [Caml-list] " 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=419EF624.30201@inria.fr \
    --to=alain.frisch@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=jfh@cs.brown.edu \
    /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