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 BAA00068 for caml-redistribution; Sun, 10 Oct 1999 01:56:23 +0200 (MET DST) 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 AAA32655 for ; Sun, 10 Oct 1999 00:51:14 +0200 (MET DST) Received: from pigeon.maya.com (po.maya.com [192.70.254.2]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id AAA07777 for ; Sun, 10 Oct 1999 00:51:11 +0200 (MET DST) Received: by pigeon.maya.com (Postfix, from userid 2229) id 7FE4D3ED6; Sat, 9 Oct 1999 18:43:35 -0400 (EDT) Sender: weis To: skaller Cc: caml-list@inria.fr Subject: Re: Proposal for study: Add a categorical Initial type to ocaml References: <37FC6572.719AD12D@tsc.uc3m.es> <37FE1E1F.4790FE85@maxtal.com.au> From: John Prevost Date: 09 Oct 1999 18:43:35 -0400 In-Reply-To: skaller's message of "Sat, 09 Oct 1999 02:38:55 +1000" Message-ID: User-Agent: Gnus/5.070095 (Pterodactyl Gnus v0.95) Emacs/20.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii skaller writes: > A better name than $ is probably 'none'. > Boxed values can use a null pointer for none. > Integers and floats can be treated as follows: > do not initialise them at all, if -unsafe is > specified. Otherwise, use the spare value of integers > and some NaN for floats, and insert tests > for all read accesses. I have a question--how is this different (except for the efficiency of using null) from using a 'a option array? The array still must be initialized--in this case to all null, or in the unsafe case, well, it's unsafe. If anything, I would argue that this points at representing 'a option specially for already boxed values by using a null pointer for None, rather than having a special strange value that comes out of arrays and magically creates exceptions. One of the frustrations I have with things like Java is that it's not possible to type references in a way which guarantees a value is not null. With my proposal, your special thing turns into an 'a option array, lookup is the same (but is not guaranteed to provide a Some value), and there's a new array function: val Array.make_with_option (or something) : unit -> 'a option array which in some sort of "unsafe" mode doesn't actually initialize the array and guarantee that all values are well-formed. This provides a failure mechanism similar to unsafe array bounds, without adding strange null values into the language. Again, rather than introduce new features into the language, add a new unsafe optimization and make the option type more efficient for boxed values. John.