subtyping (was: Re: [E-Lang] Operators #2: Comparison)

zooko@zooko.com zooko@zooko.com
Sat, 07 Apr 2001 06:57:42 -0700


 MarkM wrote:
>
> Subset-ness
> 
> 
> * On Java classes (and by extension perhaps, on declared E types, should we 
> ever declare such things, as we probably will): x <= y means that x is a 
> declared subtype of y.  If y is a class, then x is y or a class that extends 
> a class that's <= y.  If y is an interface, then x is y or x is a class or 
> interface that extends or implements a class that's <= y.  x < y means that 
> x is a declared strict subtype of y, that x < y && !(x <=> y).


Hm.  Note that you are assuming nominative typing here instead of structural.
It is nominative because it is based on typed declared by the programmer.

The structural equivalent would be something like:

`x is a subtype of y' means that x responds to all of the messages that y
responds to.

Either of these would be reasonable ways to do typing in my opinion, but would
have substantially different consequences for programmers (starting with
whether type annotations are optional or required, whether static (i.e.
load-time) typing is optional or required), mobile code, persistence, Design by
Contract, interoperation with other languages, interoperation with older
or future versions of E, and probably more things that I haven't thought of.

Also there may be other design decisions in addition to nominative vs.
structural that we are unwittingly committing ourselves to by defining subtyping
comparison like that.

Unless we really need to specify this behaviour now, I would suggest leaving it
until later, when we'll have a better idea of what we want.


By the way, I found Liskov's substitution principle: "If for each object o1 of
type S there is an object o2 of type T such that for all programs P defined in
terms of T, the behaviour of P is unchanged when o1 is substituted for o2 then S
is a subtype of T."[1]

(Hm.  In searching for that reference I note that some of Liskov's recent work
includes "Providing Persistent Objects in Distributed Systems"[2].)

Regards,

Zooko

[1] "Data Abstraction and Hierarchy", Barbara Liskov, ACM SIGPLAN Notices,
    23(5):17--34, May 1988. Revised version of the keynote address given at
    OOPSLA '87. 
   
    CiteSeer offers 38 papers that cite this one:
    http://citeseer.nj.nec.com/cs?q=data+abstraction+and+hierarchy&cs=1

[2] "Providing Persistent Objects in Distributed Systems", Barbara Liskov,
    Miguel Castro, Liuba Shrira, Atul Adya, ECOOP '99 --- Object-Oriented
    Programming 13th European Conference, Lisbon Portugal
    http://citeseer.nj.nec.com/liskov99providing.html