



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Assigned Due Extension April 17, 2008, submit in class April 10, 2008 due April 17, 5:00 pm, 20% penalty Guideline: • For problems 1 and 2, write your answers in the blanks right on page 1 and 2. For other problems, use thetemplates provided starting on page 3.
(e 1 ,e 2 ) ⇓ (v 1 ,v 2 ),σ′ ρ,σ fst e ⇓ v,σ′^1 ρ,σ` snd e ⇓ v,σ′Problem 2. For each of the semantic definitions, give a rule for this version of let: let x = e and x′^ = e′^ in e′′: (Env) (^) let x=e and x′=e′ (^) in e′′,ρ ⇓ v (Rew) (^) let x=e and x′=e′ (^) in e′′ (^) ⇓ v (Env-σ) (^) ρ,σlet x=e and x′=e′ (^) in e′′ (^) ⇓ v,σ′ on this page.and Rew above. That is, using Env, prove: Problem 3. Prove that the expression^ For the problems below, use the templates starting on page 3. Do not write your answers e = ((∅, efun ⇓ 7 x (where -> fun ∅ yis the empty environment), and using Rew, prove -> x + y)3)4 returns 7, using semantic definitions Env e ⇓ 7. int.Problem 4.^ Use the type system presented on 4/8 (slides 11-14) to prove that expression^ e^ from problem 3 has type Problem 5. Consider these two top-level expressions:(1) let memcell = letin funcell n =-> let n’= !cell in (cell := n; n’);; ref 0 (a) Use the dynamic semantic definition Env-in the empty environment and state. That is, prove^ (2)^ memcell^ 5;; σ to evaluate the expression let cell= ... from expression (1), (Hint: the value is a closure.)(Reminder: Use the template on page 5 to write your answer.)^ ∅,^ ∅^ let cell^ =^ ref^ 0 in^...^ cell:=n;n′^ ⇓^ , (b) Suppose the evaluation in step (a) returns a valueexpression (2) in the environment ρ 0 = {memcell → vv} and changes the state toand state σ. σ. Then give the evaluation of Problem 6. Use the polymorphic type system from 4/10 to infer: ∅ ` let i = fun x -> (x, x) in (i 3 , i “ 3 ”) : (int ∗ int) ∗ (string ∗ string) 2
Problem 4
∅ `^ ((fun
x^ -> fun
y^ ->^ x^
+^ y)3) : ∅ ` ((fun^ x^ -> fun
y^ ->^ x^
+^ y)3)4 :
int
Problem 5.a You may use the following abbreviations to save space in the proof tree. σ^ =^ {m
ρ^ =^ {cell
→^ m} ∅,^ ∅ `^ ref 0
⇓^ m, σ ∅,^ ∅ `^ let cell=ref 0 in
Problem 6 You may use the following abbreviation to save space in the proof tree. ρ^ =^ {i^ →
∅ `^ fun
x^ ->^ (x, x
) :^ α^ →
α^ ∗^ α^
∅ `^ let
i^ =^ fun
x^ ->^ (x, x
)^ in^ (i^
3 , i^ “^3 ”) : (
int^ ∗^ int
)^ ∗^ (string
∗^ string
where TREE-B is:
ρ^ `^ 3 :
int^
ρ^ `^ “^3 ”
:^ string
ρ^ `^ (i^3
, i^ “^3 ”) : (
int^ ∗^ int
)^ ∗^ (string
∗^ string