[−][src]Enum lambda_calculus::term::Term
A lambda term that is either a variable with a De Bruijn index, an abstraction over a term or an applicaction of one term to another.
Variants
Var(usize)
a variable
Abs(Box<Term>)
an abstraction
App(Box<(Term, Term)>)
an application
Methods
impl Term
[src]
pub fn unvar(self) -> Result<usize, TermError>
[src]
Returns a variable's De Bruijn index, consuming it in the process.
Example
use lambda_calculus::*; assert_eq!(Var(1).unvar(), Ok(1));
Errors
Returns a TermError
if self
is not a Var
iable.
pub fn unvar_ref(&self) -> Result<&usize, TermError>
[src]
Returns a reference to a variable's De Bruijn index.
Example
use lambda_calculus::*; assert_eq!(Var(1).unvar_ref(), Ok(&1));
Errors
Returns a TermError
if self
is not a Var
iable.
pub fn unvar_mut(&mut self) -> Result<&mut usize, TermError>
[src]
Returns a mutable reference to a variable's De Bruijn index.
Example
use lambda_calculus::*; assert_eq!(Var(1).unvar_mut(), Ok(&mut 1));
Errors
Returns a TermError
if self
is not a Var
iable.
pub fn unabs(self) -> Result<Term, TermError>
[src]
Returns an abstraction's underlying term, consuming it in the process.
Example
use lambda_calculus::*; assert_eq!(abs(Var(1)).unabs(), Ok(Var(1)));
Errors
Returns a TermError
if self
is not an Abs
traction.
pub fn unabs_ref(&self) -> Result<&Term, TermError>
[src]
Returns a reference to an abstraction's underlying term.
Example
use lambda_calculus::*; assert_eq!(abs(Var(1)).unabs_ref(), Ok(&Var(1)));
Errors
Returns a TermError
if self
is not an Abs
traction.
pub fn unabs_mut(&mut self) -> Result<&mut Term, TermError>
[src]
Returns a mutable reference to an abstraction's underlying term.
Example
use lambda_calculus::*; assert_eq!(abs(Var(1)).unabs_mut(), Ok(&mut Var(1)));
Errors
Returns a TermError
if self
is not an Abs
traction.
pub fn unapp(self) -> Result<(Term, Term), TermError>
[src]
Returns a pair containing an application's underlying terms, consuming it in the process.
Example
use lambda_calculus::*; assert_eq!(app(Var(1), Var(2)).unapp(), Ok((Var(1), Var(2))));
Errors
Returns a TermError
if self
is not an App
lication.
pub fn unapp_ref(&self) -> Result<(&Term, &Term), TermError>
[src]
Returns a pair containing references to an application's underlying terms.
Example
use lambda_calculus::*; assert_eq!(app(Var(1), Var(2)).unapp_ref(), Ok((&Var(1), &Var(2))));
Errors
Returns a TermError
if self
is not an App
lication.
pub fn unapp_mut(&mut self) -> Result<(&mut Term, &mut Term), TermError>
[src]
Returns a pair containing mutable references to an application's underlying terms.
Example
use lambda_calculus::*; assert_eq!(app(Var(1), Var(2)).unapp_mut(), Ok((&mut Var(1), &mut Var(2))));
Errors
Returns a TermError
if self
is not an App
lication.
pub fn lhs(self) -> Result<Term, TermError>
[src]
Returns the left-hand side term of an application. Consumes self
.
Example
use lambda_calculus::*; assert_eq!(app(Var(1), Var(2)).lhs(), Ok(Var(1)));
Errors
Returns a TermError
if self
is not an App
lication.
pub fn lhs_ref(&self) -> Result<&Term, TermError>
[src]
Returns a reference to the left-hand side term of an application.
Example
use lambda_calculus::*; assert_eq!(app(Var(1), Var(2)).lhs_ref(), Ok(&Var(1)));
Errors
Returns a TermError
if self
is not an App
lication.
pub fn lhs_mut(&mut self) -> Result<&mut Term, TermError>
[src]
Returns a mutable reference to the left-hand side term of an application.
Example
use lambda_calculus::*; assert_eq!(app(Var(1), Var(2)).lhs_mut(), Ok(&mut Var(1)));
pub fn rhs(self) -> Result<Term, TermError>
[src]
Returns the right-hand side term of an application. Consumes self
.
Example
use lambda_calculus::*; assert_eq!(app(Var(1), Var(2)).rhs(), Ok(Var(2)));
Errors
Returns a TermError
if self
is not an App
lication.
pub fn rhs_ref(&self) -> Result<&Term, TermError>
[src]
Returns a reference to the right-hand side term of an application.
Example
use lambda_calculus::*; assert_eq!(app(Var(1), Var(2)).rhs_ref(), Ok(&Var(2)));
Errors
Returns a TermError
if self
is not an App
lication.
pub fn rhs_mut(&mut self) -> Result<&mut Term, TermError>
[src]
Returns a mutable reference to the right-hand side term of an application.
Example
use lambda_calculus::*; assert_eq!(app(Var(1), Var(2)).rhs_mut(), Ok(&mut Var(2)));
Errors
Returns a TermError
if self
is not an App
lication.
pub fn is_supercombinator(&self) -> bool
[src]
Returns true
if self
is a
supercombinator.
Example
use lambda_calculus::*; let term1 = abs(app(Var(1), abs(Var(1)))); // λ 1 (λ 1) let term2 = app(abs(Var(2)), abs(Var(1))); // (λ 2) (λ 1) assert_eq!(term1.is_supercombinator(), true); assert_eq!(term2.is_supercombinator(), false);
impl Term
[src]
pub fn apply(&mut self, rhs: &Term) -> Result<(), TermError>
[src]
Applies a Term
to self
via substitution and variable update.
Example
use lambda_calculus::*; let mut term1 = parse(&"λλ42(λ13)", DeBruijn).unwrap(); let term2 = parse(&"λ51", DeBruijn).unwrap(); let result = parse(&"λ3(λ61)(λ1(λ71))", DeBruijn).unwrap(); term1.apply(&term2); assert_eq!(term1, result);
Errors
Returns a TermError
if self
is not an Abs
traction.
pub fn reduce(&mut self, order: Order, limit: usize) -> usize
[src]
Performs β-reduction on a Term
with the specified evaluation Order
and an optional limit
on the number of reductions (0
means no limit) and returns the number of performed
reductions.
Example
use lambda_calculus::*; let mut expression = parse(&"(λa.λb.λc.b (a b c)) (λa.λb.b)", Classic).unwrap(); let reduced = parse(&"λa.λb.a b", Classic).unwrap(); expression.reduce(NOR, 0); assert_eq!(expression, reduced);
Trait Implementations
impl Clone for Term
[src]
fn clone(&self) -> Term
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Eq for Term
[src]
impl Into<Term> for bool
[src]
impl Into<Term> for (Term, Term)
[src]
impl Into<Term> for Vec<Term>
[src]
impl Into<Term> for Option<Term>
[src]
impl Into<Term> for Result<Term, Term>
[src]
impl PartialEq<Term> for Term
[src]
impl Display for Term
[src]
impl Debug for Term
[src]
impl Hash for Term
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,