Types and Type Systems

March 1, 2024
All notes are expanded based on

Why Data Types?


Terminology


Types as Specifications


Sound Type System


Strongly Typed Language


Static vs Dynamic Types


Type Checking


Dynamic Type Checking


Static Type Checking


Type Declarations


Type Inference


Format of Type Judgments


Axioms - Constants (Monomorphic)


Γn:int (assuming n is an integer constant)

Γ true : bool Γ false : bool 

Axioms - Variables (Monomorphic Rule)


Notation: Let Γ(x)=σ if x:σΓ Note: if such σ exits, its unique

Variable axiom:

Γx:σ if Γ(x)=σ

Simple Rules - Arithmetic (Mono)


Primitive Binary operators ({+,,,...}):

Γe1:τ1Γe2:τ2():τ1τ2τ3Γe1e2:τ3

Special case: Relations (∼∈{<,>,=,<=,>=}):

Γe1:τΓe2:τ():ττ bool Γe1e2: bool 

For the moment, think τ is int

Example: {x:int}x+2=3: bool


What do we need to show first?

What we need fot the left and right side?

How to finish?

And

Complete Proof (type derivation)

BinBinVar{x:int}x:intConst{x:int}2:int{x:int}x+2:intConst{x:int}3:int{x:int}x+2=3:int

Simple Rules - Booleans


Connectives

Γe1:boolΓe2:boolΓe1&&e2: bool

Γe1:boolΓe2:boolΓe1||e2: bool

Type Variables in Rules


Γe1: bool Γe2:τΓe3:τΓ(if e1 then e2 else e3)τ

Example derivation: if-then-else:


Γ={x:int, int_of_float : float  int, y : float }