ARTICLEalok.github.io6 min read

The Perfectability of Lean: A Journey Through Programming Languages

By Alok Singh

AI Summary

At a lively party, I was challenged to name 40 programming languages, and I rattled them off with ease. Yet, amidst the sea of languages like JavaScript, Python, and Rust, Lean stands out as the best. Why? Because it's perfectable. Lean allows you to write properties about itself within its own framework, creating a foundation of progress. In most languages, you can define a function, but Lean lets you prove properties about it, like a function always returning 5.

Languages without types often evolve to include them, as seen with PHP and Python. The push for types is inevitable, with C++ templates and Rust's constification leading the way. The ultimate goal is to do things properly, which means using dependent types. These types, akin to Turing-completeness, allow for perfectability. On top of types, you need infrastructure to prove type equality, essentially turning any dependent language into a theorem prover.

Metaprogramming is another area where Lean excels. While many languages struggle with this, Lean makes it seamless. I demonstrated this with a custom tic-tac-toe board notation, showcasing how Lean's syntax can be easily adapted and interpreted. This flexibility allows for layered API design, hiding complexity behind custom syntax.

Speed is crucial in programming, and while Lean isn't as fast as Rust, it offers significant optimization potential. By proving two functions are equal, the compiler can substitute them freely, enhancing performance. Lean's community is growing, unlike its competitors like Coq and Idris, which haven't gained the same traction. Lean combines raw programming ability with theorem proving, making it a unique and powerful tool.

This article itself is written in Lean code, a testament to its versatility and the vibrant community supporting it. Lean's perfectability and metaprogramming capabilities make it a standout choice for those seeking a language that evolves with their needs.

Key Concepts

Perfectability

The concept that something can be improved or refined continuously, reaching closer to an ideal state. In programming, it refers to the ability of a language or system to evolve and improve over time.

Dependent Types

A type system feature where types can depend on values, allowing for more expressive and precise type definitions. This enables the encoding of more complex invariants directly in the type system.

Category

Programming
M

Summarized by Mente

Save any article, video, or tweet. AI summarizes it, finds connections, and creates your to-do list.

Start free, no credit card