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

Material Type: Notes; Professor: Pierce; Class: SOFTWARE FOUNDATIONS; Subject: Computer & Information Science; University: University of Pennsylvania; Term: Fall 2004;

Typology: Study notes

Pre 2010

Uploaded on 03/28/2010

koofers-user-4nu-2
koofers-user-4nu-2 🇺🇸

9 documents

1 / 72

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
'
&
$
%
CIS 500
Software Foundations
Fall 2004
6 October
CIS 500, 6 October 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48

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