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
Var
Link
Let
With
Ask
Use
App
Fan
Either a tuple or a superposition
Num
Nat
Str
Fields
val: GlobalString
List
Oper
A numeric operation between built-in numbers.
Mat
Pattern matching on an ADT.
Fields
Swt
Native pattern matching on numbers
Fields
Fold
Fields
Bend
Open
Ref
Def
Era
Err
Implementations§
Source§impl Term
impl Term
Sourcepub fn check_unbound_vars<'a>(
&'a mut self,
scope: &mut Vec<Option<&'a Name>>,
errs: &mut Vec<UnboundVarErr>,
)
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
impl Term
pub fn collect_unscoped( &self, unscoped: &mut HashSet<Name>, scope: &mut Vec<Name>, )
Sourcepub fn apply_unscoped(&mut self, unscoped: &HashSet<Name>)
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
impl Term
pub fn desugar_use(&mut self)
pub fn desugar_ctr_use(&mut self)
Source§impl Term
impl Term
pub fn encode_matches(&mut self, adt_encoding: AdtEncoding)
Source§impl Term
Dereferences any non recursive generated definitions in the term.
Used after readback.
impl Term
Dereferences any non recursive generated definitions in the term. Used after readback.
pub fn expand_generated(&mut self, book: &Book, recursive_defs: &BTreeSet<Name>)
Source§impl Term
impl Term
pub fn has_unscoped_diff(&self) -> bool
pub fn float_children_mut(&mut self) -> impl Iterator<Item = &mut Term>
Source§impl Term
impl Term
pub fn lift_local_defs( &mut self, parent: &Name, check: bool, defs: &mut IndexMap<Name, Definition>, gen: &mut usize, )
Source§impl Term
impl Term
Sourcepub fn linearize_match_binds(&mut self)
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
impl Term
pub fn linearize_vars(&mut self)
Source§impl Term
impl Term
Sourcepub fn children_mut_with_binds_mut(
&mut self,
) -> impl DoubleEndedIterator<Item = (&mut Term, impl DoubleEndedIterator<Item = &mut Option<Name>>)>
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
impl Term
Sourcepub fn resugar_lists(&mut self, adt_encoding: AdtEncoding)
pub fn resugar_lists(&mut self, adt_encoding: AdtEncoding)
Converts lambda-encoded lists ending with List/Nil to list literals.
Source§impl Term
impl Term
Sourcepub fn resugar_strings(&mut self, adt_encoding: AdtEncoding)
pub fn resugar_strings(&mut self, adt_encoding: AdtEncoding)
Converts lambda-encoded strings ending with String/nil to string literals.
Source§impl Term
impl Term
pub fn make_var_names_unique(&mut self)
Source§impl Term
impl Term
Sourcepub fn tagged_lam(tag: Tag, pat: Pattern, bod: Term) -> Self
pub fn tagged_lam(tag: Tag, pat: Pattern, bod: Term) -> Self
Lambda with any tag
Sourcepub fn rfold_lams(
term: Term,
pats: impl DoubleEndedIterator<Item = Option<Name>>,
) -> Self
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
.
pub fn var_or_era(nam: Option<Name>) -> Self
pub fn app(fun: Term, arg: Term) -> Self
pub fn tagged_app(tag: Tag, fun: Term, arg: Term) -> Self
Sourcepub fn call(called: Term, args: impl IntoIterator<Item = Term>) -> Self
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.
pub fn tagged_call( tag: Tag, called: Term, args: impl IntoIterator<Item = Term>, ) -> Self
pub fn ref(name: &str) -> Self
pub fn str(str: &str) -> Self
pub fn sub_num(arg: Term, val: Num) -> Term
pub fn add_num(arg: Term, val: Num) -> Term
pub fn pattern(&self) -> Option<&Pattern>
pub fn pattern_mut(&mut self) -> Option<&mut Pattern>
pub fn children(&self) -> impl DoubleEndedIterator<Item = &Term> + Clone
pub fn children_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut Term>
Sourcepub fn children_with_binds(
&self,
) -> impl DoubleEndedIterator<Item = (&Term, impl DoubleEndedIterator<Item = &Option<Name>> + Clone)> + Clone
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.
Sourcepub fn children_mut_with_binds(
&mut self,
) -> impl DoubleEndedIterator<Item = (&mut Term, impl DoubleEndedIterator<Item = &Option<Name>> + Clone)>
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.
Sourcepub fn subst(&mut self, from: &Name, to: &Term)
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.
Sourcepub fn subst_ctrs(&mut self, from: &Name, to: &Name)
pub fn subst_ctrs(&mut self, from: &Name, to: &Name)
Substitute the occurrences of a constructor name with the given name.
Sourcepub fn subst_type_ctrs(&mut self, from: &Name, to: &Name)
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.
Sourcepub fn subst_unscoped(&mut self, from: &Name, to: &Term)
pub fn subst_unscoped(&mut self, from: &Name, to: &Term)
Substitute the occurrence of an unscoped variable with the given term.
Sourcepub fn free_vars(&self) -> IndexMap<Name, u64>
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
Sourcepub fn unscoped_vars(&self) -> (IndexSet<Name>, IndexSet<Name>)
pub fn unscoped_vars(&self) -> (IndexSet<Name>, IndexSet<Name>)
Returns the set of declared and the set of used unscoped variables
pub fn has_unscoped(&self) -> bool
Trait Implementations§
impl Eq for Term
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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