Version française
Home     About     Download     Resources     Contact us    
Browse thread
mutually recursive modules
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: ketti <kattlachan@g...>
Subject: Re: [Caml-list] mutually recursive modules
2008/3/23 Jacques Le Normand <rathereasy@gmail.com>:
> how would I do that?
>

You have to factor out the types of the modules.
Lets say we have modules A and B which are mutually recursive.
A needs to know the signature of B and vise verse.

So we define the signatures somewhere visible to both A and B:

module type A_T = sig ... end
module type B_T = sig ... end

Now in A and B we can write something like this:

module MkA = functor (B: B_T) -> struct
  ...
end

And then we can tie it together in a third file:

module MkA = A.MkA
module MkB = B.MkB
module rec A : A_T = MkA(B)
and B : B_T = MkB(A)

Done. ^^ (unless i made mistakes)

Does someone know of a less cumbersome way?