如何在OCaml中定义两个相互链接的模块?

时间:2012-01-19 18:26:14

标签: types module ocaml

我知道我们可以定义两种相互链接的类型,例如:

type a =
   | CC of b

and b =
   | CD of a

有谁知道如何为两个模块做同样的事情?

module A = struct
  type t = | CC of B.t
end

?and? B = struct
  type t = | CD of A.t
end

1 个答案:

答案 0 :(得分:4)

在OCaml中称为recursive modules。你不得不两次写出类型声明,这有点不幸。

module rec A: sig
  type t = | CC of B.t
end = 
struct  
  type t = | CC of B.t
end

and B: sig 
  type t = | CD of A.t
end = 
struct
  type t = | CD of A.t
end