SoftTimur
SoftTimur

Reputation: 5490

How to define two modules linking each other in OCaml?

I know that we can define two types linking each other, for instance:

type a =
   | CC of b

and b =
   | CD of a

Does anyone know how to do same thing for two modules?

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

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

Upvotes: 3

Views: 166

Answers (1)

pad
pad

Reputation: 41290

It's called recursive modules in OCaml. It's a little bit unfortunate that you have to write type declaration twice.

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

Upvotes: 4

Related Questions