Re: Objects as sums

From: Didier Remy (
Date: Thu Nov 26 1998 - 16:58:42 MET

Date: Thu, 26 Nov 1998 16:58:42 +0100
From: Didier Remy <>
To: Anton Moscal <>
Subject: Re: Objects as sums
In-Reply-To: <>; from Anton Moscal on Wed, Nov 25, 1998 at 06:17:35PM +0300

> 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)

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)

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


This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:17 MET