From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA09119 for caml-redistribution; Thu, 28 Jan 1999 20:59:01 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA13111 for ; Thu, 28 Jan 1999 15:47:12 +0100 (MET) Received: from linc.cis.upenn.edu (LINC.CIS.UPENN.EDU [158.130.12.3]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id PAA12890 for ; Thu, 28 Jan 1999 15:47:10 +0100 (MET) Received: from codex.cis.upenn.edu (CODEX.CIS.UPENN.EDU [158.130.6.15]) by linc.cis.upenn.edu (8.8.5/8.8.5) with ESMTP id JAA24841; Thu, 28 Jan 1999 09:47:07 -0500 (EST) Received: (from mwh@localhost) by codex.cis.upenn.edu (8.8.5/8.8.5) id JAA24346; Thu, 28 Jan 1999 09:47:05 -0500 (EST) From: Michael Hicks Message-Id: <199901281447.JAA24346@codex.cis.upenn.edu> Subject: Re: one-time initialization To: prevost@maya.com (John Prevost) Date: Thu, 28 Jan 1999 09:47:04 -0500 (EST) Cc: caml-list@inria.fr In-Reply-To: from "John Prevost" at Jan 28, 99 04:54:07 am X-Mailer: ELM [version 2.4 PL23-upenn3.1] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: weis > val global = (ref (fun () -> failwith "not initialized") : > (mytype -> unit) ref) > > let init i = global := fun () -> i > > let f () = ... (!global ()) > let g () = (!global ()) ... > > this at least has the advantage that you don't have to have a big > hairy pattern match in every function. I've tried this and similar alternatives using classes and records, but they all end up being slower than the naive approach I presented before. :( One thing I've thought of is to make the entire program a bunch of functors, parameterized by their external module references and an additional "initialization information" module. Then, the toplevel "main" module would execute some code to initialize the "initialization" module, and then invoke all of the functors to construct a custom program based on the initialization information. Since my program is a long-running server application, it might be worth this one-time cost. On the other hand, I'm not sure the gain will be worth re-architecting the whole program ... Mike -- Michael Hicks Ph.D. Candidate, the University of Pennsylvania http://www.cis.upenn.edu/~mwh mailto://mwh@dsl.cis.upenn.edu "I worked with an individual who plugged his power strip back into itself and for the life of him could not understand why his computer would not turn on."