Zulip Chat Archive

Stream: new members

Topic: Lean Compilation to Other Languages


Daniel Geisz (Aug 17 2024 at 03:58):

Hey all, I've been looking a bit at Dafny and noticed that it compiles to a bunch of different languages (Go, Python, Java, etc). Wondering if there's anything similar in Lean or any desire for something like this? Just would be cool if you could write a verified program in Lean and then compile it to another more common language for use there

Bulhwi Cha (Aug 17 2024 at 06:49):

Honestly, I'm satisfied with using Dafny to write a verified program and compile it into other languages.

Johan Commelin (Aug 17 2024 at 09:27):

Atm the only options are C and WebASM I think

Eric Wieser (Aug 17 2024 at 09:38):

Writing CPython / lean bindings would be a nice project

Eric Wieser (Aug 17 2024 at 09:39):

(that is, code to convert between basic lean_object* types and PyObject*s)

Eric Wieser (Aug 17 2024 at 09:39):

Then you could compile lean to C code, then write / generate a small wrapper to create python bindings for that C code

Sebastian Ullrich (Aug 17 2024 at 10:37):

The general answer here is that Lean does not compile to other languages as it is a general-purpose language in itself. So you do like you do in other general-purpose languages and use FFI to communicate with external languages.

David⚛️ (Sep 26 2024 at 16:11):

Eric Wieser said:

Then you could compile lean to C code, then write / generate a small wrapper to create python bindings for that C code

I've been trying to compile lean to C code but is not working for me

Eric Wieser (Sep 26 2024 at 17:16):

What have you tried? This is supported natively by lake

Tom (Sep 26 2024 at 18:56):

Eric Wieser said:

Writing CPython / lean bindings would be a nice project

I am about to embark on reading more about Lean's FFI, even though my understanding is that it's still... provisional/unstable?

I've done a lot of work with Python/C++ bindings. What are you imagining you would use the bindings for? Are you looking to call compiled Lean code from Python, or calling Python functionality (e.g. numpy?) from Lean?


Last updated: May 02 2025 at 03:31 UTC