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
Lazy modules
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-03-17 (17:36)
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