Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Lazy modules
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alain Frisch <alain@f...>
Subject: Re: [Caml-list] Lazy modules
On 17/03/2010 18:04, Dario Teixeira wrote:
> In a sense I need a lazy module.  Also, note that I find the solution
> of declaring all values in that module as lazy a bit inelegant.
> I do have a solution which though hackish and relying on a language
> extension (local modules) seems to work: I create the module on demand
> via a functor parameterised over an empty sig:

Here is a variant of your version with first-class modules (which will 
be available in OCaml 3.12). Compared to your version, we get the 
benefit of laziness (the "functor body" is evaluated only once).

module Config =
     let x = ref "XXX"

module type S =
     val x: string

let lazy_module =
      let module M =
          let x = !Config.x
      (module M : S)

let foo () =
   let module M = (val Lazy.force lazy_module : S) in

-- Alain