Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Michael Hicks <mwh@dsl.cis.upenn.edu>
To: prevost@maya.com (John Prevost)
Cc: caml-list@inria.fr
Subject: Re: one-time initialization
Date: Thu, 28 Jan 1999 09:47:04 -0500 (EST)	[thread overview]
Message-ID: <199901281447.JAA24346@codex.cis.upenn.edu> (raw)
In-Reply-To: <ya2d83z67uo.fsf@zarya.maya.com> from "John Prevost" at Jan 28, 99 04:54:07 am


> 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."




  reply	other threads:[~1999-01-28 19:59 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
1999-01-28 14:47   ` Michael Hicks [this message]
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=199901281447.JAA24346@codex.cis.upenn.edu \
    --to=mwh@dsl.cis.upenn.edu \
    --cc=caml-list@inria.fr \
    --cc=prevost@maya.com \
    /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