English version
Accueil     Ŕ propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis ŕ jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml ŕ l'adresse ocaml.org.

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: 2008-03-23 (18:37)
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

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?