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
Var
Link
Let
Do
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.
Swt
Native pattern matching on numbers
Fold
Bend
Open
Ref
Era
Err
Implementations§
source§impl Term
impl Term
sourcepub fn check_unbound_vars<'a>(
&'a mut self,
scope: &mut HashMap<&'a Name, u64>,
errs: &mut Vec<UnboundVarErr>
)
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
impl Term
pub fn collect_unscoped( &self, unscoped: &mut HashSet<Name>, scope: &mut Vec<Name> )
pub fn apply_unscoped(&mut self, unscoped: &HashSet<Name>)
source§impl Term
impl Term
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
impl Term
pub fn encode_matches(&mut self)
source§impl Term
impl Term
Dereferences any generated definitions in the term. Used after readback.
pub fn expand_generated(&mut self, book: &Book)
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
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 resugar_lists(&mut self)
pub fn resugar_lists(&mut self)
Converts lambda-encoded lists ending with List/Nil to list literals.
source§impl Term
impl Term
sourcepub fn resugar_strings(&mut self)
pub fn resugar_strings(&mut self)
Converts lambda-encoded strings ending with String/nil to a string literals.
source§impl Term
impl Term
pub fn make_var_names_unique(&mut self)
source§impl Term
impl Term
pub fn lam(pat: Pattern, bod: Term) -> Self
pub fn tagged_lam(tag: Tag, pat: Pattern, bod: Term) -> Self
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 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>>)>
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_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) -> HashMap<Name, u64>
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
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§
source§impl PartialEq for Term
impl PartialEq for Term
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<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