Version franēaise
Home     About     Download     Resources     Contact us    
Browse thread
recursive modules: Cannot safely evaluate the definition
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Hendrik Tews <tews@c...>
Subject: Re: [Caml-list] recursive modules: Cannot safely evaluate the definition
Jean-Christophe Filliātre <Jean-Christophe.Filliatre@lri.fr>
writes:

   Keiko Nakata wrote:
   > Hello.
   > 
   > I think that functors cannot be recursive in the current OCaml.

   They can:

   [example deleted]


For those who are interested but were too lazy to read the paper
that Keiko pointed to: In a set of recursive modules every
dependency cycle has to go through a safe module, whose signature
consists only of functions, lazy values and exceptions and
submodules with the same requirement.

Initialization first initializes all safe modules by providing
function bodies that throw execptions. Then initialize the
remaining modules in the order of their dependency. In the end
the functions in the safe modules are replace in place with the
right closures. For this replacement trick to work you need to
know the size of the safe modules. Functors are closures whose
size cannot determined from their signature, thus functors are
never safe.

This does not exclude functors in recursive modules. It only
means that apart from the functors you need at least one safe
module. See 7.9 in the reference manual for a very sensible
example with a functor.

If there are dependency cycles without a safe module, you
apparently get the "Cannot safely evaluate ..." error. 

If you have dependency cycles with two or more safe modules than
the compiler might choose an initialization order that does not
work. Then it might help to make some of the safe modules unsafe. 

Bye,

Hendrik