Enum bend::fun::Term

source ·
pub enum Term {
Show 22 variants Lam { tag: Tag, pat: Box<Pattern>, bod: Box<Term>, }, Var { nam: Name, }, Link { nam: Name, }, Let { pat: Box<Pattern>, val: Box<Term>, nxt: Box<Term>, }, Do { typ: Name, bod: Box<Term>, }, Ask { pat: Box<Pattern>, val: Box<Term>, nxt: Box<Term>, }, Use { nam: Option<Name>, val: Box<Term>, nxt: Box<Term>, }, App { tag: Tag, fun: Box<Term>, arg: Box<Term>, }, Fan { fan: FanKind, tag: Tag, els: Vec<Term>, }, Num { val: Num, }, Nat { val: u32, }, Str { val: GlobalString, }, List { els: Vec<Term>, }, Oper { opr: Op, fst: Box<Term>, snd: Box<Term>, }, Mat { arg: Box<Term>, bnd: Option<Name>, with: Vec<Name>, arms: Vec<MatchRule>, }, Swt { arg: Box<Term>, bnd: Option<Name>, with: Vec<Name>, pred: Option<Name>, arms: Vec<Term>, }, Fold { bnd: Option<Name>, arg: Box<Term>, with: Vec<Name>, arms: Vec<MatchRule>, }, Bend { bind: Vec<Option<Name>>, init: Vec<Term>, cond: Box<Term>, step: Box<Term>, base: Box<Term>, }, Open { typ: Name, var: Name, bod: Box<Term>, }, Ref { nam: Name, }, Era, Err,
}

Variants§

§

Lam

Fields

§tag: Tag
§bod: Box<Term>
§

Var

Fields

§nam: Name

Fields

§nam: Name
§

Let

Fields

§val: Box<Term>
§nxt: Box<Term>
§

Do

Fields

§typ: Name
§bod: Box<Term>
§

Ask

Fields

§val: Box<Term>
§nxt: Box<Term>
§

Use

Fields

§val: Box<Term>
§nxt: Box<Term>
§

App

Fields

§tag: Tag
§fun: Box<Term>
§arg: Box<Term>
§

Fan

Either a tuple or a superposition

Fields

§tag: Tag
§els: Vec<Term>
§

Num

Fields

§val: Num
§

Nat

Fields

§val: u32
§

Str

Fields

§

List

Fields

§els: Vec<Term>
§

Oper

A numeric operation between built-in numbers.

Fields

§opr: Op
§fst: Box<Term>
§snd: Box<Term>
§

Mat

Pattern matching on an ADT.

Fields

§arg: Box<Term>
§with: Vec<Name>
§

Swt

Native pattern matching on numbers

Fields

§arg: Box<Term>
§with: Vec<Name>
§pred: Option<Name>
§arms: Vec<Term>
§

Fold

Fields

§arg: Box<Term>
§with: Vec<Name>
§

Bend

Fields

§bind: Vec<Option<Name>>
§init: Vec<Term>
§cond: Box<Term>
§step: Box<Term>
§base: Box<Term>
§

Open

Fields

§typ: Name
§var: Name
§bod: Box<Term>
§

Ref

Fields

§nam: Name
§

Era

§

Err

Implementations§

source§

impl Term

source

pub fn encode_str(val: &str) -> Term

source

pub fn encode_nat(val: u32) -> Term

source

pub fn encode_ok(val: Term) -> Term

source

pub fn encode_err(val: Term) -> Term

source§

impl Term

source

pub fn check_unbound_vars<'a>( &'a mut self, scope: &mut HashMap<&'a Name, u64>, errs: &mut Vec<UnboundVarErr> )

Checks that all variables are bound. Precondition: References have been resolved, implicit binds have been solved.

source§

impl Term

source

pub fn display_pretty(&self, tab: usize) -> impl Display + '_

source§

impl Term

source

pub fn collect_unscoped( &self, unscoped: &mut HashSet<Name>, scope: &mut Vec<Name> )

source

pub fn apply_unscoped(&mut self, unscoped: &HashSet<Name>)

source§

impl Term

source

pub fn apply_use(&mut self)

source§

impl Term

source

pub fn subst_ref_to_ref(term: &mut Term, ref_map: &BTreeMap<Name, Name>) -> bool

Performs reference substitution within a term replacing any references found in ref_map with their corresponding targets.

source§

impl Term

source

pub fn desugar_do_blocks( &mut self, cur_block: Option<&Name>, def_names: &HashSet<Name> ) -> Result<(), String>

source§

impl Term

source

pub fn desugar_fold( &mut self, def_name: &Name, fresh: &mut usize, new_defs: &mut Vec<Definition>, ctrs: &Constructors, adts: &Adts ) -> Result<(), String>

source§

impl Term

source

pub fn encode_matches(&mut self)

source§

impl Term

Dereferences any generated definitions in the term. Used after readback.

source

pub fn expand_generated(&mut self, book: &Book)

source§

impl Term

source

pub fn has_unscoped_diff(&self) -> bool

source

pub fn float_children_mut(&mut self) -> impl Iterator<Item = &mut Term>

source§

impl Term

source

pub fn linearize_match_binds(&mut self)

Linearize any binds preceding a match/switch term, up to the first bind used in either the scrutinee or the bind.

source§

impl Term

source

pub fn linearize_vars(&mut self)

source§

impl Term

source

pub fn resolve_refs<'a>( &'a mut self, def_names: &HashSet<Name>, main: Option<&Name>, scope: &mut HashMap<&'a Name, usize> ) -> Result<(), String>

source§

impl Term

source

pub fn resugar_lists(&mut self)

Converts lambda-encoded lists ending with List/Nil to list literals.

source§

impl Term

source

pub fn resugar_strings(&mut self)

Converts lambda-encoded strings ending with String/nil to a string literals.

source§

impl Term

source

pub fn make_var_names_unique(&mut self)

source§

impl Term

source

pub fn lam(pat: Pattern, bod: Term) -> Self

source

pub fn tagged_lam(tag: Tag, pat: Pattern, bod: Term) -> Self

source

pub fn var_or_era(nam: Option<Name>) -> Self

source

pub fn app(fun: Term, arg: Term) -> Self

source

pub fn tagged_app(tag: Tag, fun: Term, arg: Term) -> Self

source

pub fn call(called: Term, args: impl IntoIterator<Item = Term>) -> Self

Make a call term by folding args around a called function term with applications.

source

pub fn tagged_call( tag: Tag, called: Term, args: impl IntoIterator<Item = Term> ) -> Self

source

pub fn arg_call(fun: Term, arg: Name) -> Self

Apply a variable to a term by the var name.

source

pub fn ref(name: &str) -> Self

source

pub fn str(str: &str) -> Self

source

pub fn sub_num(arg: Term, val: Num) -> Term

source

pub fn add_num(arg: Term, val: Num) -> Term

source

pub fn pattern(&self) -> Option<&Pattern>

source

pub fn pattern_mut(&mut self) -> Option<&mut Pattern>

source

pub fn children(&self) -> impl DoubleEndedIterator<Item = &Term> + Clone

source

pub fn children_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut Term>

source

pub fn children_with_binds( &self ) -> impl DoubleEndedIterator<Item = (&Term, impl DoubleEndedIterator<Item = &Option<Name>> + Clone)> + Clone

An iterator over the subterms with an iterator over the binds introduced by the current term for each subterm.

Must only be called after fix_matches.

Example: A lambda introduces 1 bind for it’s only subterm, while a let expression introduces 0 binds for the value and many binds for the next term.

source

pub fn children_mut_with_binds( &mut self ) -> impl DoubleEndedIterator<Item = (&mut Term, impl DoubleEndedIterator<Item = &Option<Name>> + Clone)>

Must only be called after fix_matches.

source

pub fn children_mut_with_binds_mut( &mut self ) -> impl DoubleEndedIterator<Item = (&mut Term, impl DoubleEndedIterator<Item = &mut Option<Name>>)>

Must only be called after fix_matches.

source

pub fn subst(&mut self, from: &Name, to: &Term)

Substitute the occurrences of a variable in a term with the given term.

Caution: can cause invalid shadowing of variables if used incorrectly. Ex: Using subst to beta-reduce (@a @b a b) converting it into @b b.

NOTE: Expects var bind information to be properly stored in match expressions, so it must run AFTER fix_match_terms.

NOTE: Since it doesn’t (can’t) handle with clauses in match terms, it must be run only AFTER with linearization.

source

pub fn subst_unscoped(&mut self, from: &Name, to: &Term)

Substitute the occurrence of an unscoped variable with the given term.

source

pub fn free_vars(&self) -> HashMap<Name, u64>

Collects all the free variables that a term has and the number of times each var is used

source

pub fn unscoped_vars(&self) -> (IndexSet<Name>, IndexSet<Name>)

Returns the set of declared and the set of used unscoped variables

source

pub fn has_unscoped(&self) -> bool

Trait Implementations§

source§

impl Clone for Term

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Term

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Term

source§

fn default() -> Term

Returns the “default value” for a type. Read more
source§

impl Display for Term

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Term

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Hash for Term

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for Term

source§

fn eq(&self, other: &Term) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Term

source§

impl StructuralPartialEq for Term

Auto Trait Implementations§

§

impl Freeze for Term

§

impl RefUnwindSafe for Term

§

impl Send for Term

§

impl Sync for Term

§

impl Unpin for Term

§

impl UnwindSafe for Term

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<'t, T> Place<'t, T> for T

source§

fn place(loaned: LoanedMut<'t, T>, place: &'t mut T)

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.