I'm going through the book "Haskell programming from first principles" and although the authors try to explain in detail how to reduce expressions, I still have trouble understanding how to read some expressions in the examples provided.
Let's assume the below expression:
(λx.x)
Then if I understand things correctly this can be read as: "A lambda function, that accepts an argument x
and returns (basically translating .
as "returns") the same value x
.
Now supposing that that we have the below expression:
(λxy.xy)
, how do we read that expression in plain English? To make it even more complex the authors then expand (λxy.xy)
to (λxy.xy)(λz.a) 1
. How are these z
and a
appearing to the above expression? I was hoping that if I can properly transform the expression to plain English I'd be able to understand where z
and a
come from.
In lambda calculus, values that are next to each other imply that the first value is being called as a function with the second value as an argument.
(λxy.xy)
is shorthand for(λx.λy.xy)
, which means a function that takes an argument x then an argument y, and calls x with argument y. (if you're wondering why there's a function returning a function, it's due to currying). To figure out what(λxy.xy)(λz.a) 1
means, we have to take it step by step:(λx. λy. xy) (λz. a) 1
λx
):(λy. (λz. a) y) 1
λy
):(λz. a) 1
λz
):a
So, we end up with whatever
a
is (probably an externally defined constant).