Remix.run Logo
▲ chamomeal an hour ago

I’ve only heard of these neato languages on hackernews. Could you write a regular ol’ program with a language like Lean? Like a web server or CLI? And would it be like… proved?? Do “proofs” make sense in the context of regular ol’ software?

▲solomonb an hour ago | parent | next [-]

> Could you write a regular ol’ program with a language like Lean? Like a web server or CLI?

Yes, absolutely you can build a web server or CLI tool in Lean.

The compiler lowers your code to C, and a bundled clang turns that C into a native binary so it can actually be fast. It also has an FFI. The community is small but there are a growing number of general purpose libraries.

Lean is a pure functional programming language whose type system is strong enough to write proofs. To keep proofs sound, it adds some constraints, but there are escape hatches and you can absolutely use them for general purpose programming.

If you want to see a dependently typed language that can act as a proof checker but is actually aimed at building "regular" software, check out Idris.

> And would it be like… proved??

No, using one for a "regular" programming does not mean you have done any formal verification. You would have to specifically use the theorem proving language features to prove anything.

> Do “proofs” make sense in the context of regular ol’ software?

Yes! You can write proofs about invariants in your program and have the compiler enforce them. For example, you could write a list index function that requires a proof that the index is in bounds. Writing proofs is hard and you have to think like a type theorist, but you can do some really cool stuff in these languages.

▲agentultra an hour ago | parent | prev | next [-]

Yeah you totally can.

https://agentultra.github.io/lean-4-hackers/

You don’t need to write proofs. You can if you want to. Like you could prove that adding two sized vectors results on a new sized vector with the appropriate length. That’s a trivial one but the sky’s the limit with what iou want to prove about your programs.

▲tomhp an hour ago | parent | prev | next [-]

Yes, in certain contexts a “proof” of software can be useful. See https://compcert.org/ for a formally verified C compiler; I know it’s been used to compile C code for aircraft. I’m not entirely sure how useful Lean is for developing software like this, but I know it has some facilities to do so.

▲pegasus an hour ago | parent | prev [-]

Yes. There are verified compilers and OS kernels for example. Here's a recent example for someone coding a simple, yet surprisingly performant web server in Lean: https://theoric.com/blog/deriving_the_runtime/