Expand description
§lolli-codegen
Code generation for the Lolli linear logic workbench.
This crate generates Rust code from linear logic proofs, translating formulas to types and terms to code.
§Linear Logic to Rust Mapping
| Linear Logic | Rust Type |
|---|---|
| A ⊸ B | impl FnOnce(A) -> B |
| A ⊗ B | (A, B) |
| A & B | With<A, B> (lazy pair) |
| A ⊕ B | Either<A, B> |
| 1 | () |
| ⊤ | Top (unit type) |
| 0 | Void (empty type) |
| !A | Rc<A> (shared) |
§Example
use lolli_codegen::RustCodegen;
use lolli_core::{Formula, Term};
let codegen = RustCodegen::new();
// Formula to type
let lolli = Formula::lolli(Formula::atom("A"), Formula::atom("B"));
assert_eq!(codegen.formula_to_type(&lolli), "impl FnOnce(A) -> B");
// Term to code
let mut codegen = RustCodegen::new();
let id = Term::Abs("x".to_string(), Box::new(Term::Var("x".to_string())));
assert_eq!(codegen.term_to_code(&id), "|x| x");Structs§
- Proof
- A proof in the sequent calculus.
- Rust
Codegen - Rust code generator.
- Sequent
- A one-sided sequent ⊢ Γ.
- Type
Generator - Generates Rust types from linear logic formulas.
Enums§
Constants§
- PRELUDE
- Prelude code to include in generated modules.
Functions§
- generate_
function - Generate a complete Rust function from a sequent and term.