

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: PROG ANLYS&UNDERSTANDING; Subject: Computer Science; University: University of Maryland; Term: Spring 2009;
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


(a) (λx.x(xy))(λu.u) (b) (λxyz.zyx)aa(λpq.q) (c) (λxyz.xz(yz))(λxy.x)(λxy.x)
Note: λxy.e is short for λx.λy.e. Remember also that the scope of λ extends as far to the right as possible, and that application associates to the left.
(a) α → β → β (b) (α → β → γ) → β → α → γ (c) α → β (d) α → α → α
e : t and e′^ → e, does A e′^ : t? Here → is reduction under call-by-value semantics. Either prove that subject expansion holds, or give a counterexample showing that it does not hold.e ::= x | n | λx : t.e | e e | ref e |!e | e := e t ::= int | t → t | t ref
Figure 1 gives an operational semantics for this language. In these rules, instead of just having an expression reduce to another expression, we also track a store s, which is a (partial) mapping from locations to values. Locations are just our abstraction for pointers. In the S-Ref rule, we allocate new memory by picking an that is not already in the domain of s and then mapping ` to v in the store. Then we can apply S-Deref if we’re asked to dereference a value that is in the store. Similarly, S-Assign handles assignment, which in these semantics not only updates the store, but also returns the value of the right-hand side (so we don’t have a unit value, unlike OCaml).
S-App 〈s, (λx.e) v〉 → 〈s, e[x 7 → v]〉
C-App-Left 〈s, e 1 〉 → 〈s′, e′ 1 〉 〈s, e 1 e 2 〉 → 〈s′, e′ 1 e 2 〉
C-App-Right 〈s, e 2 〉 → 〈s′, e′ 2 〉 〈s, v e 2 〉 → 〈s′, v e′ 2 〉
S-Ref 6 ∈ dom(s) 〈s, ref v〉 → 〈s[ 7 → v], `〉
C-Ref 〈s, e〉 → 〈s′, e′〉 〈s, ref e〉 → 〈s′, ref e′〉
S-Deref ∈ dom(s) 〈s, !〉 → 〈s, s(`)〉
C-Deref 〈s, e〉 → 〈s′, e′〉 〈s, !e〉 → 〈s′, !(e′)〉
S-Assign ∈ dom(s) 〈s, := v〉 → 〈s[` 7 → v], v〉
C-Assign-Left 〈s, e 1 〉 → 〈s′, e′ 1 〉 〈s, e 1 := e 2 〉 → 〈s′, e′ 1 := e 2 〉
C-Assign-Right 〈s, e 2 〉 → 〈s′, e′ 2 〉 〈s, := e 2 〉 → 〈s′, := e′ 2 〉
Figure 1: (Small-step) Operational semantics with stores
T-Var x ∈ dom(A) A ` x : A(x)
T-Int A ` n : int
T-Lam A, x : t e : t′ A λx : t.e : t → t′
T-App A e 1 : t → t′^ A e 2 : t A ` e 1 e 2 : t′
T-Ref A e : t A ref e : t ref
T-Deref A e : t ref A!e : t
T-Assign A e 1 : t ref A e 2 : t A ` e 1 := e 2 : t
Figure 2: Type rules with references