Enum lamcal::Term[][src]

pub enum Term {
    Var(String),
    Lam(VarBox<Term>),
    App(Box<Term>, Box<Term>),
}

A term in the lambda calculus.

Variants

A variable (x)

A character or string representing a parameter or mathematical/logical value.

An abstraction (λx.M)

Function definition (M is a lambda term). The variable x becomes bound in the expression.

An application (M N)

Applying a function to an argument. M and N are lambda terms.

Methods

impl Term
[src]

Returns whether this Term is a beta redex.

A beta redex is a term of the form (λx.A) M

The term redex, short for reducible expression, refers to subterms that can be reduced by one of the reduction rules.

Returns whether this Term is a beta normal form.

A beta normal form is a term that does not contain any beta redex, i.e. that cannot be further reduced.

Performs an α-conversion on this Term.

Substitutes all occurrences of var as free variables with the expression rhs recursively on the structure of this Term.

Applies the expression rhs to the param of this lambda abstraction if this Term is of variant Term::Lam by recursively substituting all occurrences of the bound variable in the body of the lambda abstraction with the expression rhs.

If this Term is not a lambda abstraction this function does nothing.

To avoid name clashes this function performs α-conversions when appropriate. Therefore a strategy for α-conversion must be given as a type parameter.

Example

let mut expr = lam("x", app(var("y"), var("x")));

expr.apply::<Enumerate>(&var("z"));

assert_eq!(expr, app(var("y"), var("z")));

Performs a β-reduction on this Term.

The reduction strategy to be used must be given as a type parameter, like in the example below.

Example

let mut expr = app![
    lam("a", var("a")),
    lam("b", lam("c", var("b"))),
    var("x"),
    lam("e", var("f"))
];

expr.reduce::<NormalOrder<Enumerate>>();

assert_eq!(expr, var("x"));

Trait Implementations

impl Debug for Term
[src]

Formats the value using the given formatter. Read more

impl Clone for Term
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl PartialEq for Term
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Eq for Term
[src]

impl Hash for Term
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl Display for Term
[src]

Formats the value using the given formatter. Read more

impl<'a> From<&'a Term> for Term
[src]

Performs the conversion.

impl From<Var> for Term
[src]

Performs the conversion.

Auto Trait Implementations

impl Send for Term

impl Sync for Term