15-312 Recitation #9: Subtyping
2002-10-23
Joshua Dunfield (joshuad@cs)
Carnegie Mellon University
+ Subtyping:
- subset interp: odd, even, int, float, earlier recitation
- coercion interp: string, float, int
coherence
Subsumption
Contravariant rule for ->
Rule for sums
Rule for unit
Rule for void; the void coercions
Rule for polymorphism; coercions
+ Intersection types:
- Basic idea: e : A & B means e : A and e : B
- Fairly old, but only introduced into a practical language around 1990 [Reynolds]
- Various uses, including operator overloading:
+ : (int * int -> int) & (float * float -> float)
- The "obvious" 3 subtyping rules
- The "obvious" introduction rule
e : A e : B
-------------
e : A & B
...is wrong if we have store! [Davies & Pfenning '00]
let x = (ref 2) : int ref & even ref
in
x := 3;
!x
end : even
Need to add a condition e value.
- Typing these is hard. --> bidirectional typing