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
ctor: CollectionCtorargs: 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.
Function
The function type (params) -> result. Used for higher-order methods
like Vec[T].map.
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 strThe 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
item: Box<TypePattern>Implementations§
Source§impl TypePattern
impl TypePattern
Sourcepub const fn var(name: &'static str) -> TypePattern
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.
Sourcepub const fn bounded(name: &'static str, bound: Bound) -> TypePattern
pub const fn bounded(name: &'static str, bound: Bound) -> TypePattern
A type variable that must satisfy bound.
Sourcepub const fn is_scalar(name: &'static str, scalar: ScalarType) -> TypePattern
pub const fn is_scalar(name: &'static str, scalar: ScalarType) -> TypePattern
A type variable required to be exactly scalar — the Int-only sinks.
Sourcepub fn iterable(item: TypePattern) -> TypePattern
pub fn iterable(item: TypePattern) -> TypePattern
The pipeline receiver yielding item — Iterable { item }, spelled
without the Box every row would otherwise write (ADR-127).
Sourcepub const fn of_kind(name: &'static str, kind: CapKind) -> TypePattern
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
impl Clone for TypePattern
Source§fn clone(&self) -> TypePattern
fn clone(&self) -> TypePattern
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more