In functional programming and lambda calculus, combinators are small,
reusable function patterns. They don’t rely on variables or external state — they only
use the inputs you give them. Think of them as the “grammar rules” of functions.
Below, each combinator is explained as if a lecturer is guiding you through the intuition,
the purpose, and the Python equivalent.
1. Identity Combinator (I)
Lecturer’s explanation:
The Identity combinator is the simplest possible function. It takes an input and returns
it unchanged. In programming, this is useful when you need a placeholder function — one
that does nothing but pass the value through.
Think of it like a mirror: whatever you put in front of it is exactly what you get back.
| Lambda Calculus |
Python Equivalent |
| λx.x |
I = lambda x: x |
2. Constant Combinator (K)
Lecturer’s explanation:
The Constant combinator takes two inputs but always returns the first one.
This is surprisingly useful: it lets you “freeze” a value and ignore anything that comes later.
Imagine someone hands you a pizza and then hands you a carrot. You keep the pizza and ignore the carrot.
That’s exactly what K does.
| Lambda Calculus |
Python Equivalent |
| λxy.x |
K = lambda x: (lambda y: x) |
3. Substitution Combinator (S)
Lecturer’s explanation:
The S combinator is more interesting. It takes two functions and one value.
Then it applies the value to both functions and combines the results.
Think of it like this:
You have a piece of wood. You give it to a builder (who shapes it) and a painter (who colors it).
Then you combine the shaped wood and the painted wood into a final product.
This pattern appears everywhere in functional programming — it’s the foundation of how
you apply the same input to multiple functions.
| Lambda Calculus |
Python Equivalent |
| λxyz. x(z)(y(z)) |
S = lambda x: (lambda y: (lambda z: x(z)(y(z)))) |
4. Self‑Apply Combinator (B)
Lecturer’s explanation:
The B combinator applies a function to itself.
This may sound strange, but it’s the seed of recursion — the idea that a function can
call itself to solve a problem.
Imagine giving a machine its own blueprint.
The machine builds another machine exactly like itself.
That’s what B does.
| Lambda Calculus |
Python Equivalent |
| λx.xx |
B = lambda x: x(x) |