Skip to main content

Term

Enum Term 

Source
pub enum Term {
    Sort(Universe),
    Var(String),
    Global(String),
    Pi {
        param: String,
        param_type: Box<Term>,
        body_type: Box<Term>,
    },
    Lambda {
        param: String,
        param_type: Box<Term>,
        body: Box<Term>,
    },
    App(Box<Term>, Box<Term>),
    Match {
        discriminant: Box<Term>,
        motive: Box<Term>,
        cases: Vec<Term>,
    },
    Fix {
        name: String,
        body: Box<Term>,
    },
    Lit(Literal),
    Hole,
}
Expand description

Unified term representation.

Every expression in CoC is a Term:

  • Sort(u) - universes (Type 0, Type 1, Prop)
  • Var(x) - variables
  • Pi - dependent function types: Π(x:A). B
  • Lambda - functions: λ(x:A). t
  • App - application: f x

Variants§

§

Sort(Universe)

Universe: Type n or Prop

§

Var(String)

Local variable reference (bound by λ or Π)

§

Global(String)

Global definition (inductive type or constructor)

§

Pi

Dependent function type: Π(x:A). B

When B doesn’t mention x, this is just A → B. When B mentions x, this is a dependent type.

Fields

§param: String
§param_type: Box<Term>
§body_type: Box<Term>
§

Lambda

Lambda abstraction: λ(x:A). t

Fields

§param: String
§param_type: Box<Term>
§body: Box<Term>
§

App(Box<Term>, Box<Term>)

Application: f x

§

Match

Pattern matching on inductive types.

match discriminant return motive with cases

  • discriminant: the term being matched (must have inductive type)
  • motive: λx:I. T — describes the return type
  • cases: one case per constructor, in definition order

Fields

§discriminant: Box<Term>
§motive: Box<Term>
§cases: Vec<Term>
§

Fix

Fixpoint (recursive function).

fix name. body binds name to itself within body. Used for recursive definitions like addition.

Fields

§name: String

Name for self-reference within the body

§body: Box<Term>

The body of the fixpoint (typically a lambda)

§

Lit(Literal)

Primitive literal value.

Hardware-native values like i64, f64, String. These compute via CPU ALU, not recursion.

§

Hole

Hole (implicit argument).

Represents an argument that should be inferred by the type checker. Used in Literate syntax like X equals Y where the type of X/Y is implicit.

Trait Implementations§

Source§

impl Clone for Term

Source§

fn clone(&self) -> Term

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 Display for Term

Source§

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

Formats the value using the given formatter. 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<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.