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 TAA32171 for caml-redistribution@pauillac.inria.fr; Fri, 10 Mar 2000 19:45:55 +0100 (MET) Resent-Message-Id: <200003101845.TAA32171@pauillac.inria.fr> 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 JAA11905 for ; Fri, 10 Mar 2000 09:33:58 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id JAA05738; Fri, 10 Mar 2000 09:33:27 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA29380; Fri, 10 Mar 2000 09:33:24 +0100 (MET) Message-ID: <20000310093324.41034@pauillac.inria.fr> Date: Fri, 10 Mar 2000 09:33:24 +0100 From: Xavier Leroy To: Didier Remy , David Chemouil Cc: caml-list@inria.fr Subject: Re: typing of a class References: <38C50056.9A272C81@enseeiht.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89.1 In-Reply-To: ; from Didier Remy on Thu, Mar 09, 2000 at 09:25:25PM +0100 Resent-From: weis@pauillac.inria.fr Resent-Date: Fri, 10 Mar 2000 19:45:55 +0100 Resent-To: caml-redistribution@pauillac.inria.fr David Chemouil writes: > > # class a (arg : a -> b) = object(self) > > val ob = arg self > > end > > and b = object > > end;; > > The instance variable self > > cannot be accessed from the definition of another instance variable > > I don't understand why it is forbidden for an object to pass itself to > > another one > > (which is possible in Java or Eiffel for example). 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 = object(self) val mutable ob = (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