Version française
Home     About     Download     Resources     Contact us    
Browse thread
a module with multiple signatures
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Keiko Nakata <keiko@k...>
Subject: Re: [Caml-list] a module with multiple signatures
> Because only M.T1 exists, not M1.T1. You can see this on a simpler
> example:
> 
> module X = struct type t = T end
> module Y = struct type t = X.t end
> let f x = match x with Y.T -> ()
> (* type error : "Unbound constructor Y.T" *)
> let f (x:Y.t) = match x with X.t -> ()
> (* val f : Y.t -> unit *)
Hmmm, I see ...

> But, in ocaml, it possible to export the constructor T in Y by using the
> following syntax:
> 
> module X = struct type t = T end
> module Y = struct type t = X.t = T (* T is egal to X.t *) end
> let f x = match x with Y.T -> ()
> (* val f : Y.t -> unit *)
> You can use signature constraints:
> 
> module M = struct type s = S type t = T1 | T2 end
> module M1 : sig type t = M.t end = M
> module M2 : sig type s = M.s type t = M.t end = M

This means that if I want to export T1 and T2 then I have to write as
 module M1 : sig type t = M.t = T1 | T2 end = M
Is it correct?

In my situation, M defines many types and many type constructors,
and I want to give M different signatures, each of which will export
different sets of type constructors.
Then, it seems that I have to write the same type constructor declarations
a number of times....
Isn't it avoidable?

Best regards,
NAKATA keiko.