Lamcal
lamcal is a Lambda Calculus parser and evaluator written in Rust.
It can be used to
- parse lambda expressions in classic notation into terms, like
parse_str("(λx.(λy.x y) a) b")
orparse_str("(\\x.(\\y.x y) a) b")
- construct terms programmatically using functions, e.g.
lam("x", app(var("x"), var("y")))
- construct a sequence of function applications using the macro
app!
, e.g.app![var("a"), var("b"), var("c")]
which is equivalent toapp(app(var("a"), var("b")), var("c))
- apply α-conversion to terms using different strategies, such as enumeration or appending the tick symbol
- apply β-reduction to terms using different strategies, such as call-by-name, normal-order or call-by-value
- be extended by implementing user specific strategies for α-conversion and β-reduction.
The separate crate lamcal-repl provides a command line REPL (read-evaluate-print-loop) application to play around with lambda calculus terms and applying α-conversion and β-reduction interactively.
Features:
- Evaluation function are provided in two variants: An mutable (associated) function, e.g.
Term::reduce
and an immutable (standalone) function, e.greduce
. - Strategies for α-conversion and β-reduction are defined as traits to easily implement custom strategies and use it with the functionality of this library.
- The parser gives detailed information about parse errors, like the position of the error in the source stream and what would have been expected instead in a valid expression.
- Optional support for
failure
crate compatible error types.
Usage
To use lamcal as a library in your project add this to your Cargo.toml
file:
[]
= "0.1"
and this to your crate root:
extern crate lamcal;
For details about the library see the documentation at crates.io.
This library optionally supports the failure
crate. The support for the failure
crate is a crate
feature. To enable it add the dependency to your Cargo.toml
like so:
[]
= { = "0.1", = ["failure"] }
License
Licensed under Apache License, Version 2.0 see LICENSE or http://www.apache.org/licenses/LICENSE-2.0 for details.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.