据我所知,你不能.最接近的解决方案是将"递归"位限制为分别表达每个签名实际需要的位:
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
Run Code Online (Sandbox Code Playgroud)
然后在定义模块时进行优化:
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
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用:
Error: Unbound module type BB.T
Run Code Online (Sandbox Code Playgroud)