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 TAA16263 for caml-redist; Thu, 11 May 2000 19:51:16 +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 QAA02269 for ; Thu, 11 May 2000 16:30:02 +0200 (MET DST) Received: from opus.cs.cornell.edu (EXCHANGE.CS.CORNELL.EDU [128.84.248.73]) by nez-perce.inria.fr (8.10.0/8.10.0) with ESMTP id e4BETMP26669 for ; Thu, 11 May 2000 16:29:28 +0200 (MET DST) Received: by exchange.cs.cornell.edu with Internet Mail Service (5.5.2650.21) id <23WPX57H>; Thu, 11 May 2000 10:28:35 -0400 Message-ID: From: Stephanie Weirich To: "'Hongwei Xi'" , "'caml-list@inria.fr'" Subject: RE: reference initialization Date: Thu, 11 May 2000 10:28:33 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain; charset="iso-8859-1" Sender: weis > -----Original Message----- > From: Hongwei Xi [mailto:hwxi@ececs.uc.edu] > Sent: Wednesday, May 10, 2000 12:50 AM > To: caml-list@inria.fr > Subject: reference initialization > > > > Wrong. You have references, which are quite better than pointers > > (they are typed, and necessarily initialized) > > I have given some thoughts on this one. > [... parts elided ...] > > Can you still say that the ML strategy is better than the Java > strategy? I thus argue that it is better using dynamic checking > to detect reading from uninitialized reference than simply > assigning a value to every reference upon its creation. > > To summarize, my bottom line question is: what is really achieved > by assigning a reference a (wrong) initial value? Isn't this just > like an ostrich solving its problem by burying its head in sand? > > Of course, another problem with the ML strategy is efficiency loss > (which, though, is often negligible as discussed here before) The real difference between ML references and Java pointers is that ML separates "reference" from "possibly unitialized", while Java combines the two into one construct. It's not to difficult to implement Java-style pointers in ML, just use an option ref. For example: type 'a ptr = a' option ref exception NullPointer let new () = ref None let get x = match !x with Some y -> y | None -> raise NullPointer let set x y = x := Some y ML, of course, lacks the syntactic support to use these pointers as gracefully as Java can. On the other hand, the problem with _Java_ is efficiency loss, as the programmer cannot syntactically enforce that the reference is initialized -- requiring a null check at every use. -Stephanie