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 JAA08897 for caml-redistribution@pauillac.inria.fr; Fri, 10 Mar 2000 09:08:41 +0100 (MET) Resent-Message-Id: <200003100808.JAA08897@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 VAA22773 for ; Thu, 9 Mar 2000 21:25:58 +0100 (MET) Received: from pacherenc.inria.fr (pacherenc.inria.fr [128.93.11.83]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id VAA01540; Thu, 9 Mar 2000 21:25:29 +0100 (MET) Received: (from remy@localhost) by pacherenc.inria.fr (8.8.7/8.8.7) id VAA27825; Thu, 9 Mar 2000 21:25:26 +0100 To: David Chemouil Cc: caml-list@inria.fr Subject: Re: typing of a class References: <38C50056.9A272C81@enseeiht.fr> From: Didier Remy Date: 09 Mar 2000 21:25:25 +0100 In-Reply-To: David Chemouil's message of Tue, 07 Mar 2000 14:12:54 +0100 Message-ID: X-Mailer: Gnus v5.5/Emacs 20.2 Resent-From: weis@pauillac.inria.fr Resent-Date: Fri, 10 Mar 2000 09:08:41 +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 Indeed, this is unsafe, since the function arg could well try to access the field "ob" of self that you are currently trying to initialize (so this is not done yet). Consider, for instance, class a = object (self) val ob = self#bad method bad = ob + 1 end;; which is very similar to: type a = { ob : int; } let rec self = { ob = self.ob + 1; };; > (which is possible in Java or Eiffel for example). Yes, but unfortunately Java is not a reference. In particular, it initializes all fields to meaningless default values (which will often result in a dynamically-raised null-pointer exception). Didier