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 NAA18175 for caml-redistribution; Thu, 28 Jan 1999 13:21:52 +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 KAA19624 for ; Thu, 28 Jan 1999 10:54:27 +0100 (MET) Received: from zarya.maya.com (zarya.maya.com [192.70.254.128]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id KAA07682 for ; Thu, 28 Jan 1999 10:54:26 +0100 (MET) Received: (from prevost@localhost) by zarya.maya.com (8.8.7/8.8.7) id EAA20919; Thu, 28 Jan 1999 04:54:07 -0500 Sender: weis To: caml-list@inria.fr Subject: Re: one-time initialization References: <199901280508.AAA21644@codex.cis.upenn.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii From: John Prevost Date: 28 Jan 1999 04:54:07 -0500 In-Reply-To: Michael Hicks's message of "Thu, 28 Jan 1999 00:08:23 -0500 (EST)" Message-ID: User-Agent: Gnus/5.070072 (Pterodactyl Gnus v0.72) Emacs/20.3 Michael Hicks writes: > I wonder if anyone knows how to optimize the following (simplified for the > sake of dicussion) situation: The only alternative I can think of that might provide a significant performance boost is to make the reference a "default" value when the initialization hasn't yet been done. Another alternative that may win some speed (but I sort of doubt it) is to make the reference be to a function that raises an exception, like so: 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. jmp