From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA15570; Thu, 22 Mar 2001 12:41:09 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA15728 for ; Thu, 22 Mar 2001 12:41:08 +0100 (MET) Received: from miss.wu-wien.ac.at (miss.wu-wien.ac.at [137.208.107.17]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f2MBf7b17964 for ; Thu, 22 Mar 2001 12:41:07 +0100 (MET) Received: (from mottl@localhost) by miss.wu-wien.ac.at (8.9.0/8.9.0) id MAA04089; Thu, 22 Mar 2001 12:40:55 +0100 (MET) Date: Thu, 22 Mar 2001 12:40:53 +0100 From: Markus Mottl To: John Max Skaller Cc: Chris Hecker , caml-list@inria.fr Subject: Re: [Caml-list] recursive modules redux, & interface files Message-ID: <20010322124053.A1738@miss.wu-wien.ac.at> References: <4.3.2.7.2.20010318142842.00d85300@shell16.ba.best.com> <3AB5E7D2.8C611747@ozemail.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <3AB5E7D2.8C611747@ozemail.com.au>; from skaller@ozemail.com.au on Mon, Mar 19, 2001 at 22:04:50 +1100 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, 19 Mar 2001, John Max Skaller wrote: > Yes. More precisely, you cannot forward reference any symbol, > however you _can_ call forward by passing a function backward as an > argument. > [This sucks though] Note that you can always use local modules + functors so as not having to pass around functions backwards, e.g.: module MakeM (Spec : sig val f : int -> int end) = struct open Spec let foo x = f x let bar x y = f x + f y end let bla g = let module Spec = struct let f = g end in let module M = MakeM (Spec) in print_int (M.foo 42 + M.bar 1 2) let _ = bla succ Put the functions that should be "backwards parameterized" into functor "MakeM". Then generate its specifcation "Spec" at runtime in some function "bla" (here: "f" should be some function "g" passed at runtime) and apply the functor "MakeM" to the specification "Spec". Now you can access the "backwards parameterized" functions using the qualified module path "M." If you feel annoyed by the fully qualified path, just write another local module, in which you can "open" module "M" and provide some "start" function in this new module to continue execution. If you want even more hardcore moduling, you might be interested in trying out the new "include"-keyword for structures (my favourite new language extension! Thanks!) with the tricks above. You can do tremendous things with it, like overriding specific functions of modules at runtime, etc., with hardly any effort. The only remaining question here is: how efficiently can OCaml handle local modules and local functor applications? I haven't measured it, but I guess that this could be expensive. Regards, Markus Mottl -- Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr