Ocaml 将函子的结果合并到单个模块中

Ocaml 将函子的结果合并到单个模块中,ocaml,Ocaml,假设我有两个类似的函子: module X (T : sig type t end) = struct type t = T.t ... end module Y (T : sig type t end) = struct type t = T.t ... end 我想将他们的结果合并到一个模块中: module M = struct include X(struct type t = int end) include Y(struct type t = int en

假设我有两个类似的函子:

module X (T : sig type t end) = struct
  type t = T.t
  ...
end

module Y (T : sig type t end) = struct
  type t = T.t
  ...
end
我想将他们的结果合并到一个模块中:

module M = struct
  include X(struct type t = int end)
  include Y(struct type t = int end)
end
当然,这不起作用,因为我在
m
中定义了
t
两次。我知道一种方法是不在
X
Y
内部指定
t
,但我不能这样做,因为我不能写
X
Y
将产生的签名,因为它涉及
t
。我希望我能有一种方法,在没有
t
的情况下,以某种方式获得
X
Y
的签名

编辑:为了使我的问题不那么抽象,我将给出更多的上下文:我试图在cohttp中统一
Request.S
Response.S

下面是模块的组合:


您可以使用
:=
Y(t)
的签名中删除
t

module X (T : sig type t end) = struct
  type t = T.t
end

module Y (T : sig type t end) = struct
  type t = T.t
end

module M = struct
  module T = struct type t = int end
  include X(T)
  include (Y(T) : module type of Y(T) with type t := T.t)
end

您可以使用
:=
Y(t)
的签名中删除
t

module X (T : sig type t end) = struct
  type t = T.t
end

module Y (T : sig type t end) = struct
  type t = T.t
end

module M = struct
  module T = struct type t = int end
  include X(T)
  include (Y(T) : module type of Y(T) with type t := T.t)
end

你不能在
X
Y
的签名中使用
t.t
而不是
t
?那么也必须指定结果模块的类型:
模块X(t:sig type t end):YYY
。所以问题是指
t
YYY
中。我想你仍然可以在那里使用
t.t
。注意:我已经在我的问题中添加了上下文。你不能在
X
Y
的签名中使用
t
而不是
t
?那么,结果模块的类型也必须指定:
模块X(T:sig类型T端):YYY
。因此,问题是在
YYY
中引用
t
。我认为您仍然可以在那里使用
t.t
。注意:我已经为我的问题添加了上下文