Introductory Course
- n Logic and Automata Theory
Introduction to type systems
Polyvios.Pratikakis@imag.fr
Based on slides by Jeff Foster, UMD
Introduction to type systems – p. 1/5
Introduction to type systems Polyvios.Pratikakis@imag.fr Based on - - PowerPoint PPT Presentation
Introductory Course on Logic and Automata Theory Introduction to type systems Polyvios.Pratikakis@imag.fr Based on slides by Jeff Foster, UMD Introduction to type systems p. 1/5 The need for types Consider the lambda calculus terms: false
Based on slides by Jeff Foster, UMD
Introduction to type systems – p. 1/5
Introduction to type systems – p. 2/5
Introduction to type systems – p. 3/5
– Benjamin Pierce, Types and Programming Languages
Introduction to type systems – p. 4/5
Introduction to type systems – p. 5/5
Introduction to type systems – p. 6/5
Introduction to type systems – p. 7/5
Introduction to type systems – p. 8/5
Introduction to type systems – p. 9/5
TypeCheck : (type_env × expression) → type TypeCheck(Γ, n) = int TypeCheck(Γ, x) = if x ∈ dom(Γ) then Γ(x) else fail TypeCheck(Γ, λx : τ.e) = TypeCheck((Γ, x : τ), e) TypeCheck(Γ, e1 e2) = let τ1 = TypeCheck(Γ, e1) in let τ2 = TypeCheck(Γ, e2) in if dom(τ1) = τ2 then range(τ1) else fail
Introduction to type systems – p. 10/5
1
1 e2
2
2
Introduction to type systems – p. 11/5
Introduction to type systems – p. 12/5
Introduction to type systems – p. 13/5
Introduction to type systems – p. 14/5
Introduction to type systems – p. 15/5
Introduction to type systems – p. 16/5
Introduction to type systems – p. 17/5
Introduction to type systems – p. 18/5
Introduction to type systems – p. 19/5
Introduction to type systems – p. 20/5
Introduction to type systems – p. 21/5
Introduction to type systems – p. 22/5
Introduction to type systems – p. 23/5
type intlist = Int of int | Cons of int ∗ intlist
( Int 3)
Introduction to type systems – p. 24/5
(Cons (42, (Int 3)))
match e with Int x → e1 | Cons x → e2
Introduction to type systems – p. 25/5
Introduction to type systems – p. 26/5
Introduction to type systems – p. 27/5
Introduction to type systems – p. 28/5
Introduction to type systems – p. 29/5
Introduction to type systems – p. 30/5
Introduction to type systems – p. 31/5
Introduction to type systems – p. 32/5
Introduction to type systems – p. 33/5
Introduction to type systems – p. 34/5
Introduction to type systems – p. 35/5
Introduction to type systems – p. 36/5
Introduction to type systems – p. 37/5
Introduction to type systems – p. 38/5
Introduction to type systems – p. 39/5
Introduction to type systems – p. 40/5
Introduction to type systems – p. 41/5
Introduction to type systems – p. 42/5
Introduction to type systems – p. 43/5
Introduction to type systems – p. 44/5
α[u/α] = u β[u/α] = β
where β = α
(τ → τ ′)[u/α] = τ[u/α] → τ ′[u/α] (∀β.τ)[u/α] = ∀β.(τ[u/α])
where β = α ∧ β /
∈ FV (u)
(λx : τ.e)[u/α] = (λx : τ[u/α].e[u/α] (Λβ.e)[u/α] = Λβ.e[u/α]
where β = α ∧ β /
∈ FV (u) (e1 e2)[u/α] = e1[u/α] e2[u/α] x[u/α] = x n[u/α] = n
Introduction to type systems – p. 45/5
Introduction to type systems – p. 46/5
Introduction to type systems – p. 47/5
Introduction to type systems – p. 48/5
Introduction to type systems – p. 49/5
1 → τ′ 2} ⇒ C ∪ {τ1 = τ′ 1} ∪ {τ2 = τ′ 2}
Introduction to type systems – p. 50/5
Introduction to type systems – p. 51/5
Introduction to type systems – p. 52/5
Introduction to type systems – p. 53/5
Introduction to type systems – p. 54/5
Introduction to type systems – p. 55/5
Introduction to type systems – p. 56/5
Introduction to type systems – p. 57/5
Introduction to type systems – p. 58/5
Introduction to type systems – p. 59/5