* small typing problem with modules ...
@ 2009-05-26 9:37 Pietro Abate
2009-05-26 12:37 ` [Caml-list] " Julien Signoles
0 siblings, 1 reply; 4+ messages in thread
From: Pietro Abate @ 2009-05-26 9:37 UTC (permalink / raw)
To: caml-list
Hi all,
I'm trying to build a functorized version of a library providing also
a default type. Consider the two follwoing modules :
~$cat a.ml
module type T = sig
type extra
val f : extra -> unit
end
module type Extra = sig
type t = private [> ]
val g : t -> unit
end
module Make (Extra : Extra) = struct
type extra = Extra.t
let f t = ()
end
module ExtraDefault = struct
type t = [`A]
let g t = ()
end
include Make(ExtraDefault)
~$cat a.mli
module type T = sig
type extra
val f : extra -> unit
end
module type Extra = sig
type t = private [> ]
val g : t -> unit
end
module ExtraDefault : Extra with type t = [ `A ]
module Make : functor (Extra : Extra) -> T with type extra = Extra.t
include T with type extra = ExtraDefault.t
------------------
so far so good. Now I've another module that I can type as follows:
~$cat b.ml
module Make (Extra : A.Extra) (A : A.T with type extra = Extra.t) = struct
open A
let f t = ()
end
include Make(A.ExtraDefault)(A)
~$cat b.mli
module Make :
functor (Extra : A.Extra) ->
functor (A : A.T with type extra = Extra.t) ->
sig
open A
val f : extra -> unit
end
open A
val f : extra -> unit
------------------------
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 ?
TA.
p
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] small typing problem with modules ...
2009-05-26 9:37 small typing problem with modules Pietro Abate
@ 2009-05-26 12:37 ` Julien Signoles
2009-05-26 13:12 ` Pietro Abate
2009-05-26 13:35 ` Andreas Rossberg
0 siblings, 2 replies; 4+ messages in thread
From: Julien Signoles @ 2009-05-26 12:37 UTC (permalink / raw)
To: Pietro Abate, caml list
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] small typing problem with modules ...
2009-05-26 12:37 ` [Caml-list] " Julien Signoles
@ 2009-05-26 13:12 ` Pietro Abate
2009-05-26 13:35 ` Andreas Rossberg
1 sibling, 0 replies; 4+ messages in thread
From: Pietro Abate @ 2009-05-26 13:12 UTC (permalink / raw)
To: caml-list
On Tue, May 26, 2009 at 02:37:18PM +0200, Julien Signoles wrote:
> >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 :
uhmmm I was wondering ... :)
> =====
> 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?
well it does not solve the duplication problem as I cannot write
something like :
include T (A.ExtraDefault) (A)
as we don't have functorized module types as you pointed out. you just
moved the functor signature to the type T ...
> =====
> 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
> =====
ok, I can do that, but it would be still annoying as the module A might
contain a lot of types that I would need to add to the signature T in
b.mli . Something like :
module type T = sig
type a
type b
...
type n
val fa : a -> unit
val fb : b -> unit
...
val fn : n -> unit
end
but this should solve the duplication problem as I can now write
something like
include T with type extra = A.extra ( .... and all other types .... )
I'm still not really satisfied with this solution, but I'm now worried
that with the current syntax is just not possible to solve my problem...
thanks :)
pp
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] small typing problem with modules ...
2009-05-26 12:37 ` [Caml-list] " Julien Signoles
2009-05-26 13:12 ` Pietro Abate
@ 2009-05-26 13:35 ` Andreas Rossberg
1 sibling, 0 replies; 4+ messages in thread
From: Andreas Rossberg @ 2009-05-26 13:35 UTC (permalink / raw)
To: Julien Signoles; +Cc: Pietro Abate, caml list
[-- Attachment #1: Type: text/plain, Size: 1390 bytes --]
On May 26, 2009, at 14.37 h, Julien Signoles wrote:
>
>> 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.
Actually, they can. You just have to put them into a functor. For
example:
# module TF (A : sig type t end) =
struct
module type T = sig open A val x : t end
end;;
module TF :
functor (A : sig type t end) -> sig module type T = sig val x : A.t
end end
# module I = struct type t = int end;;
module I : sig type t = int end
# module M : TF(I).T = struct let x = 9 end;;
module M : TF(I).T
- Andreas
[-- Attachment #2: Type: text/html, Size: 2542 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-05-26 13:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-26 9:37 small typing problem with modules Pietro Abate
2009-05-26 12:37 ` [Caml-list] " Julien Signoles
2009-05-26 13:12 ` Pietro Abate
2009-05-26 13:35 ` Andreas Rossberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox