caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Lazy modules
@ 2010-03-17 17:04 Dario Teixeira
  2010-03-17 17:36 ` [Caml-list] " Alain Frisch
  2010-03-17 17:42 ` David Allsopp
  0 siblings, 2 replies; 10+ messages in thread
From: Dario Teixeira @ 2010-03-17 17:04 UTC (permalink / raw)
  To: caml-list

Hi,

I've come across a problem which though novel to me, I presume must be
familiar to those with more ML baggage.  Namely, I need a module whose
values are not known at the initialisation stage, since they can only
be determined after reading a configuration file.  If this were a lone
value, I would declare it as a lazy value which when forced would read
from the configuration file.  But how can I achieve similar semantics
with a whole module? 

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:

module Socket_maker (S: sig end) : Client.SOCKET =
struct
    let sockaddr = !Config.sockaddr
    let sockdomain = !Config.sockdomain
    let socktype = !Config.socktype
    let sockproto = !Config.sockproto
end

let foo =
    let module Socket = Socket_maker (struct end) in
    ...

But I wonder a) what's the penalty associated with the runtime application
of the functor, and b) if there's some better way of doing this.  Any thoughts?

Thanks for your time!
Best regards,
Dario Teixeira






^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-03-22 18:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-17 17:04 Lazy modules Dario Teixeira
2010-03-17 17:36 ` [Caml-list] " Alain Frisch
2010-03-17 18:18   ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).