This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 8/19/2026.
Types
~import std/typesKoru Standard Library: Type Declarations
types.kz · 10 tors · ~[comptime]· ~[runtime]
Koru Standard Library: Type Declarations · 28 more lines
Koru Standard Library: Type Declarations
This module provides events for declaring Zig types that Koru can reason about.
All events use explicit module paths (no keywords) to keep things clear.
Koru doesn't have a built-in type system - Zig does all the type checking.
But by declaring types through these events, Koru can:
- Track types in a registry for transforms
- Apply layout annotations like [soa], [packed]
- Enable data-oriented patterns (ECS, etc.)
USAGE:
import std/types
std/types:struct(Player) { name: []const u8, health: i32 }
[pub]std/types:struct(Position) { x: f32, y: f32 }
std/types:enum(Color) { red, green, blue }
[pub]std/types:enum(State) { idle, running, jumping }
std/types:union(Value) { int: i32, float: f32, none }
Future annotations:
[pub|soa]std/types:struct(Enemies) { hp: i32, x: f32, y: f32 }
[packed]std/types:struct(NetworkPacket) { ... }
NOTE: For const declarations, use raw Zig or const (in std/declarations —
const is a value declaration, not a type, so it lives in its own module).
// TYPE DECLARATIONS
//
// Declare a Zig struct type
// [pub] - emits `pub const Name = struct { ... }`
// [soa] - (future) emits struct-of-arrays layout
// [packed] - (future) emits packed struct
// `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~[keyword|comptime|transform] pub tor struct {
expr: Expression,
source: Source,
item: *const Item,
program: *const Program,
allocator: std.mem.Allocator
} -> SiteResult~[norun] pub tor struct.impl { name: string }// Declare a Zig enum type
~[comptime|norun] pub tor enum { expr: Expression, source: Source }// Declare a Zig union type
~[comptime|norun] pub tor union { expr: Expression, source: Source }// NOMINAL PRIMITIVE TYPES
// These create distinct named types that wrap Zig primitives.
// Koru tracks them as separate types for type checking.
//
// USAGE:
// string(EmailAddress) // wraps []const u8
// int(UserId) // wraps i64
// float(Temperature) // wraps f64
// bool(IsActive) // wraps bool
//
// Declare a nominal string type (wraps []const u8)
~[keyword|comptime|transform] pub tor string {
expr: Expression,
item: *const Item,
program: *const Program,
allocator: std.mem.Allocator
} -> SiteResult// Declare a nominal integer type (wraps i64)
~[keyword|comptime|transform] pub tor int {
expr: Expression,
item: *const Item,
program: *const Program,
allocator: std.mem.Allocator
} -> SiteResult// Declare a nominal float type (wraps f64)
~[keyword|comptime|transform] pub tor float {
expr: Expression,
item: *const Item,
program: *const Program,
allocator: std.mem.Allocator
} -> SiteResult// Declare a nominal bool type (wraps bool)
~[keyword|comptime|transform] pub tor bool {
expr: Expression,
item: *const Item,
program: *const Program,
allocator: std.mem.Allocator
} -> SiteResult// GENERIC TYPE INSTANTIATION
// Instantiate a generic type with concrete type arguments.
//
// USAGE:
// struct(Option<T>) { value: ?T = null } // Define generic
// type(OptionalInt = Option<i32>) // Instantiate it
//
// struct(Pair<A, B>) { first: A, second: B }
// type(StringIntPair = Pair<[]const u8, i32>)
~[keyword|comptime|transform] pub tor type {
expr: Expression,
item: *const Item,
program: *const Program,
allocator: std.mem.Allocator
} -> SiteResult