Hacker News new | ask | show | jobs
by braabe 20 days ago
I have started learning Lean this year and have recently stumbled on the concept of subtypes in Lean: For a subtype S of a type T, an element is a tuple <t, P t> of an element t of type T and a proof of a predicate P on t.

An example of this could be the subtype AuthenticatedUser of the type User or the subtype SearchTree of the type BinaryTree. Any time you want to change the element (By updating user data or by inserting a node in a tree), you have to reattach a proof for the modified element or the type-checker will straight up reject it.

It is, of course, a lot of work to (re)construct the proofs, but for me this strikes the perfect middleground between "formalize all your code and try to finish before retirement/bankruptcy" and "just ship and hope you didn't mess up". If you have a critical part of your software, you can formalize some characteristic on it and guarantee (!) that no one further down the pipeline will mess it up. And you can do that while leaving most of your other code untouched.