Docsity

The Simply Typed Lambda-Calculus - Software Foundations | CIS 500, Study notes of Computer Science

Partial preview of the text

Download The Simply Typed Lambda-Calculus - Software Foundations | CIS 500 and more Study notes Computer Science in PDF only on Docsity!

CIS 500

Software Foundations

Fall 2004

6 October

CIS 500, 6 October

1

Midterm 1 is next Wednesday



Today’s lecture will not be covered by the midterm.



Next Monday, review class.



Old exams and review questions on webpage.



No recitation sections next week.



New office hours next week, watch newsgroup for details.

CIS 500, 6 October

2

Plans

Where we’ve been:



Inductive definitions 

abstract syntax



inference rules



Proofs by structural induction



Operational semantics



The lambda-calculus



Typing rules and type soundness

Where we’re going:



“Simple types” for the lambda-calculus



references, exceptions, etc.)Formalizing more features of real-world languages (records, datatypes,



Subtyping



Objects

CIS 500, 6 October

3-a

The Simply Typed Lambda-Calculus

CIS 500, 6 October

4

“Simple Types”

T

types

Bool

type of booleans

T

T

types of functions

CIS 500, 6 October

6

Typing rules

true

Bool

T-True

false

Bool

T-False

t 1

Bool

t 2 : T t 3 : T

if t

1

then t

2

else t

3

T

T-If

CIS 500, 6 October

7

Typing rules

true

Bool

T-True

false

Bool

T-False

t 1

Bool

t 2 : T t 3 : T

if t

1

then t

2

else t

3

T

T-If

x:T

Γ ` x : T (

T-Var

CIS 500, 6 October

7-b

Γ^ Typing rules

`

true

Bool

T-True

`

false

Bool

T-False

`

t 1

Bool

Γ t 2 : T Γ t 3 : T

`

if t

1

then t

2

else t

3

T

T-If

x:T

Γ ` x : T (

T-Var

CIS 500, 6 October

7-c

Γ^ Typing rules

`

true

Bool

T-True

`

false

Bool

T-False

`

t 1

Bool

Γ t 2 : T Γ t 3 : T

`

if t

1

then t

2

else t

3

T

T-If

x:T

Γ ` x : T (

T-Var

x:T

1 ` t 2 : T 2

`

λ x:T

1 .t

2 : T 1 → T 2 (

T-Abs

Γ ` t 1 : T

11

T

12

Γ ` t 2 : T

11

Γ ` t 1 t 2 : T

12

T-App

CIS 500, 6 October

7-e

Typing Derivations

What derivations justify the following typing statements?



`

λ x:Bool.x) true

Bool



f:Bool

Bool

`

f (if false then true else false)

Bool



f:Bool

Bool

`

λ x:Bool. f (if x then false else x)

Bool

Bool

CIS 500, 6 October

8

Properties of

→

soundness As before, the fundamental property of the type system we have just defined is

with respect to the operational semantics.

Progress:

A closed, well-typed term is not stuck

If

`

t

T

, then either

t

is a value or else

t

− →

t (^) ′

for some

t (^) ′ .

Preservation:

Types are preserved by one-step evaluation

If

`

t

T

and

t

− →

t (^) ′ , then

`

t (^) ′

T

CIS 500, 6 October

9-a

Proving progress

Same steps as before...

CIS 500, 6 October

10

Typing rules again (for reference)

`

true

Bool

T-True

`

false

Bool

T-False

`

t 1

Bool

Γ t 2 : T Γ t 3 : T

`

if t

1

then t

2

else t

3

T

T-If

x:T

Γ ` x : T (

T-Var

x:T

1 ` t 2 : T 2

`

λ x:T

1 .t

2 : T 1 → T 2 (

T-Abs

Γ ` t 1 : T

11

T

12

Γ ` t 2 : T

11

Γ ` t 1 t 2 : T

12

T-App

CIS 500, 6 October

11

Inversion

Lemma:

If

`

true

R

, then

R

Bool

If

`

false

R

, then

R

Bool

If

`

if t

1

then t

2

else t

3

R

, then

`

t 1

Bool

and

`

t 2 , (^) t

3

R

CIS 500, 6 October

12