[][src]Enum lalrpop_lambda::Expression

pub enum Expression {
    Var(Variable),
    Abs(Abstraction),
    App(Application),
}

A mutually recursive definition for all lambda expressions

let parser = lalrpop_lambda::parse::ExpressionParser::new();

assert!(parser.parse("λx.(x x)").is_ok());

Variants

Var(Variable)Abs(Abstraction)App(Application)

Methods

impl Expression[src]

pub fn rename(&self, old: &Variable, new: &Variable) -> Self[src]

α-conversion

pub fn apply(&self, η: bool) -> Self[src]

β-reduction small-step semantics.

η: Local completeness in natural deduction.

Local reducibility in natural deduction.

pub fn normalize(&self, η: bool) -> Self[src]

Big-step natural semantics.

η: Global completeness in natural deduction.

Global reducibility in natural deduction.

let parser = lalrpop_lambda::parse::ExpressionParser::new();

let expression = parser.parse("((λx.(λy.x y) b) a)").unwrap();
let normal = parser.parse("a b").unwrap();

assert_eq!(normal, expression.normalize(false));

pub fn variables(&self) -> HashSet<Variable>[src]

pub fn free_variables(&self) -> HashSet<Variable>[src]

FV(M) is the set of variables in M, not closed by a λ term.

use std::collections::HashSet;
use lalrpop_lambda::Variable;

let parser = lalrpop_lambda::parse::ExpressionParser::new();

let mut free = HashSet::new();
free.insert(Variable("y".into()));

let expression = parser.parse("λx.(x y)").unwrap();

assert_eq!(free, expression.free_variables());

pub fn resolve<T: From<Expression>>(
    &self,
    env: &HashMap<Variable, Expression>
) -> Option<T> where
    Expression: From<T>, 
[src]

let env = map! {
    variable!(id) => abs!{x.x},
//     variable!(a) => app!(id,"a".into()),
    variable!(x) => 1.into(),
};
assert_eq!(None, var!(q).resolve::<u64>(&env));
assert_eq!(Some(1), var!(x).resolve::<u64>(&env));
// assert_eq!(Some("a"), var!(a).resolve::<String>(&env));
// assert_eq!(Some((1,2)), var!(id).resolve::<(u64,u64)>(&env)(1,2));
// assert_eq!(None, abs!{x.x}.resolve::<Fn()>(&env));

Trait Implementations

impl Eq for Expression[src]

impl PartialEq<Expression> for Expression[src]

impl Clone for Expression[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<T> FnOnce(T) for Expression where
    T: Into<Expression> + From<Expression>, 
[src]

Function call support for an Expression.

assert_eq!(0u64, λ!{x.x}(0).into());
assert_eq!(γ!(γ!(a,b),0), γ!(a,b)(0));

type Output = Expression

The returned type after the call operator is used.

impl From<u64> for Expression[src]

Church encoded natural numbers

assert_eq!(0, u64::from(λ!{f.λ!{x.x}}));
assert_eq!(1, u64::from(λ!{f.λ!{x.γ!(f,x)}}));
assert_eq!(3, u64::from(λ!{f.λ!{x.γ!(f,γ!(f,γ!(f,x)))}}));

impl From<Expression> for u64[src]

Convert λ term back to native Rust type

assert_eq!(0, u64::from(λ!{f.λ!{x.x}}));
assert_eq!(1, u64::from(λ!{f.λ!{x.γ!(f,x)}}));
assert_eq!(3, u64::from(λ!{f.λ!{x.γ!(f,γ!(f,γ!(f,x)))}}));

impl Debug for Expression[src]

impl Display for Expression[src]

impl Add<Expression> for Expression[src]

type Output = Self

The resulting type after applying the + operator.

impl Mul<Expression> for Expression[src]

type Output = Self

The resulting type after applying the * operator.

Auto Trait Implementations

impl Send for Expression

impl Sync for Expression

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<A, F> FnBox<A> for F where
    F: FnOnce<A>, 
[src]