Term

Enum Term 

Source
pub enum Term {
Show 23 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>, }, With { 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 { bnd: Option<Name>, arg: Box<Term>, with_bnd: Vec<Option<Name>>, with_arg: Vec<Term>, arms: Vec<MatchRule>, }, Swt { bnd: Option<Name>, arg: Box<Term>, with_bnd: Vec<Option<Name>>, with_arg: Vec<Term>, pred: Option<Name>, arms: Vec<Term>, }, Fold { bnd: Option<Name>, arg: Box<Term>, with_bnd: Vec<Option<Name>>, with_arg: Vec<Term>, arms: Vec<MatchRule>, }, Bend { bnd: Vec<Option<Name>>, arg: Vec<Term>, cond: Box<Term>, step: Box<Term>, base: Box<Term>, }, Open { typ: Name, var: Name, bod: Box<Term>, }, Ref { nam: Name, }, Def { def: Definition, nxt: Box<Term>, }, 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>
§

With

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_bnd: Vec<Option<Name>>
§with_arg: Vec<Term>
§

Swt

Native pattern matching on numbers

Fields

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

Fold

Fields

§arg: Box<Term>
§with_bnd: Vec<Option<Name>>
§with_arg: Vec<Term>
§

Bend

Fields

§arg: Vec<Term>
§cond: Box<Term>
§step: Box<Term>
§base: Box<Term>
§

Open

Fields

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

Ref

Fields

§nam: Name
§

Def

Fields

§nxt: Box<Term>
§

Era

§

Err

Implementations§

Source§

impl Term

Source

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

Source

pub fn encode_nat(val: u32) -> Term

Source§

impl Term

Source

pub fn check_unbound_refs(&self, book: &Book, unbounds: &mut HashSet<Name>)

Source§

impl Term

Source

pub fn check_unbound_vars<'a>( &'a mut self, scope: &mut Vec<Option<&'a Name>>, 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>)

Transform the variables that we previously found were unscoped into their unscoped variants.

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_use(&mut self)

Source

pub fn desugar_ctr_use(&mut self)

Source§

impl Term

Source

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

Source§

impl Term

Source

pub fn encode_matches(&mut self, adt_encoding: AdtEncoding)

Source§

impl Term

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

Source

pub fn expand_generated(&mut self, book: &Book, recursive_defs: &BTreeSet<Name>)

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 lift_local_defs( &mut self, parent: &Name, check: bool, defs: &mut IndexMap<Name, Definition>, gen: &mut usize, )

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 children_mut_with_binds_mut( &mut self, ) -> impl DoubleEndedIterator<Item = (&mut Term, impl DoubleEndedIterator<Item = &mut Option<Name>>)>

Because multiple children can share the same binds, this function is very restricted. Should only be called after desugaring bends/folds/matches/switches.

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>, info: &mut Diagnostics, ) -> Result<(), String>

Source§

impl Term

Source

pub fn resugar_lists(&mut self, adt_encoding: AdtEncoding)

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

Source§

impl Term

Source

pub fn resugar_strings(&mut self, adt_encoding: AdtEncoding)

Converts lambda-encoded strings ending with String/nil to 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

Lambda with a static tag

Source

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

Lambda with any tag

Source

pub fn rfold_lams( term: Term, pats: impl DoubleEndedIterator<Item = Option<Name>>, ) -> Self

Wraps a term in lambdas, so that the outermost lambda is the first given element.

The lambda equivalent of Term::call.

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 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_ctrs(&mut self, from: &Name, to: &Name)

Substitute the occurrences of a constructor name with the given name.

Source

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

Substitutes the occurrences of a type constructor in the term with the given name.

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) -> IndexMap<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 duplicate 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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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§

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>,

Source§

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>,

Source§

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.