pub enum Expr {
Sort(Level),
BVar(u32),
FVar(FVarId),
Const(Name, Vec<Level>),
App(Box<Expr>, Box<Expr>),
Lam(BinderInfo, Name, Box<Expr>, Box<Expr>),
Pi(BinderInfo, Name, Box<Expr>, Box<Expr>),
Let(Name, Box<Expr>, Box<Expr>, Box<Expr>),
Lit(Literal),
Proj(Name, u32, Box<Expr>),
}Expand description
Core expression type.
This is the heart of the kernel. All terms in the type theory are
represented as Expr values.
We use Box for sub-expressions for simplicity in Phase 0.
In later phases, these will be Idx<Expr> pointing into an arena.
Variants§
Sort(Level)
Sort u — universe.
Prop is Sort(Level::Zero).
Type is Sort(Level::Succ(Level::Zero)).
BVar(u32)
Bound variable (de Bruijn index, 0-based).
BVar(0) refers to the innermost binder.
BVar(n) refers to the n-th enclosing binder.
FVar(FVarId)
Free variable (locally nameless).
Used during type checking to represent local hypotheses.
Const(Name, Vec<Level>)
Named constant with universe level instantiation.
Const(name, levels) represents a global constant with its
universe parameters instantiated.
App(Box<Expr>, Box<Expr>)
Function application: f a.
Application is always binary. f a b is App(App(f, a), b).
Lam(BinderInfo, Name, Box<Expr>, Box<Expr>)
Lambda abstraction: λ (x : type), body.
Pi(BinderInfo, Name, Box<Expr>, Box<Expr>)
Dependent function type: Π (x : type), body.
Non-dependent arrows A → B are represented as
Pi(Default, _, A, B) where the body doesn’t use BVar(0).
Let(Name, Box<Expr>, Box<Expr>, Box<Expr>)
Let binding: let x : type := val in body.
Lit(Literal)
Literal value (Nat or String).
Proj(Name, u32, Box<Expr>)
Structure projection: projName.idx struct.
Implementations§
Source§impl Expr
impl Expr
Sourcepub fn is_atom(&self) -> bool
pub fn is_atom(&self) -> bool
Check if this expression is an “atom” (cannot be further reduced without context): Sort, BVar, FVar, Const, Lit.
Sourcepub fn as_const_name(&self) -> Option<&Name>
pub fn as_const_name(&self) -> Option<&Name>
Extract the constant name, or None.
Sourcepub fn as_sort_level(&self) -> Option<&Level>
pub fn as_sort_level(&self) -> Option<&Level>
Extract the sort level, or None.
Sourcepub fn app_head_args(&self) -> (&Expr, Vec<&Expr>)
pub fn app_head_args(&self) -> (&Expr, Vec<&Expr>)
Return the head and argument list of an application spine.
For f a b c, returns (&f, [&a, &b, &c]).
Sourcepub fn mk_app_many(self, args: &[Expr]) -> Expr
pub fn mk_app_many(self, args: &[Expr]) -> Expr
Apply this expression to a list of arguments.
e.mk_app_many(&[a, b, c]) returns ((e a) b) c.
Sourcepub fn has_loose_bvar_at(&self, d: u32) -> bool
pub fn has_loose_bvar_at(&self, d: u32) -> bool
Check if this expression has any loose bound variables at depth d.
Sourcepub fn count_bvar_occurrences(&self, idx: u32) -> usize
pub fn count_bvar_occurrences(&self, idx: u32) -> usize
Count occurrences of bound variable BVar(idx) in this expression.