Date: Thu, 26 Nov 1998 16:58:42 +0100
From: Didier Remy <firstname.lastname@example.org>
To: Anton Moscal <email@example.com>
Subject: Re: Objects as sums
In-Reply-To: <Pine.LNX.firstname.lastname@example.org>; 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)
Here the type of method b is a (the type of objects of class a)
> and b = object (self)
> inherit a
> method b () = self
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)
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)
method c () = self
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:17 MET