| Crates.io | minilamb |
| lib.rs | minilamb |
| version | 0.1.1 |
| created_at | 2025-07-21 19:57:36.69503+00 |
| updated_at | 2025-07-22 19:45:27.073873+00 |
| description | A minimal lambda calculus library in Rust |
| homepage | |
| repository | https://github.com/TeddyHuang-00/minilamb |
| max_upload_size | |
| id | 1762554 |
| size | 185,690 |
A minimal lambda calculus library in Rust.
λ, \, /, | lambda symbols with comprehensive error handlingabs! and app! macros for expression constructionAdd minilamb to your Cargo.toml:
[dependencies]
minilamb = "0.1"
use minilamb::{parse, evaluate, abs, app};
// Parse and evaluate expressions
let expr = parse("(λx.x) (λy.y)")?;
let result = evaluate(&expr, 1000)?;
println!("{result}"); // λy.y
// Use ergonomic macros
let identity = abs!(1); // λx.x using De Bruijn index
let application = app!("f", "x", "y"); // f x y
// Parse different lambda formats
let expressions = ["λx.x", "\\x.x", "/x.x", "|x.x"];
for expr_str in expressions {
let expr = parse(expr_str)?;
println!("{expr_str} -> {expr}");
}
use minilamb::{parse_and_evaluate, Expr};
// Church encodings
let church_true = parse("λt.λf.t")?;
let church_false = parse("λt.λf.f")?;
let church_two = parse("λf.λx.f (f x)")?;
// Evaluation with step limits
let result = parse_and_evaluate("(λx.λy.x) a b", 100)?;
println!("{result}"); // a
minilamb uses a 4-variant expression system optimized for both correctness and binary size:
pub enum Expr {
BoundVar(usize), // De Bruijn indices (1-based)
FreeVar(String), // Named variables
Abs(usize, Box<Expr>), // Lambda abstractions with explicit levels
App(Vec<Expr>), // Multi-argument applications
}
Run the included demo to see minilamb in action:
cargo run --example demo
This demonstrates:
λ, \, /, |)Always run these commands before committing:
# Format, lint, and test
cargo fmt
cargo clippy --all-targets --all-features -- -D warnings
cargo test
# Or use the justfile
just check
minilamb/
├── src/
│ ├── lib.rs # Public API and convenience functions
│ ├── expr.rs # Expression types and IntoExpr trait
│ ├── engine.rs # β-reduction evaluation and simplification
│ ├── parser.rs # Recursive descent parser
│ └── lexer.rs # Multi-format tokenizer
├── examples/
│ └── demo.rs # Usage demonstration
└── tests/
└── integration_test.rs # End-to-end tests
The project maintains 135+ tests covering:
This project is licensed under either of
at your option.
Contributions are welcome! Please ensure all quality checks pass:
cargo fmt && cargo clippy --all-targets --all-features -- -D warnings && cargo test
The project follows strict security and quality guidelines:
.unwrap() or .expect())