Chapter 1: All You Need is Lambda

This note captures my solutions to exercises in Chapter 1: All You Need is Lambda of the book Haskell programming from first principles

Intermission: Equivalence Exercises

  1. λxy.xz\lambda x y . x z is equivalent to (b) λmn.mz.\lambda m n . m z.

  2. λxy.xxy\lambda x y . x x y is equivalent to (c) λa.(λb.aab).\lambda a . (\lambda b . a a b).

  3. λxyz.zx\lambda x y z . z x is equivalent to (b) λtos.st.\lambda t o s . s t.

Combinators Exercise

  1. λx.xxx\lambda x.xxx is a combinator.

  2. λxy.zx\lambda xy.zx is not a combinator because zz is a free variable.

  3. λxyz.xy(zx)\lambda xyz.xy(zx) is a combinator.

  4. λxyz.xy(zxy)\lambda xyz.xy(zxy) is a combinator.

  5. λxy.xy(zxy)\lambda xy.xy(zxy) is not a combinator because zz is a free variable.

Normal form or diverge

  1. λx.xxx\lambda x.xxx is a normal form.

  2. (λz.zz)(λy.yy)(\lambda z.zz)(\lambda y.yy) diverges.

  3. (λx.xxx)z(\lambda x.xxx)z can be reduced to the normal form, zzzzzz.

Beta reduce

  1. (λabc.cba)zz(λwv.w)(\lambda abc.cba)zz(\lambda wv.w) reduces to zz.

  2. (λx.λy.xyy)(λa.a)b(\lambda x . \lambda y .xyy)(\lambda a.a)b reduces to bbbb.

  3. (λy.y)(λx.xx)(λz.zq)(\lambda y .y)(\lambda x.xx)(\lambda z.zq) reduces to qqqq.

  4. (λz.z)(λz.zz)(λz.zy)(\lambda z.z)(\lambda z.zz)(\lambda z.zy) reduces to yyyy.

  5. (λx.λy.xyy)(λy.y)y(\lambda x. \lambda y.xyy)(\lambda y.y)y reduces to yyyy.

  6. (λa.aa)(λb.ba)c(\lambda a.aa)(\lambda b.ba)c reduces to aacaac.

  7. (λxyz.xz(yz))(λx.z)(λx.a)(\lambda xyz.xz(yz))(\lambda x.z)(\lambda x.a) reduces to (λz1.za)(\lambda z1.za).

Since the book has solutions for the chapter exercises, refer to Haskell programming from first principles for detailed solutions.