Version française
Home     About     Download     Resources     Contact us    
Browse thread
small typing problem with modules ...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Julien Signoles <Julien.Signoles@c...>
Subject: Re: [Caml-list] small typing problem with modules ...
Hello,

> My problem here is that I'd like to have a module type T for the functor
> Make in b.ml and to avoid the signature duplication in b.mli ... ideally
> I'd like to write in b.mli something like :
> 
> module type T = sig ???? end
> module Make : functor (Extra : A.Extra) -> 
> functor (A : A.T with type extra  = Extra.t) -> T with ...
> include T with ...
> 
> It's clear that I cannot write a module type as follows because the 
> the "open A" will consider the default type of A and not it's
> parametrized version ...
> 
> module type T = sig
>   open A
>   val f : extra -> unit
> end
> 
> how can I parametrize this signature ? I can write something like :
> module type T = functor (A : A.T) -> 
>   sig
>     open A
>     val f : extra -> unit 
> end ;;
> 
> but then I'm a bit lost putting all this together ... 
> I know I'm close ... a small hint ?

Hum, module types cannot be parameterized. If you want to use a functor 
signature, you can write the following :

=====
module type T =
   functor (Extra : A.Extra) ->
   functor (A : A.T with type extra  = Extra.t) ->
   sig val f : A.extra -> unit end

module Make : T

open A
val f : extra -> unit
=====

But I'm pretty sure that is not really what is expected...
However why cannot you just add an another abstract type in your 
signature like below?

=====
module type T = sig
   type extra
   val f : extra -> unit
end

module Make(Extra : A.Extra)(A : A.T with type extra  = Extra.t)
   : T with type extra = A.extra

open A
val f : extra -> unit
=====

Hope this helps,
Julien Signoles