Self type

Cormac Flanagan cormac at soe.ucsc.edu
Tue Aug 14 09:56:31 PDT 2007



Peter Hall wrote:
> On 8/14/07, Eylon Stroh <estroh at adobe.com> wrote:
>> From the proposal:
>> "The return type T2 is ok, even if the function returns a T1 instead...
>> covariant occurrences of Self (eg in the result type) are replaced by
>> T2"
>>
> 
> I was also wondering about this.
> To me, if someone writes "Self" for an argument or return type, they
> probably mean T1. If they actually want it to be "*", why not let them
> write "*"? Or is there something else going on here?

Yes, it would be intuitive to replace "Self" by T1, but it would be 
unsound, since Self really means:

   the actual allocated type of the current object, which is some unknown
   subtype of the known static type T1 of that object

so we can only safely replace Self by T1 in "covariant" contexts (where 
we get stuff out, and don't care if we actually get a subtype),
but not in "contravariant" contexts, such as argument positions.

- Cormac



More information about the Es4-discuss mailing list