Types¶
Static terms: types, indices, shapes, effect references, and their rendering.
types
¶
Static terms for the Quivers Indexed Effect Core (QIEC).
The module intentionally models only the kernel's small static language. Didactic and Panproto check a first-order projection of its indexed-family declarations, while these frozen records retain the QIEC-specific distinction between uniform parameters and refinable indices.
UNIT
module-attribute
¶
UNIT = TypeApplication(TypeConstructorRef.builtin('Unit'))
The unit type, inhabited by None alone.
BOOL
module-attribute
¶
BOOL = TypeApplication(TypeConstructorRef.builtin('Bool'))
The Boolean type.
REAL
module-attribute
¶
REAL = TypeApplication(TypeConstructorRef.builtin('Real'))
The real-number type.
STRING
module-attribute
¶
STRING = TypeApplication(TypeConstructorRef.builtin('String'))
The string type.
IndexTerm
¶
IndexTerm = IndexVariable | IndexLiteral | IndexConstructor | ShapeIndex
A static index: a variable, a literal, a constructor application, or a shape.
TypeExpr
¶
TypeExpr = TypeVariable | TypeApplication | FunctionType | EqualityType
A type: a variable, a constructor application, a function type, or an equality.
StaticArgument
¶
StaticArgument = TypeExpr | IndexTerm | EffectRef | EffectVariable
Anything a telescope binder may be instantiated at: a type, an index, or an effect.
IndexVariable
dataclass
¶
IndexVariable(name: str, sort: IndexSort, identity: StaticVariableId | None = None, tag: Literal['index_variable'] = 'index_variable')
A variable standing for an index term.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The variable's display name.
TYPE:
|
sort
|
The closed index sort of the terms it stands for.
TYPE:
|
identity
|
The rigid identity of a case branch's skolem, or
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
__eq__
¶
Compare by identity when either side is rigid, else by name.
A variable carrying a StaticVariableId is rigid: a case branch's
skolem, distinct from every other even where the names agree. One
without is a declaration binder, which two occurrences share by
name. Comparing a rigid variable to a free one is therefore
false, which is what stops a branch's skolem from unifying with
an enclosing binder.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The value to compare against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when both denote the same variable at the same sort. |
Source code in src/quivers/qiec/types.py
__hash__
¶
Hash the fields __eq__ compares.
| RETURNS | DESCRIPTION |
|---|---|
int
|
A hash of the sort with the identity when rigid, and with the name otherwise, so equal variables hash alike. |
Source code in src/quivers/qiec/types.py
IndexLiteral
dataclass
¶
IndexLiteral(value: int | str, sort: IndexSort, tag: Literal['index_literal'] = 'index_literal')
A closed index literal.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
A natural number for the nat sort, or a nullary constructor name for a user-defined index sort.
TYPE:
|
sort
|
The sort the literal inhabits.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
__post_init__
¶
Check the literal inhabits the sort it claims.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a |
Source code in src/quivers/qiec/types.py
IndexConstructor
dataclass
¶
IndexConstructor(name: str, arguments: tuple[IndexTerm, ...], sort: IndexSort, tag: Literal['index_constructor'] = 'index_constructor')
A fully applied constructor of a user-defined index sort.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The constructor's name, which must belong to
TYPE:
|
arguments
|
The constructor's index arguments, in order.
TYPE:
|
sort
|
The sort the constructor builds.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
__post_init__
¶
Check the constructor belongs to its sort and is fully applied.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the sort is not a user-defined one, if it declares no such constructor, or if the argument count differs from the declared arity. A partially applied index constructor is rejected rather than curried, since an index is a value of its sort and a partial application is not one. |
Source code in src/quivers/qiec/types.py
ShapeIndex
dataclass
¶
ShapeIndex(dimensions: tuple[IndexTerm, ...], tag: Literal['shape_index'] = 'shape_index')
A shape given by its dimensions.
| PARAMETER | DESCRIPTION |
|---|---|
dimensions
|
One index term per dimension, outermost first.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
TypeVariable
dataclass
¶
TypeVariable(name: str, kind: Kind = TYPE, identity: StaticVariableId | None = None, tag: Literal['type_variable'] = 'type_variable')
A variable standing for a type or effect-kinded static argument.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The variable's display name.
TYPE:
|
kind
|
The kind of the arguments it stands for. |
identity
|
The rigid identity of a case branch's skolem, or
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
__eq__
¶
Compare by identity when either side is rigid, else by name.
A variable carrying a StaticVariableId is rigid: a case branch's
skolem, distinct from every other even where the names agree. One
without is a declaration binder, which two occurrences share by
name. Comparing a rigid variable to a free one is therefore
false, which is what stops a branch's skolem from unifying with
an enclosing binder.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The value to compare against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when both denote the same variable at the same kind. |
Source code in src/quivers/qiec/types.py
__hash__
¶
Hash the fields __eq__ compares.
| RETURNS | DESCRIPTION |
|---|---|
int
|
A hash of the kind with the identity when rigid, and with the name otherwise, so equal variables hash alike. |
Source code in src/quivers/qiec/types.py
TypeConstructorRef
dataclass
¶
A fully qualified type constructor and its kinding telescope.
| PARAMETER | DESCRIPTION |
|---|---|
id
|
The constructor's stable identity, which alone determines equality.
TYPE:
|
name
|
The constructor's display name.
TYPE:
|
telescope
|
The binders the constructor's arguments instantiate, in order.
TYPE:
|
builtin
classmethod
¶
builtin(name: str) -> TypeConstructorRef
A constructor for one of the language's own types.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The builtin's name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TypeConstructorRef
|
A nullary constructor whose identity derives from the
|
Source code in src/quivers/qiec/types.py
__eq__
¶
Compare semantic identity, excluding diagnostic presentation data.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The value to compare against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when both name the same declaration. The display name and the telescope are presentation, so a constructor read back under a different spelling is still the same type. |
Source code in src/quivers/qiec/types.py
__hash__
¶
Hash the identity __eq__ compares.
| RETURNS | DESCRIPTION |
|---|---|
int
|
A hash of the declaration identity alone. |
TypeApplication
dataclass
¶
TypeApplication(constructor: TypeConstructorRef, arguments: tuple[StaticArgument, ...] = (), tag: Literal['type_application'] = 'type_application')
A type constructor applied to static arguments.
| PARAMETER | DESCRIPTION |
|---|---|
constructor
|
The constructor applied.
TYPE:
|
arguments
|
The arguments instantiating the constructor's telescope, in order; empty for a nullary constructor.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
FunctionType
dataclass
¶
FunctionType(parameter: TypeExpr, result: TypeExpr, tag: Literal['function_type'] = 'function_type')
A pure function type.
Effectful codomains are represented explicitly by
:class:quivers.qiec.effects.ComputationType, keeping the value and
computation strata separate.
| PARAMETER | DESCRIPTION |
|---|---|
parameter
|
The argument type.
TYPE:
|
result
|
The result type.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
EqualityType
dataclass
¶
EqualityType(kind: Kind | IndexSort, left: StaticArgument, right: StaticArgument, tag: Literal['equality_type'] = 'equality_type')
The proposition that two static arguments are equal.
| PARAMETER | DESCRIPTION |
|---|---|
kind
|
The kind or index sort both sides inhabit. |
left
|
The left side of the equation.
TYPE:
|
right
|
The right side of the equation.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
EffectVariable
dataclass
¶
EffectVariable(name: str, identity: StaticVariableId | None = None, tag: Literal['effect_variable'] = 'effect_variable')
A variable standing for an effect interface application.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The variable's display name.
TYPE:
|
identity
|
The rigid identity of a case branch's skolem, or
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
__eq__
¶
Compare by identity when either side is rigid, else by name.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The value to compare against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when both denote the same effect variable. A rigid variable never equals a free one, which is what keeps a branch's skolem from unifying with an enclosing binder. |
Source code in src/quivers/qiec/types.py
__hash__
¶
Hash the fields __eq__ compares.
| RETURNS | DESCRIPTION |
|---|---|
int
|
A hash of the identity when the variable is rigid, and of the name otherwise. |
Source code in src/quivers/qiec/types.py
EffectRef
dataclass
¶
EffectRef(id: EffectId, name: str, arguments: tuple[StaticArgument, ...] = (), tag: Literal['effect_ref'] = 'effect_ref')
One closed effect interface application.
| PARAMETER | DESCRIPTION |
|---|---|
id
|
The stable identity of the interface declaration.
TYPE:
|
name
|
The interface's display name.
TYPE:
|
arguments
|
The arguments instantiating the interface's telescope, in order.
TYPE:
|
tag
|
The serialization discriminator; always
TYPE:
|
__eq__
¶
Compare a concrete interface application by stable identity.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The value to compare against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when both name the same declaration and supply equal static arguments. The display name is ignored, and identity is nominal, so two applications of one interface differ only by their arguments. |
Source code in src/quivers/qiec/types.py
__hash__
¶
Hash the fields __eq__ compares.
| RETURNS | DESCRIPTION |
|---|---|
int
|
A hash of the declaration identity and the arguments. |
product_type
¶
product_type(*components: TypeExpr) -> TypeApplication
Construct the canonical finite-product type of the given arity.
| PARAMETER | DESCRIPTION |
|---|---|
components
|
The component types, in order.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TypeApplication
|
The product. Its constructor identity derives from the arity, so every two-component product in every module is the same type constructor and two products of different arity are different ones. |
Source code in src/quivers/qiec/types.py
static_kind
¶
static_kind(term: StaticArgument) -> Kind
Return the outer kind of a static term.
Index sorts are deliberately not collapsed into Type: callers that
validate an index binder compare the term's concrete sort separately.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The static term to classify.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Kind
|
The term's kind. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the term is an index, which carries a sort rather than a kind. Raising rather than returning a placeholder is what keeps a caller from comparing an index against a kind and finding them equal. |
Source code in src/quivers/qiec/types.py
index_sort
¶
Return an index term's sort, checking shape dimensions.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The index whose sort is wanted.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IndexSort
|
The term's sort. A shape reports its concrete rank, which is what lets a rank-polymorphic binder accept it while a binder of a fixed rank does not. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If a shape dimension is not of |
Source code in src/quivers/qiec/types.py
validate_static_argument
¶
validate_static_argument(term: StaticArgument) -> None
Recursively validate one intrinsically kinded static argument.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The static term to validate, together with everything nested in it.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If a term is of a class that cannot appear in a static position. |
ValueError
|
If an application is ill-kinded, or an index constructor is applied at the wrong arity. |
Source code in src/quivers/qiec/types.py
check_static_arguments
¶
check_static_arguments(telescope: Telescope, arguments: tuple[StaticArgument, ...]) -> tuple[tuple[tuple[str, TypeExpr], ...], tuple[tuple[str, IndexTerm], ...], tuple[tuple[str, EffectRef | EffectVariable], ...]]
Kind-check static arguments against a telescope and classify them.
| PARAMETER | DESCRIPTION |
|---|---|
telescope
|
The binders the arguments instantiate, in order.
TYPE:
|
arguments
|
One argument per binder.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[tuple[tuple[str, TypeExpr], ...], tuple[tuple[str, IndexTerm], ...], tuple[tuple[str, EffectRef | EffectVariable], ...]]
|
The type, index, and effect bindings the arguments make, each paired with its binder's name, in telescope order. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the counts differ, an argument is of the wrong static class for its binder, or an argument is of the wrong kind or index sort. |
ValueError
|
If a nested application is ill-kinded, or an index constructor is applied at the wrong arity. |
Source code in src/quivers/qiec/types.py
render_static
¶
render_static(term: StaticArgument) -> str
Render a static term in the surface spelling.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The type, index, or effect term to render.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
A readable rendering: a constructor applied to its arguments in
brackets, with shape arguments in parentheses after them; an
arrow for a function type; an equality with |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the term is not a static term. |