Docsity

Lambda Calculus Homework: Reducing Lambda Terms and Translating C Code, Assignments of Programming Languages

Toggle sidebar
bg1
Homework 4 (25pts)
Due before class Feb 18, 2009
1. Reduce the following lambda terms to normal forms. For each reduction step, mark
the function abstraction and the parameter value being reduced.
(a) (λx. λy. y x) 5
(b) (λx. λy. y x) 5 (λz .z + 3)
(c) (λx. λy. x y) (λz .z +y) 7
(d) (λy.(λx. λy. x y) (λz.y z) 7) (λx.x + 1)
2. Translate the following C code to lambda calculus.
int apply_twice (int (*f) (...), int x) { return f(x); }
int twice (int (*g)(...), int y) { return y + apply_twice(g, y); }
int foo(int x) { return x + x; }
int main() { return twice(foo, 5); }
1

Partial preview of the text

Download Lambda Calculus Homework: Reducing Lambda Terms and Translating C Code and more Assignments Programming Languages in PDF only on Docsity!

Homework 4 (25pts)

Due before class Feb 18, 2009

  1. Reduce the following lambda terms to normal forms. For each reduction step, mark the function abstraction and the parameter value being reduced.

(a) (λx. λy. y x) 5 (b) (λx. λy. y x) 5 (λz.z + 3) (c) (λx. λy. x y) (λz.z + y) 7 (d) (λy.(λx. λy. x y) (λz.y z) 7) (λx.x + 1)

  1. Translate the following C code to lambda calculus.

int apply_twice (int (f) (...), int x) { return f(x); } int twice (int (g)(...), int y) { return y + apply_twice(g, y); } int foo(int x) { return x + x; } int main() { return twice(foo, 5); }