r/ProgrammingLanguages • u/gaearon • Aug 17 '25
Beyond Booleans
https://overreacted.io/beyond-booleans/12
u/Fofeu Aug 17 '25
Nice introduction to Lean. As a Coq/Rocq user, I wonder though what distinguishes Lean ?
16
u/celsobonutti Aug 17 '25
Haven’t tried Coq yet, but having tried Agda, F* and Idris in the past, what distinguishes Lean IMO is that it’s in the sweet spot for the proof assistant/programming language balance: the language is equally capable of doing proofs and working as a normal, performance programming language. Too bad the ecosystem isn’t there yet, although it’s an opportunity to contribute to (I’d love to do it if I only I had the time 😓.)
6
u/777777thats7sevens Aug 17 '25
I moved from Coq to Lean, though it's been awhile since I've used Coq. The two languages feel very similar, and if you stripped away the prelude and libraries for each, you could probably reconstruct those to produce two nearly indistinguishable languages. What drew me to Lean is that it felt like its prelude and libraries had fixed a lot of cruft that existed in Coq due to historical quirks. It feels more specifically tailored to do math proofs in, so expressing math concepts in code felt a bit more natural. The tooling is also newer and a bit smoother to use, or at least it was at the time -- I remember having to wrestle with Coq to get imports working the way I expected, and it felt easier to manage in Lean.
Sorry I can't be more specific; as I mentioned it's been awhile since I used Coq.
-34
u/church-rosser Aug 17 '25 edited Aug 17 '25
So rather than rely on a sane implementation of an algebraic type system in a language that doesn't provide one as stock, we should instead rely on an adhoc poorly specified half baked and ill conceived system of runtime constraint checks over user asserted propositional logics and treat those propositions as first class types because Booleans just don't work as one would expect in a fundamentally ill conceived language that violates standard conventions of first order logic by treating null values, truth, and falsehood as ambiguously distinct from one another?
Cool story bro.
30
u/nerdycatgamer Aug 17 '25
you're on a programming language subreddit disagreeing with the notion of Curry-Howard correspondance and automated proof assistants ?
10
2
-18
u/church-rosser Aug 17 '25 edited Aug 17 '25
Did i say that? Don't think so.
Curry-Howard is great. Automated proof assistance is great.
Lean seems like a nice language for certain use cases.
I take issue with the articles conflation of ECMAscript's treatment of Booleans as somehow representative of other programming languages with a sane type system. If you want or choose to take up Lean because it scratches an itch, then by all means.
However, lauding Lean in lieu of ECMAscript because ECMAscript completely botched booleans, and expecting that conflating ECMAscript's type system with other more capable languages type systems, is shit poor reasoning.
I can accomplish plenty in a language with a sensible type system without having to migrate to a new and unproven one that uses propositional logics in lieu of typing. Just because ECMAscript and it's braindead Boolean typing sucks doesn't mean that Boolean logic is broken elsewhere, and it doesn't mean one should disavow them in favor of an alternative.
Im sure Lean is full of whiz bang goodness, and the funding and accolades it has received bear that out.
But don't piss on my leg about ECMAscript and then tell me it's raining everywhere else. It isnt.
1
u/evincarofautumn Aug 18 '25
The article’s examples in TypeScript could just as well be in Haskell. The main point is that storing only a Boolean yes-or-no answer forgets what the question was. Keeping the propositions around in dependent types is one way to be sure that it’s impossible for “yes (use dark theme)” to be misheard as “yes (incinerate computer)”.
-1
u/church-rosser Aug 18 '25
It could be, but they do have different type systems. Haskell's is at least resemblant of Lean. It would have been much more approachable article had it used Haskell as the foil.
1
u/prettiestmf Aug 18 '25
What do you mean by "runtime constraint checks" here?
0
u/church-rosser Aug 18 '25 edited Aug 18 '25
Exactly what it says, constraint checks at runtime.
if you're using a functional programming language with a dynamic runtime that includes a REPL, and that runtime environment can dynamically introspect on the arguments to an operator at runtime, then depending on the languages type-system and evaluation model, it can be possible to perform constraint checks that verify that objects in the environment meet a constraint. Which is abstractly what a theorem prover does at some point prior to reduction.
Most programming languages that serve to perform formal verification, validation, theorem proving, etc. tend to have meta programming capabilities that facilitate some amount of runtime constraints on dynamic inputs, to what degree this so depends on the language's theory of types and it's evaluation model.
ECMAscript (with or without extension frameworks) does this not so well, largely because of it's type system (or lack thereof). It would seem that Lean does this much better. My own experience with such things is largely limited to Common Lisp, which as a functional paradigm language is strongly but dynamically typed and allows mutation and side-effects. Lean appears to be more similar to ML influenced languages than most Lisp's given it's mutation model and theory of types. Regardless, at some point, given that it is a meta programming language and has an eval and check special operators, and a REPL, it (Lean) must perform some amount of runtime checks. This is the proofer aspect of Lean AFAICT but using a Calculus of Constructions (dependent type theory) to do so.
Lean seems like a near language. It also seems mostly to be a theorem prover with a novel theory of types that otherwise resembles most other well known functional programming languages (with or without mutation) which have a well specified type system. However useful it may be, it's specification and formalization seem to be lacking as yet. To that end, I don't get the appeal, it feels heavy handed overblown for most use cases, and seems mostly to be targeting hypothetical future agentic applications.
I believe there are plenty of pre existing programming languages (mostly Lisp and ML derived) that perform quite well as theorem provers while doing so with a more familiar underlying theory of types (most with Booleans) and evaluation model than what Lean provides. In my opinion ECMAscript isn't one of those languages and the article's comparison of Lean with the Typescript Framework looks like a strawman.
3
u/prettiestmf Aug 19 '25
All the constraint checks happen as part of typechecking, that's the point of the proof system. It's the real Curry-Howard. If you've got values that aren't available at compile time (reading from a file, say), sure, you need to handle invalid possibilities, same as anywhere.
Lean is, at the level of detail described here, basically a standard dependent type theory, comparable to Rocq and Agda. Dependent types aren't really novel -- Rocq dates back to 1989, Agda 1999, with real projects like CompCert using them decades ago. They're the state of the art for formalizing mathematical proofs, but they're certainly niche outside of that context. Lean has a relatively large following among mathematicians through a combination of ergonomics, outreach, and pragmatism about certain philosophical issues.
ML comes from the same academic background, just a simpler type theory which has its tradeoffs -- less expressive, but allows full type inference. Plain Hindley-Milner type systems (ordinary Haskell, ML, etc) aren't practical for theorem proving as they can't express anything about values; there's a whole zoo of intermediate levels of expressiveness (refinement types, GADTs, various other Haskell extensions) but at a certain point it really is just simpler to do full-on dependent types.
The choice of Typescript as a comparison is, I'm fairly certain, because the author is a React dev who's now trying out Lean. But it doesn't depend on any quirks of Typescript. Almost all their points apply equally well to any language with a normal Boolean system, including (afaict) baseline MLs and Haskell.
2
-20
9
u/BenchEmbarrassed7316 Aug 17 '25
I think you are comparing it to TypeScript in vain. Although in some aspects its type system looks powerful, in real applications it is not very expressive and unreliable.
Regarding a type that could have some range of numbers - in most languages you can create one by describing these rules in an imperative style. You can define methods for its behavior or even overload operators.
This approach has its drawbacks (primarily because it can be error-prone when writing the type and can be verbose in general), but from a usability perspective it's not bad. This type can also be used across the entire codebase, rather than having to describe the conditions every time (which is also error-prone).