Beta reduction is when we replace the bound variable with the concrete argument in the function body until we end up with an expression. Let's take the application
(λf.(f λf.f) λs.(s s)).
In this application we have two functions
λf.(f λf.f) and
λs.(s s) where the second is being provided as an argument to the first one. If we were to replace all instances of bound variables with the argument being applied to it, the process on this application would look like this:
(λf.(f λf.f) λs.(s s)) => (λs(s s) λf.f) => (λf.f λf.f) => λf.f
The β-reduction above demonstrates that
can be reduced to
(λf.(f λf.f) λs.(s s))
λf.f, which is the identity function.
const compose = f => g => x => f(g(x)) const addOne = a => a + 1 const double = a => a * 2 const applyAddOne = compose(addOne) const applyDoubleThenAddOne = applyAddOne(double) applyDoubleThenAddOne(2) // equals 5
Which gets reduced like this:
f => g => x => f(g(x)) g => x => addOne(g(x)) x => addOne(double(x)) addOne(double(2))
The end result is a function which takes an argument and applies
double and then applies
addOne. It's simple, but it's handy for reasoning about the results of functions in lambda calculus.