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 LAA29543 for caml-redistribution@pauillac.inria.fr; Fri, 17 Mar 2000 11:30:30 +0100 (MET) Resent-Message-Id: <200003171030.LAA29543@pauillac.inria.fr> 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 OAA17459 for ; Thu, 16 Mar 2000 14:30:55 +0100 (MET) Received: from pop3.dassault-aviation.fr (pop3.dassault-aviation.fr [62.161.178.177]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id OAA28473 for ; Thu, 16 Mar 2000 14:30:53 +0100 (MET) Received: from rnis.dassault-aviation.fr ([193.106.72.203]) by pop3.dassault-aviation.fr (Netscape Messaging Server 3.6) with ESMTP id AAA1098; Thu, 16 Mar 2000 14:32:48 +0100 Received: from dassault-aviation.fr by rnis.dassault-aviation.fr (8.8.8+Sun/SMI-SVR4) id OAA23555; Thu, 16 Mar 2000 14:29:50 +0100 (MET) Message-ID: <38D0E301.368FB52C@dassault-aviation.fr> Date: Thu, 16 Mar 2000 14:34:57 +0100 From: "thierry BRAVIER" Organization: Dassault Aviation X-Mailer: Mozilla 4.08 [fr] (WinNT; I) MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: typing of a class References: <38C50056.9A272C81@enseeiht.fr> <20000310093324.41034@pauillac.inria.fr> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by rnis.dassault-aviation.fr id OAA23555 Resent-From: weis@pauillac.inria.fr Resent-Date: Fri, 17 Mar 2000 11:30:30 +0100 Resent-To: caml-redistribution@pauillac.inria.fr Dear ocamlers, Xavier Leroy a =E9crit: > You can write your example just like in Java, by 1- making the > instance variable mutable, and 2- using an option type to play the > role of Java's null pointers. You'd get: > > class a arg =3D object(self) > val mutable ob =3D (None : b option) > initializer ob <- Some(arg self) > end;; > > It's not pretty, but that's exactly what's going on "under the hood" > in the equivalent Java code. > > - Xavier Leroy An alternative technique I often use is let not_ready () =3D failwith "not ready" class a arg =3D object (self) val mutable ob =3D not_ready initializer let it =3D arg self in ob <- (fun () -> it) method private ob =3D ob () end the advantage is that it is not necessary anymore to match ob with Some x= ; the drawback is that 'ob' value must now be accessed as 'ob ()'. A workaround is to introduce method ob and type 'self#ob'. Of course, field ob must not be accessed during (arg self) computation :-= ( Cheers.