From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 059B6BC57 for ; Thu, 18 Mar 2010 15:26:01 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlsBAF/UoUvZSMDjkWdsb2JhbACbLRUBAQEBCQsKBxMDH7l/hHkE X-IronPort-AV: E=Sophos;i="4.51,267,1267398000"; d="scan'208";a="59303232" Received: from fmmailgate02.web.de ([217.72.192.227]) by mail4-smtp-sop.national.inria.fr with ESMTP; 18 Mar 2010 15:26:00 +0100 Received: from smtp08.web.de (fmsmtp08.dlan.cinetic.de [172.20.5.216]) by fmmailgate02.web.de (Postfix) with ESMTP id 73561155C7D8F; Thu, 18 Mar 2010 15:22:16 +0100 (CET) Received: from [78.43.204.177] (helo=frosties.localdomain) by smtp08.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #4) id 1NsGc1-0003Mn-00; Thu, 18 Mar 2010 15:22:16 +0100 Received: from mrvn by frosties.localdomain with local (Exim 4.71) (envelope-from ) id 1NsGbp-0001o6-Fc; Thu, 18 Mar 2010 15:22:01 +0100 From: Goswin von Brederlow To: "David Allsopp" Cc: "'Dario Teixeira'" , Subject: Re: [Caml-list] Lazy modules References: <00d801cac5f9$474281f0$d5c785d0$@romulus.metastack.com> <864095.98227.qm@web111502.mail.gq1.yahoo.com> <010d01cac68b$95fcffe0$c1f6ffa0$@romulus.metastack.com> Date: Thu, 18 Mar 2010 15:22:01 +0100 In-Reply-To: <010d01cac68b$95fcffe0$c1f6ffa0$@romulus.metastack.com> (David Allsopp's message of "Thu, 18 Mar 2010 11:10:14 -0000") Message-ID: <87zl25pv5i.fsf@frosties.localdomain> User-Agent: Gnus/5.110009 (No Gnus v0.9) XEmacs/21.4.22 (linux, no MULE) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX1+2PUbuaOmFxViHc9SnTWGVe0i0pTZIs8Lb14dE Sjn4dQNcFhx9CFsyu5SCWjcbc/lEfCGoM4zHfPdKEiLkP12+bw pUVAzPhDA= X-Spam: no; 0.00; afaik:01 syntax:01 compiler:01 syntax:01 renames:01 functor:01 yup:01 ocaml:01 runtime:01 functors:01 functor:01 runtime:01 foo:01 sig:01 struct:01 "David Allsopp" 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 = >> >> # 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