Here's something from Learn You...
Lambdas are normally surrounded by parentheses unless we mean for them to extend all the way to the right. Here's something interesting: due to the way functions are curried by default, these two are equivalent:
addThree :: (Num a) => a -> a -> a -> a
addThree x y z = x + y + z
addThree :: (Num a) => a -> a -> a -> a
addThree = \x -> \y -> \z -> x + y + z
If we define a function like this, it's obvious why the type declaration is what it is. There are three ->'s in both the type declaration and the equation. But of course, the first way to write functions is far more readable, the second one is pretty much a gimmick to illustrate currying.
So with the lambda version how exactly is the currying taking place? I understand something like this
doubleDouble x = (\x -> x*2) (2 * x)
So with beta reduction we have (2*x)*2, then plug in the argument.
And with this
overwrite x = (\x -> (\x -> (\x -> x) 4) 3) 2
which gives (\x -> (\x -> 4) 3) 2
(\x -> 4) 2
4
But how is the beta reduction happening with addThree?
BTW, I flunked lambda calculus in Kindergarten.
LB