你不能,据我可以告诉。最接近的解决方案是限制“递归”位,实际需要的表达单独每个签名:当你定义模块
module type AA =
sig
module B : sig type t end
type t
val f : unit -> B.t
end
module type BB =
sig
module A : sig type t end
type t
val g : unit -> A.t
end
然后细化:
module rec A : AA with module B = B =
struct
module B = B
type t = int
let f() = B.g()
end
and B : BB with module A = A =
struct
module A = A
type t = int
let g() = A.f()
end
FWIW,可能会觉得它应该可以通过使用递归的模块来表达递归式签名(有多少重复):
module rec AA :
sig
module type T = sig module B : BB.T end
end =
struct
module type T = sig module B : BB.T end
end
and BB :
sig
module type T = sig module A : AA.T end
end =
struct
module type T = sig module A : AA.T end
end
然而,这并不工作:
Error: Unbound module type BB.T
感谢您的答案......最接近的解决方案是限制“递归”位==>请您详细说明解决方案的局限性吗? – SoftTimur 2012-01-31 13:42:01
好吧,这不允许你表示签名之间的任意递归,因为你需要能够将每个签名的自包含子集作为一种前向声明来分离。此外,你在两个地方重复每个子集 - 但是命名和包含它们可以在那里帮助。在我的回答中,我没有打算这么做,因为相关的子集(类型t)足够小。 – 2012-01-31 15:25:50