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 TAA22006 for caml-redist; Thu, 11 May 2000 19:06:21 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA28166 for ; Thu, 11 May 2000 15:47:48 +0200 (MET DST) Received: from mrwall.kal.com (mrwall.kal.com [194.193.14.236]) by concorde.inria.fr (8.8.7/8.8.7) with SMTP id PAA14940 for ; Thu, 11 May 2000 15:47:47 +0200 (MET DST) Received: from mrwall.kal.com [194.193.14.236] (HELO localhost) by mrwall.kal.com (AltaVista Mail V2.0J/2.0J BL25J listener) id 0000_0055_391a_ba1c_8ff6; Thu, 11 May 2000 14:48:12 +0100 Received: from somewhere by smtpxd Message-ID: <3145774E67D8D111BE6E00C0DF418B6621E474@nt.kal.com> From: Dave Berry To: Hongwei Xi , caml-list@inria.fr Subject: RE: reference initialization Date: Thu, 11 May 2000 14:48:02 +0100 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.0.1460.8) Content-Type: text/plain; charset="iso-8859-1" Sender: weis IMO, the "ML strategy" is to use an option type. SML has datatype 'a option = NONE | SOME of 'a although I prefer datatype 'a option = NULL | VALUE of 'a. I don't know if Caml provides such a type as standard, although it's easy to define your own. Then your code checks whether the value has been assigned (dynamically, as you require), and can take whatever action is appropriate. If you want to throw an exception, you can. With this approach, the ML type system tells you which values may be null. This has an advantage over the Java approach, where any value may be null or uninitialised. Dave. -----Original Message----- From: Hongwei Xi [mailto:hwxi@ececs.uc.edu] Sent: Wednesday, May 10, 2000 5: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) Suppose I use a reference 'x'. If I know what the initial value of 'x' should be, I'll of course prefer to initialize it with that value. Now suppose I don't, that is, I intend to assign a value to 'v' later (maybe in a loop or in a conditional branch) (1) ML strategy: initialize x with any value 'v' of an appropriate type (sometimes, such a 'v' is difficult to find or takes time to construct (consider 'x' to be a large array)).