Skip to main content

TypePattern

Enum TypePattern 

Source
pub enum TypePattern {
    Scalar(ScalarType),
    Collection {
        ctor: CollectionCtor,
        args: Vec<TypePattern>,
    },
    Var {
        name: &'static str,
        bound: Option<Bound>,
    },
    Function {
        params: Vec<TypePattern>,
        result: Box<TypePattern>,
    },
    Unit,
    Tuple(Vec<TypePattern>),
    Option(Box<TypePattern>),
    Record {
        name: &'static str,
        fields: Vec<(&'static str, TypePattern)>,
    },
    Iterable {
        item: Box<TypePattern>,
    },
}
Expand description

A pattern describing a type shape in a catalog entry.

§There is no placeholder arm

Every row writes a concrete pattern. A placeholder for rows whose shape is not worked out yet would have to arrive together with the rejection that makes it safe: the only thing pattern_to_type could instantiate one as is a fresh inference variable, which unifies with anything, so “the type checker rejects it if it is still present at use time” is a promise nothing keeps by default.

Variants§

§

Scalar(ScalarType)

A specific scalar type, e.g. Int.

§

Collection

A built-in collection type constructor applied to element type(s), e.g. Vec[Int] or Map[Text, Int].

Fields

§args: Vec<TypePattern>

Element type parameters. Length must match the constructor’s arity.

§

Var

A type variable used inside a generic method’s signature, e.g. T in Vec[T].push(T). Two occurrences of the same variable name inside one entry refer to the same type; that equality is what the type checker enforces at a call site.

bound is what the variable must satisfy. It is a fact about the variable, not about the position it is written in, so an entry declares it once — at whichever occurrence reads best — and MethodEntry::bounds finds it wherever it is. Declaring two different bounds for one name in one entry is a catalog authoring mistake and MethodCatalog::build refuses it.

Fields

§name: &'static str
§bound: Option<Bound>
§

Function

The function type (params) -> result. Used for higher-order methods like Vec[T].map.

Fields

§

Unit

The unit type, used for methods like Vec[T].push that return nothing.

§

Tuple(Vec<TypePattern>)

A tuple (T, U, ...). Used by grid methods that return/accept (x, y) points (§6.4). Structural identity is the element-type sequence.

§

Option(Box<TypePattern>)

Option[T] — the prelude enum, applied to one argument (§4.7, F12).

Its own arm rather than a Collection ctor because Option is not a collection: it is the one generic enum def the language has, and a catalog row spelling it has to lower to TypeDb::option_of, which names the single canonical def every Option[T] in a program shares.

§4.7: “Option[T] represents normal domain-level absence. It is not an error channel.” Map.get and Grid.find are the rows that need it: a miss is an absent value, not a V or an (Int, Int) standing in for one.

§

Record

A nominal prelude record — one name, one declared field order, e.g. Around4 { up, left, right, down }.

§The field order written here is the runtime’s layout, and that is not a convention

A field read compiles to a slot index taken from the def’s field order, while the value is laid out in its schema’s order. ADR-152 makes those agree for an anonymous shape by permuting every registration into the order the shape was first written anywhere in the program — which a runtime-built record cannot participate in, because the runtime built its schema before the program was read. So a catalog record is nominal: TypeDb::register_record permutes only when the name is absent, and a nominal def keeps this list’s order verbatim.

The consequence is that this list and the runtime schema’s field list are one order in two places. praxis_runtime::records::around4_schema is the other, and praxis_runtime::records::tests::around_schemas_match_the_catalog is what keeps them from drifting — it is the one test that can see both lists at once. A disagreement is a silently wrong field read, not a crash.

A record is a method result, never a receiver: praxis_hir::catalog::type_to_pattern answers None for TypeData::Record, so no row can dispatch on one.

Fields

§name: &'static str

The declared type name, which is the record’s identity (§4.5) and the SchemaIdentity::Nominal the runtime builds values under.

§fields: Vec<(&'static str, TypePattern)>

The fields, in declaration order. See the type-level note.

§

Iterable

A receiver the pipeline walks: any of the ten iterables named by is_pipeline_receiver, binding what it yields to item (ADR-127).

§It is the one pattern that is not unified with the receiver

Everywhere else a catalog receiver is instantiated and unified with the actual receiver — that is what pins T in Vec[T].push(T). This one cannot be: it accepts ten different constructors, and unifying against any one of them pins the other nine out. What is unified is the item, against capability::iter_item’s answer for the receiver — the for loop’s own answer to “what does this yield”.

One consequence is load-bearing and Decision 4 uses it: a row constrains which iterables it accepts by writing a shape into item. Iterable { item: Tuple[K, V] } is “a Map or a Counter”, because those are the two whose item is a pair — and [1, 2].to_map() is an ordinary unification failure at the method name, not a row that resolves and then faults.

Fields

Implementations§

Source§

impl TypePattern

Source

pub const fn var(name: &'static str) -> TypePattern

An unconstrained type variable — T in Vec[T].push(T).

The overwhelmingly common case, and the reason TypePattern::Var is a struct variant rather than a second enum arm: a bound is an optional fact about a variable, so there is one kind of variable and not two.

Source

pub const fn bounded(name: &'static str, bound: Bound) -> TypePattern

A type variable that must satisfy bound.

Source

pub const fn is_scalar(name: &'static str, scalar: ScalarType) -> TypePattern

A type variable required to be exactly scalar — the Int-only sinks.

Source

pub fn iterable(item: TypePattern) -> TypePattern

The pipeline receiver yielding itemIterable { item }, spelled without the Box every row would otherwise write (ADR-127).

Source

pub const fn of_kind(name: &'static str, kind: CapKind) -> TypePattern

A type variable required to have kind — the barrier combinators, whose runtime wrappers read a descriptor callback the element may not have (sorted needs compare, frequencies and unique need a key that stays findable after it is stored).

Trait Implementations§

Source§

impl Clone for TypePattern

Source§

fn clone(&self) -> TypePattern

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TypePattern

Source§

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

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

impl Display for TypePattern

Source§

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

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

impl Eq for TypePattern

Source§

impl PartialEq for TypePattern

Source§

fn eq(&self, other: &TypePattern) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TypePattern

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