Skip to content

Latest commit

 

History

History
57 lines (40 loc) · 1.73 KB

README.md

File metadata and controls

57 lines (40 loc) · 1.73 KB

Rust

leanfran for Rust: write Lean blocks with lean!, call them through Rust types, and verify supported Rust functions against Lean specifications.

Install

Install the Lean compiler and verification tools:

nix profile install 'github:conao3/lean-leanfran#rust'

Generation requires Lean 4.35.0 (lean and lake) on PATH. Add these dependencies to your crate:

[dependencies]
leanfran = "0.7.0"

[build-dependencies]
leanfran-build = "0.7.0"

First Lean block

Add build.rs:

fn main() {
    leanfran_build::Builder::new().compile().unwrap();
}

Then add a block to src/main.rs:

leanfran::lean! {
    pub mod arith;
    r#"
    def double (n : Nat) : Nat := n + n

    theorem double_eq (n : Nat) : double n = 2 * n := by
      unfold double; omega
    "#
}

fn main() {
    assert_eq!(arith::double(21u64.into()), 42u64.into());
}

cargo build checks the Lean source and generates Rust. Commit lean/ and .leanfran/cache/ so subsequent builds can use the generated code. See the guide for publishing a crate with its cache.

Next steps