From: Alain Frisch <alain@frisch.fr>
To: Dario Teixeira <darioteixeira@yahoo.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Lazy modules
Date: Wed, 17 Mar 2010 18:36:29 +0100 [thread overview]
Message-ID: <4BA1131D.10208@frisch.fr> (raw)
In-Reply-To: <571731.77500.qm@web111510.mail.gq1.yahoo.com>
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 =
struct
let x = ref "XXX"
end
module type S =
sig
val x: string
end
let lazy_module =
lazy
(
let module M =
struct
let x = !Config.x
end
in
(module M : S)
)
let foo () =
let module M = (val Lazy.force lazy_module : S) in
M.x
-- Alain
next prev parent reply other threads:[~2010-03-17 17:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-17 17:04 Dario Teixeira
2010-03-17 17:36 ` Alain Frisch [this message]
2010-03-17 18:18 ` [Caml-list] " Dario Teixeira
2010-03-17 17:42 ` David Allsopp
2010-03-17 18:23 ` Alain Frisch
2010-03-18 11:10 ` David Allsopp
2010-03-22 18:08 ` Yoann Padioleau
2010-03-17 18:37 ` Dario Teixeira
2010-03-18 11:10 ` David Allsopp
2010-03-18 14:22 ` Goswin von Brederlow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4BA1131D.10208@frisch.fr \
--to=alain@frisch.fr \
--cc=caml-list@yquem.inria.fr \
--cc=darioteixeira@yahoo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox