To cover:
[] + []Desired properties:
We will define a typing judgment e : t that says when an expression e is in a type t. Note that this is a different activity from writing a type checker or type inferencer, which are algorithms for saying yes/no for a given expression/type pair, or for producing a type for a given expression, respectively. Writing e : t declaratively, with inference rules, is an easier task.
Formal statements of soundness and completeness:
e : t and e ==> v then v : t.e ==> v and v : t then e : t.Syntax: e ::= num n | tt | ff | e + e | if e then e else e
Values: e value
--------- ---------- ---------------
tt value ff value (num n) value
Types:
tt and ff are the values in the Bool type(num n) are the values in the Number typeTypes t ::= Number | Boolean
Typing rules:
Judgment form: e : t
--------- ty/tt ----------- ty/ff ------------------ ty/n
tt : Bool ff : Bool (num n) : Number
e1 : Number e2 : Number
--------------------------- ty/+
(e1 + e2) : Number
e : Bool e1 : t e2 : t
------------------------------- ty/if
if e then e1 else e2 : t
Example typing derivation:
Expression:
(if ff then 1 else 0) + (2 + 3) : ?
Derivation:
--------- ty/ff --------- ty/n --------- ty/n -------- ty/n ----- ty/n
ff : Bool 1 : Number 0 : Number 2 : Number 3 : Number
-------------------------------------------- ty/if ------------------- ty/+
(if ff then 1 else 0) : Number (2 + 3) : Number
---------------------------------------------------------------------------- ty/+
(if ff then 1 else 0) + (2 + 3) : Number
Example ill-typed terms:
(if ff then 1 else tt)4 + ttif (if tt then 4 else 5) then tt else ffExercise: check (informally) that our inference rules cannot type these programs.
If we have time, we will consider let-expressions and their binding structure in the context of type systems.