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
。注意:我已经为我的问题添加了上下文