Alpha and eta conversions

In the previous chapter we ran into an important problem that arises during substitution. Here we look more closely at how to solve it.

α-conversion

The name of a bound variable is no more than a label: λx. x\lambda x.\,x and λy. y\lambda y.\,y are one and the same function.

λx. M  \displaystyle \lambda x.\,M \; =α  λy. M[x:=y],\displaystyle {} =_\alpha\; \lambda y.\,M[x{:=}y],​y\displaystyle y​∉FV(M)\displaystyle {} \notin \mathrm{FV}(M)
(1.6)

The especially gifted folks skip the renaming hassle altogether and use de Bruijn indices: the lambdas themselves stay but become nameless, while every occurrence of a variable is written as a number — how many lambdas you must go up from it to reach its binder (counting from zero, 00 being the nearest enclosing lambda). Then α-equivalent terms get one and the same representation, and α-conversion disappears as a concept.

  • λx. x\lambda x.\,x → λ. 0\lambda.\,0 (the only variable points to its own lambda);
  • λx. λy. x y\lambda x.\,\lambda y.\,x\,y → λ. λ. 1 0\lambda.\,\lambda.\,1\,0 (xx became 11, and yy became 00).

η-conversion

This is really a small thing, but still worth a brief mention. η-conversion says that the “wrapper” λx. M x\lambda x.\,M\,x is no different from MM itself.

λx. (M x)  \displaystyle \lambda x.\,(M\,x) \; =η  M,\displaystyle {} =_\eta\; M,​x\displaystyle x​∉FV(M)\displaystyle {} \notin \mathrm{FV}(M)
(1.7)

η-reduction collapses such a wrapper to the left, while η-expansion unfolds it to the right.

In Haskell this is the familiar point-free style:

sum xs = foldr (+) 0 xs
-- becomes
sum = foldr (+) 0