From: Max Skaller <maxs@in.ot.com.au>
To: Pierre Weis <Pierre.Weis@inria.fr>
Cc: caml-list@inria.fr
Subject: Re: reference initialization
Date: Tue, 23 May 2000 08:29:52 +1000 [thread overview]
Message-ID: <3929B4E0.30E6A7B1@in.ot.com.au> (raw)
In-Reply-To: <200005221528.RAA04339@pauillac.inria.fr>
Pierre Weis wrote:
> So, adding a test to detect this case we can initialize the vector
> properly, without using Obj.magic.
>
> exception Not_yet_initialized of int;;
> exception Already_initialized of int;;
> exception Never_initialized of int;;
>
> let initialize n f =
> if n = 0 then [||] else
> let init_v = Array.make n false in
> let v = ref [||] in
> let get i = if init_v.(i) then !v.(i) else raise (Not_yet_initialized i) in
> let set i ei =
> if !v = [||] then v := Array.make n ei;
Hmmm. This should work, even if 'ei' has a finaliser or mutable
field: 'ei' isn't a 'dummy' value, but a real value that the client
wanted in the array. On the other hand, a dummy value the client
is forced to supply may have dire consequences where the type
is either a class instance , or finalised: here
either construction or destruction may have arbitrary
semantics.
So this (the code you gave) is much better than having to supply a dummy
value.
The same problem occurs with 'forced' variable initialisation:
dummy values may have unwanted side-effects.
There is a tension here, since ocaml is not a purely
functional language.
--
John (Max) Skaller at OTT [Open Telecommications Ltd]
mailto:maxs@in.ot.com.au -- at work
mailto:skaller@maxtal.com.au -- at home
next prev parent reply other threads:[~2000-05-24 8:05 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-05-11 14:28 Stephanie Weirich
2000-05-12 20:38 ` Hongwei Xi
2000-05-15 8:49 ` Xavier Leroy
2000-05-15 17:47 ` Hongwei Xi
2000-05-15 21:33 ` Pierre Weis
2000-05-16 2:53 ` Hongwei Xi
2000-05-18 16:16 ` Pierre Weis
2000-05-19 6:54 ` Max Skaller
2000-05-22 15:28 ` Pierre Weis
2000-05-22 22:29 ` Max Skaller [this message]
2000-05-15 22:20 ` Dave Mason
2000-05-15 9:36 ` Eijiro Sumii
-- strict thread matches above, loose matches on Subject: below --
2000-05-20 20:13 Simon Peyton-Jones
2000-05-22 16:10 ` Pierre Weis
2000-05-11 13:48 Dave Berry
2000-04-25 18:16 Caml wish list Pierre Weis
2000-05-10 4:50 ` reference initialization Hongwei Xi
2000-05-11 13:58 ` Pierre Weis
2000-05-11 18:59 ` Hongwei Xi
2000-05-12 17:07 ` Pierre Weis
2000-05-12 19:59 ` Hongwei Xi
2000-05-15 6:58 ` Max Skaller
2000-05-15 17:56 ` Hongwei Xi
2000-05-14 14:37 ` John Max Skaller
2000-05-13 7:07 ` Daniel de Rauglaudre
2000-05-13 7:09 ` Daniel de Rauglaudre
2000-05-11 16:02 ` John Prevost
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=3929B4E0.30E6A7B1@in.ot.com.au \
--to=maxs@in.ot.com.au \
--cc=Pierre.Weis@inria.fr \
--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