r/ProgrammingLanguages • u/FurCollarCriminal • May 21 '24
Why do we love the lambda calculus?
I've been reading about some of the more esoteric models of computation lately, and it got me wondering why it is that the lambda calculus is the "default". So much literature has been built up around it now that it's hard to imagine anything different.
Is it merely the fact that the lambda calculus was the 'first to market'? Or does it have properties that make it obviously preferable to other models of computation such as combinators, interaction nets, kahn process networks, etc?
77
Upvotes
91
u/FantaSeahorse May 21 '24
It is simple, with only 3 syntactic forms. This means that it is good as a “foundational model”. It’s similar to how we usually prefer logical systems with fewer axioms and rules of inference.
It also captures the idea of substitution very well. (see what I did there?)
I believe the another important reason is that it is purely syntactic: the operational semantics just consist of rules of how to rewrite symbols. This fits the trend of the study of formal languages back in the days
33
u/naughty May 21 '24
There are quite a few algorithmic and complexity contexts where Turing Machines are the most natural foundation and lambda calculus is quite clunky, so it doesn't always win.
Lambda Calculus tends to beats the others when it comes actual programming though. Non of the other foundations are parametric, i.e. they don't take arguments, so structuring things is painful. Look up the Y combinator in LC versus SKI combinators and the LC version can be understood directly after a little while, the combinator version is something you can prove works but is just obtuse.
Concatenative stack based formalisms probably come closest to LC in many ways.
23
u/bl4nkSl8 May 21 '24
Pretty sure the alternatives are worse with the possible exception of some combinator based systems...
SKI combinators are horrible to follow
Turing machines and little languages like brai fuck are pretty irreducible
SSA is pretty good, and often associated with lambda calc, but people tend to struggle with Phi nodes
Not sure about other alternatives. There's some rewriting systems that are neat, but more complex imo
15
u/Disjunction181 May 21 '24
I think about this often myself. Universality is such a key point and the lambda calculus appears to be an arbitrary construction.
I think the first key difference is that the lambda calculus is somehow more comfortable and more composable than the other computational paradigms. Combinatory logic and concatenative combinators often lend themselves to syntactic messes that are difficult to sort out. Lambda calculus seems to strike a balance where parameters are labelled but arguments are not. Automata like Turing machines are notoriously hard to write programs in, and tape-based machines don't compose very well since tapes aren't structurally inductive.
I think the second key difference is that the lambda calculus is easy to modify and control. By adding types to the lambda calculus, you can control its expressivity and its ability to express recursion. The types exist an order above terms so we can talk about typing programs without actually changing the program, or we can talk about the addition of features with an accompanying change to the type system. With automata, you have to change the structure of the machine, e.g. Turing Machine to stack machine, to control power, and this seems more awkward.
And I think where things really start to take off is with System F because of the stunning connections to logic and the power of free theorems. The realization that System F is an algorithmic instance of intuitionistic logic and that types embed simple intuitionistic proofs. E.g.
a -> b -> (a, b) is analogous toa ==> b ==> a /\ b, or that a pair of proofs is a proof of the conjunction, the realization the fixpoint combinator(a -> a) -> ais logically nonsensical because it is literally the admission of circular logic into your system, and so on. And free theorems can indicate to you what terms are by just looking at their type: the classic example is thatforall a, a -> amust be the identity function in a total system. System F can be extended with type constructors and dependent types so that richly typed programs can constitute proofs.So I don't completely understand why the lambda calculus is so fundamental, but I've become convinced empirically from working on type systems that there's really something there. It's extremely extensible due to having a universe hierarchy where types make terms safe, which allows for the addition of all sorts of different features, and the connections to logic are very surprising.
1
u/nathan_s_chappell May 22 '24
Haven't you read "category theory for programmers"? The essence of computation is substitution! Wait, that's not right...
Basically, lambda calculus is absolutely amazing because it crystalizes:
Those are quite powerful concepts, probably worth pondering a bit...
3
u/cdsmith May 21 '24
Lambda calculus is:
That's the full answer, I think. There are simpler or equally simple models of computation, but they don't really let you do abstraction directly within the model, so they aren't suitable for more than formal analysis of computation itself or some intermediate representation. There are also other models of computation that can express abstraction and have nice denotational semantics, but they are much more complex than lambda calculus with its three syntactic forms and only one non-trivial evaluation rule.
3
u/Tonexus May 21 '24
It's a bit of a stretch to call lambda calculus the "default". In complexity theory, TMs and uniform circuit models are the standard since lambda calculus computations don't really have a reasonable notion of "cost".
3
u/kniebuiging May 21 '24
My totally uninformed guess: it’s expressions are compositional. If you build two state machines and you want to combine them you are up for some heavy liftingy
7
u/zyxzevn UnSeen May 21 '24
From theory it is liked, because it matches with mathematical logic. And that allows for certain tricks and certain proofs.
Personally, I don't like it. I think it is often obfuscating, not abstracting, the data-flow and program-flow.
2
u/ericbb May 21 '24
Not so much an answer to the question but just a link to a presentation that complements the discussion: Two Kinds of Foundations.
1
u/integrate_2xdx_10_13 May 21 '24
The Curry-Howard Correspondence gives rises to types as proofs via {products/conjugation} and {function application/implication}
-3
u/kleram May 21 '24
I do not love it, because it's just big buzz about function parameters getting replaced with arguments upon function application.
-1
u/ThyringerBratwurst May 21 '24 edited May 23 '24
Konrad Zuse already used the lambda calculus as the basis for his programming language "Plankalkül", the first of its kind on the world's first digital computer.