Skip to main content

Crate lolli_codegen

Crate lolli_codegen 

Source
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 LogicRust Type
A ⊸ Bimpl FnOnce(A) -> B
A ⊗ B(A, B)
A & BWith<A, B> (lazy pair)
A ⊕ BEither<A, B>
1()
⊤Top (unit type)
0Void (empty type)
!ARc<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.
RustCodegen
Rust code generator.
Sequent
A one-sided sequent ⊢ Γ.
TypeGenerator
Generates Rust types from linear logic formulas.

Enums§

Formula
A linear logic formula.
Term
Linear λ-terms extracted from proofs.

Constants§

PRELUDE
Prelude code to include in generated modules.

Functions§

generate_function
Generate a complete Rust function from a sequent and term.