This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 9/16/2026.
Types
~import std/typesKoru Standard Library: Type Declarations
types.kz · 6 tors · ~[comptime]· ~[runtime]
Koru Standard Library: Type Declarations · 16 more lines
Koru Standard Library: Type Declarations
This module is the SURVIVING slice of the old type-mint surface. The mint
verbs (`std/types:struct`, `:type`, `:enum`, `:union`) were retired
2026-08-23: a construct whose only demand was its own test cluster was
redundant with the language spine (frag-type-system-design, fourth
dissolution). What remains:
- `fields-of(T)` — comptime traversal SOURCE over an EXISTING type's
fields; consumed by std/constructor's struct terminal.
- Nominal primitives — `string(EmailAddress)`, `int(UserId)`,
`float(Temperature)`, `bool(IsActive)` — distinct named wrappers.
The declaration front door going forward is `~std/types:proto(name)`
(layout-silent registry entries), landing with std/list as its first
consumer. Until then std/types intentionally declares NO composite types.
// COMPTIME FIELD REFLECTION
// `fields-of(T)` — a comptime traversal SOURCE over an existing type's fields.
// Iteration is EMERGENT: like `for`, it pulses `! each f` (each `f` a reflected
// field, `.name` / `.type`) rather than handing an iterator to a loop. Round one is
// consumed by std/constructor's struct terminal (lowered to Zig `@typeInfo`); a
// standalone lowering — `fields-of` traversing outside a constructor — is the later
// generalization, and the surface where Koru-level type reflection eventually lands.
~[comptime] pub tor fields-of { expr: Expression }
! each *
| ?done// NOMINAL PRIMITIVE TYPES
//
// PROTO ENTRIES
// `proto(Name) { field: type, ... }` declares a COMPILE-TIME registry entry —
// layout-silent, with no emission of its own: the first consumer derives what
// it needs (std/list:new synthesizes the element struct plus its
// `List_<Name>` container from these fields; the vector/table consumers are
// later rungs on the same entry). Registration is the AST scans' job: the
// checker and the type registry read the declaration flow FROM THE PRE-TRANSFORM
// AST (the same copy they read `struct`/nominal declarations from), and this
// transform self-erases the site into a comment so nothing runtime is emitted.
//
// USAGE:
// std/types:proto(Car) { rpm: i32, serial: string }
//
// RULED 2026-08-23 (frag-type-system-design, proto rung): the entry is the
// identity — two registrants of the same name are a loud collision, and values
// over two different protos must not interchange (both refused at the KORU
// layer by the nominal-distinctness gate; see scanDeclaredTypes + the
// container registration it derives).
~[keyword|comptime|transform] pub tor proto {
expr: Expression,
source: Source,
item: std/compiler:*const Item,
allocator: std.mem.Allocator,
reporter: std/compiler:*ErrorReporter
} -> SiteResult~[keyword|comptime|transform] pub tor string {
expr: Expression,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
allocator: std.mem.Allocator
} -> SiteResult// Declare a nominal integer type (wraps i64)
~[keyword|comptime|transform] pub tor int {
expr: Expression,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
allocator: std.mem.Allocator
} -> SiteResult// Declare a nominal float type (wraps f64)
~[keyword|comptime|transform] pub tor float {
expr: Expression,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
allocator: std.mem.Allocator
} -> SiteResult// Declare a nominal bool type (wraps bool)
~[keyword|comptime|transform] pub tor bool {
expr: Expression,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
allocator: std.mem.Allocator
} -> SiteResult