ty ) : e in e x let v · ML programs are typed Programs of type ty: Prog ty,{ e| ∅ ⊢ e: ty}...

10
ML programs are typed Programs of type ty : Prog ty { e |∅⊢ e : ty } where Type assignment relation Γ e : ty Γ = typing context e = expression to be typed ty = type is inductively generated by axioms and rules following the structure of e, for example: Γ e 1 : ty 1 Γ[x ty 1 ] e 2 : ty 2 x / dom (Γ) Γ (let x = e 1 in e 2 ): ty 2 Theorem (Type Soundness). If e, s v, s and e Prog ty , then v Prog ty . 9

Transcript of ty ) : e in e x let v · ML programs are typed Programs of type ty: Prog ty,{ e| ∅ ⊢ e: ty}...

Page 1: ty ) : e in e x let v · ML programs are typed Programs of type ty: Prog ty,{ e| ∅ ⊢ e: ty} where Type assignment relation Γ ⊢ e: ty Γ = typing context e = expression to be

ML programs are typed

Programs of type ty : Progty , { e | ∅ ⊢ e : ty }

where

Type assignment relation

Γ ⊢ e : ty

Γ = typing context

e = expression to be typed

ty = type

is inductively generated by axioms and rules following the structure of e,

for example:

Γ ⊢ e1 : ty1 Γ[x 7→ ty1] ⊢ e2 : ty2 x /∈ dom(Γ)

Γ ⊢ (let x = e1 in e2) : ty2

Theorem (Type Soundness). If e, s ⇒ v, s′ and e ∈ Progty ,

then v ∈ Progty .

9

Page 2: ty ) : e in e x let v · ML programs are typed Programs of type ty: Prog ty,{ e| ∅ ⊢ e: ty} where Type assignment relation Γ ⊢ e: ty Γ = typing context e = expression to be

ML programs are typed

Programs of type ty : Progty , { e | ∅ ⊢ e : ty }

where

Type assignment relation

Γ ⊢ e : ty

Γ = typing context

e = expression to be typed

ty = type

is inductively generated by axioms and rules following the structure of e,

for example:

Γ ⊢ e1 : ty1 Γ[x 7→ ty1] ⊢ e2 : ty2 x /∈ dom(Γ)

Γ ⊢ (let x = e1 in e2) : ty2

Theorem (Type Soundness). If e, s ⇒ v, s′ and e ∈ Progty ,

then v ∈ Progty .

9

Page 3: ty ) : e in e x let v · ML programs are typed Programs of type ty: Prog ty,{ e| ∅ ⊢ e: ty} where Type assignment relation Γ ⊢ e: ty Γ = typing context e = expression to be

ML programs are typed

Programs of type ty : Progty , { e | ∅ ⊢ e : ty }

where

Type assignment relation

Γ ⊢ e : ty

Γ = typing context

e = expression to be typed

ty = type

is inductively generated by axioms and rules following the structure of e,

for example:

Γ ⊢ e1 : ty1 Γ[x 7→ ty1] ⊢ e2 : ty2 x /∈ dom(Γ)

Γ ⊢ (let x = e1 in e2) : ty2

Theorem (Type Soundness). If e, s ⇒ v, s′ and e ∈ Progty ,

then v ∈ Progty .

9

Page 4: ty ) : e in e x let v · ML programs are typed Programs of type ty: Prog ty,{ e| ∅ ⊢ e: ty} where Type assignment relation Γ ⊢ e: ty Γ = typing context e = expression to be

ML transition relation (s , e) → (s′ , e′)

is inductively generated by rules following the structure of e—e.g.

a simplification step(s , e1) → (s′ , e′

1)

(s , let x = e1 in e2) → (s′ , let x = e′1in e2)

a basic reductionv a canonical form

(s , let x = v in e) → (s , e[v/x ])

(see Sect. A.5 for the full definition).

Theorem. s, e ⇒ v, s′ iff (s , e) →∗ (s′ , v).

(→∗ is the reflexive-transitive closure of →.)

12

Page 5: ty ) : e in e x let v · ML programs are typed Programs of type ty: Prog ty,{ e| ∅ ⊢ e: ty} where Type assignment relation Γ ⊢ e: ty Γ = typing context e = expression to be

Are these OCaml expressions contextually equivalent?

F ,

let a = ref()in

let b = ref()in

fun x →if x == a then belse a

G ,

let c = ref()in

let d = ref()in

fun y →if y == d then delse c

No!

For T , fun f → let x = ref()in f ( f x) == f x,

T F has value false, whereas T G has value true,

so F 6∼=ctx G.

ACS L16, lecture 2 9/10

Page 6: ty ) : e in e x let v · ML programs are typed Programs of type ty: Prog ty,{ e| ∅ ⊢ e: ty} where Type assignment relation Γ ⊢ e: ty Γ = typing context e = expression to be
Page 7: ty ) : e in e x let v · ML programs are typed Programs of type ty: Prog ty,{ e| ∅ ⊢ e: ty} where Type assignment relation Γ ⊢ e: ty Γ = typing context e = expression to be
Page 8: ty ) : e in e x let v · ML programs are typed Programs of type ty: Prog ty,{ e| ∅ ⊢ e: ty} where Type assignment relation Γ ⊢ e: ty Γ = typing context e = expression to be
Page 9: ty ) : e in e x let v · ML programs are typed Programs of type ty: Prog ty,{ e| ∅ ⊢ e: ty} where Type assignment relation Γ ⊢ e: ty Γ = typing context e = expression to be

ML programs are typed

Programs of type ty : Progty , { e | ∅ ⊢ e : ty }

where

Type assignment relation

Γ ⊢ e : ty

Γ = typing context

e = expression to be typed

ty = type

is inductively generated by axioms and rules following the structure of e,

for example:

Γ ⊢ e1 : ty1 Γ[x 7→ ty1] ⊢ e2 : ty2 x /∈ dom(Γ)

Γ ⊢ (let x = e1 in e2) : ty2

Theorem (Type Soundness). If e, s ⇒ v, s′ and e ∈ Progty ,

then v ∈ Progty .

9

Page 10: ty ) : e in e x let v · ML programs are typed Programs of type ty: Prog ty,{ e| ∅ ⊢ e: ty} where Type assignment relation Γ ⊢ e: ty Γ = typing context e = expression to be