pub enum QalaType {
}Expand description
every type the type checker can talk about.
derive Debug, Clone, PartialEq only – no Eq, because future variants
may carry float-valued metadata, and no serde, because the typed AST and
codegen run in-process and never serialize a type. structural equality on
primitives and compounds, nominal equality on Named. use
QalaType::types_match (not bare ==) for the type-equality predicate
the type checker actually consults – it adds the Unknown
poison-as-wildcard rule that == does not.
Variants§
I64
the 64-bit signed integer primitive.
F64
the 64-bit IEEE 754 float primitive.
Bool
the boolean primitive.
Str
the string primitive.
Byte
the byte primitive (one 8-bit unsigned value, distinct from i64).
Void
the empty type, used as the return type of a function that has no
declared -> T and as the value type of statement-shaped expressions.
Array(Box<QalaType>, Option<usize>)
an array. Some(n) is the fixed-length [T; n] form; None is the
dynamic [T] form. the element type is boxed because an array of
arrays is legal and the box keeps QalaType a fixed size.
Tuple(Vec<QalaType>)
a tuple: an ordered list of element types. an empty tuple is the
void-shaped tuple that the language does not write directly (a
trailing-comma single-element tuple is a QalaType::Tuple of one).
Function
a function type. params is the (un-named) parameter types in order;
returns is boxed for the same fixed-size reason as Array.
Fields
Named(Symbol)
a user-declared type referenced by name – struct / enum /
interface. nominal equality: two Named values are equal iff their
Symbols are equal.
Result(Box<QalaType>, Box<QalaType>)
the built-in Result<T, E>. the type checker resolves a generic
Result<T, E> type expression to this variant directly, without a
user-defined generic mechanism.
Option(Box<QalaType>)
the built-in Option<T>. the type checker resolves a generic
Option<T> type expression to this variant directly.
FileHandle
the opaque handle returned by the stdlib open(path) call. a built-in
named type rather than a Named(Symbol("FileHandle")) so users do not
need to declare it; the stdlib signature table refers to this variant
by name. closing a FileHandle (close(h)) is checked structurally
the same way as any other call.
Unknown
the poison type emitted on a type error so the rest of the program
keeps typing. equal to anything under QalaType::types_match – the
research’s Pattern 3 – so a chain of expressions after the first error
does not cascade into a wall of follow-on errors.
Implementations§
Source§impl QalaType
impl QalaType
Sourcepub fn types_match(&self, other: &QalaType) -> bool
pub fn types_match(&self, other: &QalaType) -> bool
the type-equality predicate the type checker uses everywhere.
structural on primitives, Array, Tuple,
Function, Result, and
Option; nominal on Named (matches by
Symbol equality); reflexive on FileHandle.
Unknown is symmetrically equal to anything –
Unknown.types_match(x) and x.types_match(Unknown) are both true
for every x. that rule is what stops one type error from cascading
into many; it is Pattern 3 in the phase research.
note this is NOT the same as ==. == is derived structural equality
across the whole enum; it does not treat Unknown as a wildcard. always
use types_match when asking “do these two types agree, for the
purpose of type-checking?”.
Sourcepub fn display(&self) -> String
pub fn display(&self) -> String
the canonical lowercase form used in expected X, found Y wording.
i64, f64, bool, str, byte, void, [i64; 5] (fixed array),
[i64] (dynamic array), (i64, bool) (tuple), fn(i64) -> i64
(function), Shape (named – the symbol’s text verbatim),
Result<i64, str>, Option<i64>, FileHandle, and ? for
Unknown. the question-mark form for Unknown keeps
error messages short when poisoning propagates: “expected i64, found ?”
reads better than “expected i64, found unknown”.
recursive: an Array(Box<I64>, Some(5)) renders "[i64; 5]"; a
Function { params: vec![I64, Bool], returns: Box::new(Str) }
renders "fn(i64, bool) -> str".