2 unstable releases
| 0.2.0 | Dec 5, 2025 |
|---|---|
| 0.1.0 | Dec 4, 2025 |
#1705 in Programming languages
Used in lolli-cli
60KB
1K
SLoC
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");
lolli-codegen
Code generation for the Lolli linear logic workbench.
Generates Rust code from linear logic proofs, enforcing resource invariants at compile time.
Type Mapping
| Linear Logic | Rust Type |
|---|---|
| A ⊗ B | (A, B) |
| A ⊸ B | impl FnOnce(A) -> B |
| A & B | With<A, B> |
| A ⊕ B | Either<A, B> |
| !A | Rc<A> |
| 1 | () |
| 0 | ! (never) |
Usage
use lolli_codegen::RustCodegen;
let mut codegen = RustCodegen::new();
let rust_code = codegen.generate_module(&proofs);
Part of Lolli
This is part of the Lolli linear logic workbench.
License
MIT
Dependencies
~100–440KB
~10K SLoC