Docsity

Simply-Typed Lambda Calculus - Lecture Slides | CIS 500, Study notes of Computer Science

Partial preview of the text

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

CIS 500

Software Foundations

Fall 2005

26 October, 2005

CIS 500, 26 October, 2005

1

Simply-Typed Lambda Calculus

CIS 500, 26 October, 2005

2

Preservation

Theorem:

If

`

t

T

and

t − →

t (^) ′ , then

`

t (^) ′

T

We got to the point where we needed a

substitution lemma

to show the

preservation theorem:

If

x:S

`

t

T

and

`

s

S

, then

`

[x

7 →

s ]t

T

CIS 500, 26 October, 2005

4

Γ 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, 26 October, 2005

5

Lemmas about the context

Lemma [Permutation]:

If

Γ

`

t

T

and

is a permutation of

then

∆ ` t : T.

Lemma [Weakening]:

If

Γ

`

t

T

and

x 6 ∈

dom

then

x : S ` t : T.

CIS 500, 26 October, 2005

7

Important points about type soundness for STLC



Typing rules need a context to deal with variables.



Progress lemma must have an empty context to be true.



Preservation lemma need not (see TAPL).



Application case of preservation lemma needs substitution lemma.



Substitution lemma must be strenthened to non-empty contexts.



Substitution lemma cannot be proved by induction on typing derivation.

CIS 500, 26 October, 2005

8

The

Unit

type

t

terms

unit

constant

unit

v

values

unit

constant

unit

T

types

Unit

unit type

New typing rules

`

t

T

`

unit

Unit

T-Unit

CIS 500, 26 October, 2005

10

Sequencing

t

terms

t 1 ;t

2

CIS 500, 26 October, 2005

11

Derived forms

One way to extend a programming language is through

derived forms

A derived form is a new syntax, operational semantics

t − →

E

t (^) ′ and type

system

Γ ` E t : T

for a language such that there is a function

e

that translates

the new language into the old language with the following properties:  t − → E t

(^) ′ iff

e ( t ) − → e ( t

(^) ′ ) .

 Γ ` t : T

iff

`

e ( t ) :

T

Derived forms are also called

syntactic sugar

CIS 500, 26 October, 2005

12

t^ Sequencing as a derived form

1 ;t

2

def

λ x:Unit.t

2 ) t

1

where

x

/∈

FV

t 2 )

CIS 500, 26 October, 2005

13

Let-bindings

t^ New syntactic forms

terms

let x=t in t

let binding

New evaluation rules

t − →

t (^) ′

let x=v

1

in t

2 − →

[x

7 →

v 1 ]t 2

E-LetV

t 1 − →

t (^1) ′

let x=t

1

in t

2 − →

let x=t

(^1) ′

in t

2

E-Let

New typing rules

`

t

T

Γ ` t 1 : T 1

x:T

1 ` t 2 : T 2

`

let x=t

1

in t

2

T

2

T-Let

CIS 500, 26 October, 2005

15

Pairs

t

terms

{t,t}

pair

t.

first projection

t.

second projection

v

values

{v,v}

pair value

T

types

T

1 (^) ×

(^) T 2

product type

CIS 500, 26 October, 2005

16

Γ Typing rules for pairs

t 1 : T 1 Γ t 2 : T 2

`

{t

1 ,t

2 }

T

1 (^) ×

(^) T 2

T-Pair

Γ ` t 1 : T

11

(^) ×

(^) T 12

`

t 1 .

T

11

T-Proj

Γ ` t 1 : T

11

(^) ×

(^) T 12

`

t 1 .

T

12

T-Proj

CIS 500, 26 October, 2005

18

Tuples

t

terms

{t

i i ∈ 1 (^) ..n

tuple

t.i

projection

v

values

{v

i i ∈ 1 (^) ..n

tuple value

T

types

{T

i i ∈ 1 (^) ..n

tuple type

CIS 500, 26 October, 2005

19