Evaluating the lambda expression $(.)(.)(.)$

454 Views Asked by At

In the book of Haskell Programming by C. Allen, at page 39, it is given the following lambda expression

$$(.)(.)(.)$$

According to me, this equals to by applying the left two expression as an input for the rightmost expression

$$(.)(.)(.) = (.)(.)y = (.)yz = yzy,$$

and if we read the main expression as

However, the book the result is (I did not understand the argument they provide) $$.,$$

so which one of us is correct ?

Edit:

Now, after reviewing my calculation, I have

\begin{align} (.)(.)(.) &= [(x(y.xxy))(a.ab)](c.cd) \\ &= (y.(a.ab)(a.ab)y)(c.cd) \\ &= (a.ab)(a.ab)(c.cd) \\ &= [(a.ab)(a.ab)](c.cd) \\ &= [(a.ab)b](c.cd) = bb(c.cd) \end{align}

however, this result does not make any sense, so where is the mistake that I'm doing in here ?

Edit 2:

enter image description here

2

There are 2 best solutions below

0
On BEST ANSWER

Your error (in the OP before your edit) is that $xxy$ stands for $(xx)y$, since application is left-associative. So, when in $xxy$ you substitute $\lambda x.xy$ for $x$, and $\lambda x. xz$ for $y$, what you get is \begin{align}\tag{1} \big((\lambda x.xy)(\lambda x.xy)\big)\lambda x.xz \end{align} which cannot be reduced to $(\lambda x.xy)(\lambda x.xz)y$. On the contrary, $(1)$ reduces in the following way: \begin{align} \big((\lambda x.xy)(\lambda x.xy)\big)\lambda x.xz =_\beta \big((\lambda x.xy)y\big)\lambda x.xz =_\beta (yy)\lambda x. xz \end{align}

In the book, the term $\lambda z.z$ is the result of the evaluation of the term $(\lambda xyz.xz(yz))(\lambda mn.m)(\lambda p.p)$, which has nothing to do with the term $(\lambda xy.xxy)(\lambda x.xy)(\lambda x.xz)$, it is just a different and completely unrelated example.

0
On

It appears that the book first presents one example and then just moves to another one, as $(λxy.xxy)(λx.xy)(λx.xz)$ is not equivalent to $(λxyz.xz(yz))(λmn.m)(λp.p)$.

In order to not get confused with clashing variable names I prefer to use De Bruijn indices; the initial expression would then be:

$(λλ221)(λ12)(λ12)$

and it would reduce (with normal order) as follows:

$(λ(λ13)(λ13)1)(λ12)$

$(λ12)(λ12)(λ12)$

$(λ12)1(λ12)$

$11(λ12)$ - equivalent to your result, $bb(λc.cd)$