![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](https://reader034.vdocuments.pub/reader034/viewer/2022042215/5ebb27648e203b2d1d02fe23/html5/thumbnails/1.jpg)
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](https://reader034.vdocuments.pub/reader034/viewer/2022042215/5ebb27648e203b2d1d02fe23/html5/thumbnails/2.jpg)
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](https://reader034.vdocuments.pub/reader034/viewer/2022042215/5ebb27648e203b2d1d02fe23/html5/thumbnails/3.jpg)
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](https://reader034.vdocuments.pub/reader034/viewer/2022042215/5ebb27648e203b2d1d02fe23/html5/thumbnails/4.jpg)
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](https://reader034.vdocuments.pub/reader034/viewer/2022042215/5ebb27648e203b2d1d02fe23/html5/thumbnails/5.jpg)
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](https://reader034.vdocuments.pub/reader034/viewer/2022042215/5ebb27648e203b2d1d02fe23/html5/thumbnails/6.jpg)
![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](https://reader034.vdocuments.pub/reader034/viewer/2022042215/5ebb27648e203b2d1d02fe23/html5/thumbnails/7.jpg)
![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](https://reader034.vdocuments.pub/reader034/viewer/2022042215/5ebb27648e203b2d1d02fe23/html5/thumbnails/8.jpg)
![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](https://reader034.vdocuments.pub/reader034/viewer/2022042215/5ebb27648e203b2d1d02fe23/html5/thumbnails/9.jpg)
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](https://reader034.vdocuments.pub/reader034/viewer/2022042215/5ebb27648e203b2d1d02fe23/html5/thumbnails/10.jpg)