Browse thread
Lazy modules
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2010-03-18 (14:26) |
From: | Goswin von Brederlow <goswin-v-b@w...> |
Subject: | Re: [Caml-list] Lazy modules |
"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