Skip to main content

Expr

Enum Expr 

Source
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

Source

pub fn is_sort(&self) -> bool

Check if this is a Sort.

Source

pub fn is_prop(&self) -> bool

Check if this is Prop.

Source

pub fn is_bvar(&self) -> bool

Check if this is a bound variable.

Source

pub fn is_fvar(&self) -> bool

Check if this is a free variable.

Source

pub fn is_app(&self) -> bool

Check if this is an application.

Source

pub fn is_lambda(&self) -> bool

Check if this is a lambda.

Source

pub fn is_pi(&self) -> bool

Check if this is a Pi type.

Source§

impl Expr

Source

pub fn is_let(&self) -> bool

Check if this expression is a let binding.

Source

pub fn is_lit(&self) -> bool

Check if this expression is a literal.

Source

pub fn is_const(&self) -> bool

Check if this expression is a named constant.

Source

pub fn is_proj(&self) -> bool

Check if this expression is a projection.

Source

pub fn is_atom(&self) -> bool

Check if this expression is an “atom” (cannot be further reduced without context): Sort, BVar, FVar, Const, Lit.

Source

pub fn as_bvar(&self) -> Option<u32>

Extract the bound variable index, or None.

Source

pub fn as_fvar(&self) -> Option<FVarId>

Extract the free variable ID, or None.

Source

pub fn as_const_name(&self) -> Option<&Name>

Extract the constant name, or None.

Source

pub fn as_sort_level(&self) -> Option<&Level>

Extract the sort level, or None.

Source

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]).

Source

pub fn app_arity(&self) -> usize

Return the number of arguments in an application spine.

Source

pub fn pi_arity(&self) -> usize

Count the number of leading Pi binders.

Source

pub fn lam_arity(&self) -> usize

Count the number of leading Lambda binders.

Source

pub fn size(&self) -> usize

Compute the AST size (total number of nodes).

Source

pub fn ast_depth(&self) -> usize

Compute the AST depth (longest path to a leaf).

Source

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.

Source

pub fn has_loose_bvar_at(&self, d: u32) -> bool

Check if this expression has any loose bound variables at depth d.

Source

pub fn count_bvar_occurrences(&self, idx: u32) -> usize

Count occurrences of bound variable BVar(idx) in this expression.

Source

pub fn is_closed(&self) -> bool

Check if this expression is closed (no loose bound variables).

Source

pub fn free_vars(&self) -> HashSet<FVarId>

Collect all free variable IDs occurring in this expression.

Source

pub fn constants(&self) -> HashSet<Name>

Collect all constant names occurring in this expression.

Trait Implementations§

Source§

impl Clone for Expr

Source§

fn clone(&self) -> Expr

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 Expr

Source§

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

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

impl Display for Expr

Source§

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

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

impl Hash for Expr

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 Expr

Source§

fn eq(&self, other: &Expr) -> 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 Expr

Source§

impl StructuralPartialEq for Expr

Auto Trait Implementations§

§

impl Freeze for Expr

§

impl RefUnwindSafe for Expr

§

impl Send for Expr

§

impl Sync for Expr

§

impl Unpin for Expr

§

impl UnsafeUnpin for Expr

§

impl UnwindSafe for Expr

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