Version française
Home     About     Download     Resources     Contact us    
Browse thread
Hiding private types
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Daniel_Bünzli <daniel.buenzli@e...>
Subject: Re: [Caml-list] Hiding private types

Le 10 févr. 09 à 18:14, David Rajchenbach-Teller a écrit :

> Does anyone have an idea of how we could/should do this?

I already encoutered these kind of visilibility problems, I'm not sure  
the following applies to your case but it's a case I managed to solve  
(e.g. in react [1]).

Suppose you have two types Pack.a and Pack.b, and two submodule Pack.A  
and Pack.B that define functions on the respective types. In these two  
modules you also want to
have Pack.A.t = Pack.a and Pack.B.t = Pack.b so that the submodules  
can be given to the usual functors.

The problem is then that when you use functions from Pack.A in the  
toplevel you get values of type A.Pack.t = Pack.a but you would like  
Pack.a to be printed. The solution is simple : in the mli of A and B  
the signature of functions should use Pack.a and Pack.b, in other  
words your signature should look like this :

module Pack = struct
type a
type b
module A : sig
  type t = a
  val create : unit -> a (* instead of unit -> t *)
end

module B : sig
  type t = b
  val create : unit -> b (* instead of unit -> t *)
end
end

This way you never get Pack.A.t and Pack.B.t in errors and in the  
toplevel unless you request it by a type annotation (or use functors).

But I don't know if you can reorder your definitions to match this  
pattern.

Best,

Daniel

[1] http://erratique.ch/software/react