caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: "David Allsopp" <dra-news@metastack.com>
Cc: "'Dario Teixeira'" <darioteixeira@yahoo.com>, <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Lazy modules
Date: Thu, 18 Mar 2010 15:22:01 +0100	[thread overview]
Message-ID: <87zl25pv5i.fsf@frosties.localdomain> (raw)
In-Reply-To: <010d01cac68b$95fcffe0$c1f6ffa0$@romulus.metastack.com> (David Allsopp's message of "Thu, 18 Mar 2010 11:10:14 -0000")

"David Allsopp" <dra-news@metastack.com> writes:

> Dario Teixeira wrote:
>> Hi,
>> 
>> > AFAIK local modules is a syntax extension not a compiler extension - I
>> > expect (not looked at it) that the syntax extension simply alpha
>> > renames all the local module declarations to make them unique and puts
>> > them globally... a very useful extension but no expressive power
>> > added.
>> 
>> But if that were true, wouldn't the functor instantiation happen at
>> initialisation time, thus preventing the delayed instantiation that is
>> key for this solution to work?
>
> Yup, somewhat embarrassingly I seemed to be barking in the wrong forest there, let alone up the wrong tree!!
>
>> > I believe that the module system due for OCaml 3.12.0 will allow this
>> > kind of runtime application of functors as modules are first class
>> > values.
>> 
>> Again, I'm under the impression that functor application can already
>> (with 3.11 at least) occur at runtime when local modules are used.
>> (Or are you talking about different things?).  For example:
>> 
>> # module Foo (S: sig end) = struct let () = print_endline "foo!" end;;
>> module Foo : functor (S : sig  end) -> sig  end
>> 
>> # let hello () = let module F = Foo (struct end) in ();; val hello :
>> unit -> unit = <fun>
>> 
>> # hello ();;
>> foo!
>> - : unit = ()
>> 
>> 
>> > Hope that's helpful - the inability to do what you're wanting to do is
>> > one of the reasons that I've never delved deeply into the module
>> > system - powerful as it may be, it didn't seem to be able to help
>> > performing a simple task (similar to yours) that I wanted it to do (I
>> > have also in the past wanted to exactly what you're doing - i.e. a
>> > module of loaded configuration values).
>> 
>> Yep, Alain confirmed that modules as first-class values are indeed
>> coming for 3.12.  Ocaml's module system just got more interesting...
>
> Definitely!
>
>
> David

Wouldn't objects work here too? You define a virtual class with the
common interface the different configs share and define all your
different config classes and a loader function that dispatches the
creation of the right object. Then you do:

let config = load_config ()

config#say_hello;
config#open_socket;
...

MfG
        Goswin


      reply	other threads:[~2010-03-18 14:26 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 ` [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 message]

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=87zl25pv5i.fsf@frosties.localdomain \
    --to=goswin-v-b@web.de \
    --cc=caml-list@yquem.inria.fr \
    --cc=darioteixeira@yahoo.com \
    --cc=dra-news@metastack.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;
as well as URLs for NNTP newsgroup(s).