English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
A second functor question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-11-20 (07:45)
From: Alain Frisch <Alain.Frisch@i...>
Subject: Re: [Caml-list] A second functor question
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 =
       module A : P
       module B : P with type t = A.t

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


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 

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

-- Alain