Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: John Prevost <prevost@maya.com>
To: caml-list@inria.fr
Subject: Re: one-time initialization
Date: 28 Jan 1999 04:54:07 -0500	[thread overview]
Message-ID: <ya2d83z67uo.fsf@zarya.maya.com> (raw)
In-Reply-To: Michael Hicks's message of "Thu, 28 Jan 1999 00:08:23 -0500 (EST)"

Michael Hicks <mwh@dsl.cis.upenn.edu> 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




  reply	other threads:[~1999-01-28 12:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-01-28  5:08 Michael Hicks
1999-01-28  9:54 ` John Prevost [this message]
1999-01-28 14:47   ` Michael Hicks
1999-01-28 10:38 ` Xavier Leroy
1999-01-28 13:03 ` Adam P. Jenkins
1999-01-28 20:23 ` Gerd Stolpmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ya2d83z67uo.fsf@zarya.maya.com \
    --to=prevost@maya.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox