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
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: 2008-04-04 (08:44)
From: Hendrik Tews <tews@c...>
Subject: recursive modules: Cannot safely evaluate the definition

for the following program

    module type Result_sig = sig
      val result : int

    module type Build_sig = sig
      val compute : int -> unit

    module rec Rec : functor(Arg : Result_sig) -> Build_sig = 
      functor(Arg : Result_sig) ->
      let compute = function
	| 0 -> Printf.printf "result: %d\n" Arg.result
	| n ->
	    let module Arg_x_2 = struct
	      let result = Arg.result * 2
	    let module Rec_tail = Rec(Arg_x_2)
	      Rec_tail.compute (n-1)

I get the compiler error 

  Cannot safely evaluate the definition of the recursively-defined module Rec

Could somebody explain to me why? As far as I can see, module Rec
is safe in the sense of section 7.9 of the reference manual. 

[Background: I am trying to solve the following Ocaml puzzle:
Build a (nested) functor application, where the functors applied
depend on an input value of the program. In particular the depth
of the functor application depends on the input value and could
be arbitrary high.]