Type Checking

Outline

Soundness

Type Checking Proofs

Rules for Constants

\[\frac{i\text{ is an integer}}{\vdash i : \texttt{Int}}\text{[Int]}\] \[\frac{}{\vdash true : \texttt{Bool}}\text{[Bool]}\] \[\frac{}{\vdash false : \texttt{Bool}}\text{[Bool]}\] \[\frac{s \text{ is a string constant}}{\vdash s : \texttt{String}}\text{[String]}\]

Rule for new

Some Other Rules

A Problem

A Solution

Type Environments

Type Environments and Rules

New Rules

Let

\[ \frac{O[T_0/x] \vdash e_1 : T_1} {0 \vdash \texttt{let} \; x : T_0 \; \texttt{in} \; e_1 : T_1}\text{[Let-No-Init]} \]

\(O[T_0/x]\) means “\(O\) modified to map \(x\) to \(T_0\) and behaving as \(O\) on all other arguments”: \[O[T_0/x](x) = T_0\] \[O[T_0/x](y) = O(y)\]

Let Example

Notes

Let with Initialization

Let with Initialization

Subtyping

Let with Initialization (Better)

Type System Tug-of-War

Expressiveness of Static Type Systems

Dynamic and Static Types

Dynamic and Static Types

Dynamic and Static Types in Cool

Dynamic and Static Types

Subtyping Example

Example of an Incorrect Let Rule (1)

Example of an Incorrect Let Rule (2)

Example of an Incorrect Let Rule (3)

Typing Rule Notation

Assignment

Initialized Attributes

If-Then-Else

If-Then-Else Example

Least Upper Bounds

If-Then-Else Revisited

\[ \frac{ \begin{array}{l} O \vdash e_0 : \texttt{Bool}\\ O \vdash e_1 : T_1\\ O \vdash e_2 : T_2\\ \end{array}} {O \vdash \texttt{if} \; e_0 \; \texttt{then} \; e_1 \; \texttt{else} \; e_2 \; \texttt{fi} : lub(T_1, T_2)}\text{[If-Then-Else]} \]

Case

\[ \frac{ \begin{array}{l} O \vdash e_0 : T_0\\ O[T_1/x_1] \vdash e_1 : T_1'\\ ...\\ O[T_n/x_n] \vdash e_n : T_n'\\ \end{array}} { \begin{array}{l} O \vdash \texttt{case} \; e_0 \; \texttt{of} \; x_1 : T_1 \; \texttt{=>} \; e_1;\\ ...;\\ x_n : T_n \; \texttt{=>} \; e_n; \; \texttt{esac} : lub(T_1', \ldots, T_n') \end{array} }\text{[Case]} \]

Summary