Skip to main content

Context

Struct Context 

Source
pub struct Context { /* private fields */ }
Expand description

Typing context: maps variable names to their types.

The context is immutable-by-default: extend creates a new context with the additional binding, preserving the original.

Also stores global definitions:

  • Inductive types (e.g., Nat : Type 0)
  • Constructors (e.g., Zero : Nat, Succ : Nat -> Nat)
  • Declarations (e.g., hypotheses like h1 : P -> Q)

Implementations§

Source§

impl Context

Source

pub fn new() -> Self

Create an empty context.

Source

pub fn add(&mut self, name: &str, ty: Term)

Add a local binding to this context (mutates in place).

Source

pub fn get(&self, name: &str) -> Option<&Term>

Look up a local variable’s type in the context.

Source

pub fn extend(&self, name: &str, ty: Term) -> Context

Create a new context extended with an additional local binding.

Does not mutate the original context.

Source

pub fn add_inductive(&mut self, name: &str, sort: Term)

Register an inductive type.

The sort is the type of the inductive (e.g., Type 0 for Nat).

Source

pub fn add_constructor(&mut self, name: &str, inductive: &str, ty: Term)

Register a constructor for an inductive type.

The ty is the full type of the constructor (e.g., Nat for Zero, Nat -> Nat for Succ).

Constructors are tracked in registration order for match expressions.

Source

pub fn add_declaration(&mut self, name: &str, ty: Term)

Add a declaration (typed assumption/hypothesis).

Used for proof certification where hypotheses are assumed. Example: h1 : P -> Q

Source

pub fn add_definition(&mut self, name: String, ty: Term, body: Term)

Register a definition: name : type := body

Definitions are transparent and unfold during normalization (delta reduction). This distinguishes them from declarations (axioms) which have no body.

Source

pub fn get_global(&self, name: &str) -> Option<&Term>

Look up a global definition (inductive, constructor, definition, or declaration).

Returns the type of the global.

Source

pub fn is_definition(&self, name: &str) -> bool

Check if a name is a definition (has a body that can be unfolded).

Source

pub fn get_definition_body(&self, name: &str) -> Option<&Term>

Get the body of a definition, if it exists.

Returns None for axioms, constructors, and inductives (only definitions have bodies).

Source

pub fn get_definition_type(&self, name: &str) -> Option<&Term>

Get the type of a definition, if it exists.

Source

pub fn is_constructor(&self, name: &str) -> bool

Check if a name is a constructor.

Source

pub fn constructor_inductive(&self, name: &str) -> Option<&str>

Get the inductive type a constructor belongs to.

Source

pub fn is_inductive(&self, name: &str) -> bool

Check if a name is an inductive type.

Source

pub fn get_constructors(&self, inductive: &str) -> Vec<(&str, &Term)>

Get all constructors for an inductive type, in registration order.

Returns a vector of (constructor_name, constructor_type) pairs.

Source

pub fn iter_declarations(&self) -> impl Iterator<Item = (&str, &Term)>

Iterate over all declarations (hypotheses).

Used by the certifier to find hypothesis by type.

Source

pub fn iter_definitions(&self) -> impl Iterator<Item = (&str, &Term, &Term)>

Iterate over all definitions.

Used by the UI to display definitions.

Source

pub fn iter_inductives(&self) -> impl Iterator<Item = (&str, &Term)>

Iterate over all inductive types.

Used by the UI to display inductive types.

Source

pub fn add_constructor_checked( &mut self, name: &str, inductive: &str, ty: Term, ) -> KernelResult<()>

Add a constructor with strict positivity checking.

Returns an error if the inductive type appears negatively in the constructor type. This prevents paradoxes like:

Inductive Bad := Cons : (Bad -> False) -> Bad
Source

pub fn add_hint(&mut self, name: &str)

Register a theorem as a hint for the auto tactic.

Hints are theorems that auto will try to apply when decision procedures fail. This allows auto to “learn” from proven theorems.

Source

pub fn get_hints(&self) -> &[String]

Get all registered hints.

Returns the names of theorems registered as hints.

Source

pub fn is_hint(&self, name: &str) -> bool

Check if a theorem is registered as a hint.

Trait Implementations§

Source§

impl Clone for Context

Source§

fn clone(&self) -> Context

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 Context

Source§

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

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

impl Default for Context

Source§

fn default() -> Context

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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