在OCaml中使用相互递归模块定义时,即使在.ml
文件中也需要签名。这是一个烦恼,我也想暴露.mli
给定的接口,因为我最终重复签名两次。 :(!为什么要在OCaml中的相互递归模块中签名?
module rec Client : sig
type ('serv,'cli) t
(* functions ... *)
end = struct
type ('serv,'cli) t =
{ server: ('serv,'cli) Server.t
; (* other members ... *)
}
end
and Server : sig
type ('serv,'cli) t
(* functions ... *)
end = struct
type ('serv,'cli) t =
{ mutable clients: ('serv,'cli) Client.t list
; mutable state: 'serv
}
(* functions again ... *)
end
这是我在做什么粗略的估计(Client
类型的对象知道实例化他们Server
。Server
■正确的Client
S)。
当然,签名。反复在.mli
为什么这是必要的
(注:我不是在抱怨,但实际上想知道是否有一种理论或“硬编译器问题”有关的原因)?
这很有道理。事实上,我通过在`.mli`中暴露外部消费者的不同类型签名来利用这个“特征”。我应该已经意识到了。 – Ashe 2011-01-21 11:02:39