Type Systems Authored By Luca Cardelli ACM Computing Surveys, 1996
Type Systems - Why, What & How? (Informally) ◮ Why : to prevent forbidden(all untrapped and some trapped) errors OR “to prove the absence of certain program behaviour” ◮ What : “tractable syntactic method” ◮ How : by distinguishing between well typed and ill typed programs, Type Checking OR “by classifying phrases according to the kinds of values they compute”
Type Checking and Type System Properties Type Checking ◮ No forbidden error = ⇒ well behaved = ⇒ Strongly Checked ◮ some untrapped undetected at compilation = ⇒ Weakly Checked = ⇒ unsafe Type System Properties ◮ Decidably Verifiable ◮ Transparent ◮ Enforceable ◮ Prove that “well typed programs are well behaved”
Type Systems for λ -calculus Syntax for untyped λ -calculus M, N := terms x variables λx.M functions MN applications Syntax for first-order F 1 typed λ -calculus A, B := types M, N := K basic x A → B function λx : A.M MN
Judgments and Rules for F 1 Judgments for F 1 Γ ⊢ ⋄ Γ well-formed environment Γ = { φ, x 1 : A 1 , .., x n : A n } Γ ⊢ M : A M is a well-formed type A in Γ Type Rules for F 1 (only important) (Val Fun) (Val Appl) Γ , x : A ⊢ M : B Γ ⊢ M : A → B Γ ⊢ N : A Γ ⊢ λx : A.M : A → B Γ ⊢ MN : B
Let’s add Bool Type in F 1 Type Rules for F 1 (Type Bool) (Val True) (Val False) Γ ⊢ ⋄ Γ ⊢ ⋄ Γ ⊢ ⋄ Γ ⊢ Bool Γ ⊢ true : Bool Γ ⊢ false : Bool Val Cond Γ ⊢ M : Bool Γ ⊢ N 1 : A Γ ⊢ N 2 : A Γ ⊢ ( if A M then N 1 else N 2 ) : A Note: if A is a hint that inferred types for N 1 and N 2 should be compared with A .
Adding Recursive Types in F 1 Type Rules List Type Example List A � µX.Unit + ( A × X ) (Type Rec) Γ , X ⊢ A Additional Type Syntax Γ ⊢ µX.A A, B := ... types µX.A Recursive (Val Fold) Additional Operations Γ ⊢ M : [ µX.A/X ] A unfold( µX.A ) = [ µX.A/X ] A Γ ⊢ fold µX.A M : µX.A fold( [ µX.A/X ] A ) = µX.A *iso-recursive approach, unfold(fold(M))=M
Second-order Type System, F 2 Syntax M, N := .. terms A, B := .. types λX.M polymorphic ∀ X.A universally abstraction quantified MA type instantiation Type Rule (Val Type Instantiation) Γ ⊢ M : ∀ X.A Γ ⊢ B Γ ⊢ MB : [ B/X ] A
Second-order Type System Derivation ◮ id � λX.λx : X.x ◮ Derive, M � id ( ∀ X.X → X )( id )
Subtyping, F 1 < : An Additional Judgment ◮ Γ ⊢ A < : B A is a subtype of B in Γ Additional Rule Γ ⊢ A Γ ⊢ A < : Top Γ ⊢ a : A Γ ⊢ A < : B Γ ⊢ a : B Γ ⊢ A ′ < : A Γ ⊢ B < : B ′ Γ ⊢ A → B < : A ′ → B ′
Conclusion ◮ Highly condensed introduction to Type Systems ◮ Type Theory, rich and highly expressive but large program are issues
Recommend
More recommend