From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA17651 for caml-redistribution; Thu, 26 Nov 1998 17:08:55 +0100 (MET) 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 QAA22190 for ; Thu, 26 Nov 1998 16:59:14 +0100 (MET) Received: from morgon.inria.fr (morgon.inria.fr [128.93.8.33]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id QAA00541; Thu, 26 Nov 1998 16:58:47 +0100 (MET) Received: (from remy@localhost) by morgon.inria.fr (8.8.7/8.8.7) id QAA02528; Thu, 26 Nov 1998 16:58:43 +0100 Message-ID: <19981126165842.07547@morgon.inria.fr> Date: Thu, 26 Nov 1998 16:58:42 +0100 From: Didier Remy To: Anton Moscal Cc: caml-list@inria.fr Subject: Re: Objects as sums Reply-To: Didier.Remy@inria.fr References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.85e In-Reply-To: ; from Anton Moscal on Wed, Nov 25, 1998 at 06:17:35PM +0300 Organization: INRIA, BP 105, F-78153 Le Chesnay Cedex Phone: (33) 1 3963 5317 -- Sec: (33) 1 3963 5570 -- Fax: (33) 1 3963 5684 Web: http://cristal.inria.fr/~remy Sender: weis > class a = object (self) > method b () = ((assert false): b) > method c () = ((assert false): c) > end Here the type of method b is a (the type of objects of class a) > and b = object (self) > inherit a > method b () = self > end The type of self is not the type a, since self may be an object ofa subclass of a (imagine you are calling method b from a subclass of b). The system tries to unify the type of self with a, and then fails. One solution at this point is to write class b as follows: class b = object (self) inherit a method b () = (self : #a :> a) end;; so that extra methods are hidden and self can be seem with type a. However, it would have been better to define a as follows (which is probably what you meant): class a = object (self : 'a) method b () = ((assert false): 'a) method c () = ((assert false): 'a) end;; Here, the methods b and c return an object of the same type as their own type. In particular, in a subclass, they will return an object of the type of objects of the subclass... Then, the rest of the example works unchanged. class c = object (self) inherit a method c () = self end;; -Didier.