Reputation: 6532
I am trying to extend a functor in OCaml.
For example, assume the following functor X
:
module type X = functor (A : ModuleA) -> I with type t := A.t
I am trying to create a similar functor Y
that also accepts A : Module A
but returns an extended version of I
.
I am trying something like:
module type Y = functor (A : ModuleA) ->
sig
include X(A)
val blah : A.t -> int
end
But I get a syntax error on this.
I am trying to extend the resulting signature from X
with more functions. Is this possible in OCaml? What am I doing wrong?
Thanks!
EDIT:
I guess my question is: why don't functors behave the same way for modules and module types?
The functor X
above returns a module type (or at least that's how I read that expression). If this expression is allowed, then why does OCaml forbid extending the resulting module type?
Upvotes: 3
Views: 2043
Reputation: 1418
Unfortunately, to my knowledge this is not possible. You will have to do
module type Y = functor (A : ModuleA) ->
sig
include I with type t := A.t
val blah : A.t -> int
end
Hopefully someone else can elaborate why the feature you were trying to use is not implemented. Possibly there is a good reason.
EDIT:
If you already have a module XX
of type X
(an instance), you can do
module type Y = functor (A : ModuleA) ->
sig
include module type of XX(A)
val blah : A.t -> int
end
Upvotes: 5