Subtyping ---------- t ::= int | top | t1 * ... * tn | t1 + ... + tn | t1-> t2 | t ref m <= n or n <= m? ------------------------------ t1 + ... + tm <= t1 + ... + tn Rules related to sums: G |- e: ti 1 <= i <= n ------------------------------------------ G |- in_i [t1 + .. + tn] e : t1 + ... + tn G|- e: t1 + .. + tn \forall i: G, x: ti |- ei : t ------------------------------------------------------ G |- case e of (in_1 x => e1 | ... | in_n x => en) : t (1 <= i <= n) ----------------------------------------------------------------- case (in_i[t] v) (in_1 x => e1 | ... | in_n x => e_n) -> e_i[v/x] One counter example: case (in_3 [int+int+int] 0) (in_1 x => true |in_2 x => false) This program type checks if int+int+int <= int+int but it breaks because it gets stuck The correct rule is: m <= n ------------------------------ t1 + ... + tm <= t1 + ... + tn Covariant rule ti <= ti' -------------------------------- t1 + ... + tm <= t1' + ... + tm' Counter example: case (in_1 (1, 2)) ( in_1 x => x.3 | in_2 x => 0 ) Rules for functions t1 <= t1' t2 <= t2' ---------------------- (bad) t1 -> t2 <= t1' -> t2' t1 <= t1' t2' <= t2 ---------------------- (bad) t1 -> t2 <= t1' -> t2' t1' <= t1 t2 <= t2' ---------------------- (good) t1 -> t2 <= t1' -> t2' t1' <= t1 t2' <= t2 ---------------------- (bad) t1 -> t2 <= t1' -> t2' Counter examples \x:int*int*int. (x.3, x.3, x.3) (2, 3) (\x:int*int*int. (x.3, x.3, x.3) (1, 2, 3)).4 To prove Rule #3 is good, we need to prove progress. Canonical forms: given a type, I know the shape of the type's values If . |- v:t then (1) if t = t1 -> t2 then v = \x:t1.e (2) if t = t1 * ... * tn then v = (v1, ..., vn) (3) if t = t1 + ... + tn then v = in_i (v) where 1 <= i <= n Proof: Next time.