Homework 5 Sample Solution - Programming Analysis and Understanding | CMSC 631, Assignments of Computer Science

Material Type: Assignment; Professor: Foster; Class: PROG ANLYS&UNDERSTANDING; Subject: Computer Science; University: University of Maryland; Term: Spring 2009;

Typology: Assignments

Pre 2010

Uploaded on 07/30/2009

koofers-user-kvm
koofers-user-kvm 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC 631, Spring 2009
Homework 5 Sample Solution (partial)
1. (a) (λx.x(xy))(λu.u)(λu.u)((λu.u)y)((λu.u)y)y
(b) (λxyz.z yx)aa(λpq.q)(λpq.q)aa a
(c) (λxyz.xz (yz))(λxy .x)(λxy.x)λz.(λxy.x)z((λxy.x)z)λz.z
2. (a) λxy.y
(b) λxyz.xz y
(c) No term has the type αβ
(d) λxy.(λf wz.((λv .fw)(f z)))(λu.u)xy
3. No, the simply typed lambda calculus with integers does not have the subject expansion property.
For example, the term 3 has a valid type, but the term (λxy.x)3(λz. ∆) 3 yet it does not
have a valid type. (Recall that = λx.xx.) Note that we must put under a λbecause we’re
using call-by-value semantics. In particular, (λxy.x) 3 (∆ ∆) does not reduce to 3 under call-by-value
semantics because the evaluation of never terminates.
1

Partial preview of the text

Download Homework 5 Sample Solution - Programming Analysis and Understanding | CMSC 631 and more Assignments Computer Science in PDF only on Docsity!

CMSC 631, Spring 2009

Homework 5 Sample Solution (partial)

  1. (a) (λx.x(xy))(λu.u) → (λu.u)((λu.u)y) → ((λu.u)y) → y

(b) (λxyz.zyx)aa(λpq.q) → (λpq.q)aa → a (c) (λxyz.xz(yz))(λxy.x)(λxy.x) → λz.(λxy.x)z((λxy.x)z) → λz.z

  1. (a) λxy.y

(b) λxyz.xzy (c) No term has the type α → β (d) λxy.(λf wz.((λv.f w)(f z)))(λu.u)xy

  1. No, the simply typed lambda calculus with integers does not have the subject expansion property. For example, the term 3 has a valid type, but the term (λxy.x) 3 (λz.∆ ∆) →∗^ 3 yet it does not have a valid type. (Recall that ∆ = λx.xx.) Note that we must put ∆ ∆ under a λ because we’re using call-by-value semantics. In particular, (λxy.x) 3 (∆ ∆) does not reduce to 3 under call-by-value semantics because the evaluation of ∆ ∆ never terminates.