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 IAA01287 for caml-redistribution@pauillac.inria.fr; Fri, 10 Mar 2000 08:54:49 +0100 (MET) Resent-Message-Id: <200003100754.IAA01287@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 TAA16452 for ; Wed, 8 Mar 2000 19:56:14 +0100 (MET) Received: from isil.localdomain (visitor5.maya.com [192.70.254.187]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id TAA13854 for ; Wed, 8 Mar 2000 19:56:11 +0100 (MET) Received: by isil.localdomain (Postfix, from userid 1000) id 5001536A4A; Wed, 8 Mar 2000 14:00:29 -0500 (EST) Sender: prevost@isil.maya.com To: David Chemouil Cc: caml-list@inria.fr Subject: Re: typing of a class References: <38C50056.9A272C81@enseeiht.fr> From: John Prevost Date: 08 Mar 2000 14:00:29 -0500 In-Reply-To: David Chemouil's message of "Tue, 07 Mar 2000 14:12:54 +0100" Message-ID: <878zzti8xe.fsf@isil.maya.com> User-Agent: Gnus/5.0804 (Gnus v5.8.4) Emacs/20.5 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-From: weis@pauillac.inria.fr Resent-Date: Fri, 10 Mar 2000 08:54:49 +0100 Resent-To: caml-redistribution@pauillac.inria.fr David Chemouil writes: > I've been using the OO features of Caml these past days, and soon > observed a behavior of the typing system that I don't understand. Here > is a simplified version of my problem: > > # 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). Could > someone explain me? Or is there a paper talking about this? The problem is that you're using self during the initialization of the object, not in a method of the object. Since the object isn't yet initialized, it can't be passed to functions. If you use a method, you're okay: class a (arg : a -> b) = object (self) method ob = arg self end and b = object end John.