Core TypesGeneric optional value container. Represents a value that may or may not exist.

Core Types

Option<T>

Generic optional value container. Represents a value that may or may not exist.

import core.option

Constructors

let some = Some(42)          // Option with value
let none = None<Int>()       // Empty option
let opt = Option<Int>.New()  // Empty option (alternative)

Methods

MethodReturnDescription
isSome()BoolTrue if value exists
isNone()BoolTrue if empty
unwrap()TGet value (panics if empty)
expect(message: String)TGet value (panics with message if empty)
unwrapOr(default: T)TGet value or return default
Store(value: T)VoidSet the value
Replace(value: T)Option<T>Replace value, return old
Clear()VoidRemove value

Example

fun findUser(id: Int) r: Option<String> {
    if id == 1 {
        return Some("Alice")
    }
    return None<String>()
}

fun main() {
    let user = findUser(1)
    if user.isSome() {
        println("Found: {user.unwrap()}")
    }
    let name = findUser(99).unwrapOr("Unknown")
}

Result<T, E>

Container for success/error values.

import core.result

Constructors

let ok = Ok<Int, String>(42)
let err = Err<Int, String>("not found")

Methods

MethodReturnDescription
isOkay()BoolTrue if success
isErr()BoolTrue if error
unwrap()TGet success value (panics if error)
expect(message: String)TGet value (panics with message if error)
unwrapOr(default: T)TGet value or return default
unwrapErr()EGet error value (panics if success)
swap()Result<E, T>Swap Ok and Err types

The ? Operator

Propagates errors:

fun process() r: Result<Int, String> {
    let x = parse("42")?   // returns Err early if parse fails
    return Ok(x * 2)
}

Allocation Errors

memory/allocation defines the resource-safety side of Seen's memory model.

import memory.allocation

Types

TypeDescription
AllocErrorAllocation failure details, including requested bytes and current budget state
MemoryStatsCurrent limit, used bytes, peak bytes, remaining bytes, and failure count

Functions

FunctionReturnDescription
setMemoryLimitBytes(bytes)VoidSet the process allocation budget
memoryStats()MemoryStatsRead runtime allocation counters
memoryRemainingBytes()IntReturn available tracked allocation budget
ensureAllocationBudget(bytes)Result<Unit, AllocError>Check budget before a fallible allocation path

Example

fun divide(a: Int, b: Int) r: Result<Int, String> {
    if b == 0 {
        return Err("division by zero")
    }
    return Ok(a / b)
}

fun main() {
    let result = divide(10, 3)
    if result.isOkay() {
        println("Result: {result.unwrap()}")
    } else {
        println("Error: {result.unwrapErr()}")
    }
}

Unit

The unit type, used as a placeholder when no value is needed:

import core.unit

let u = unit()

Useful as the value type in Result<Unit, E> or map types like HashMap<String, Unit> (set semantics).

Ordering

Comparison result type:

import core.ord

enum Ordering {
    Less
    Equal
    Greater
}

Functions

FunctionSignatureDescription
compareInt(a: Int, b: Int) r: OrderingCompare two integers
compareString(a: String, b: String) r: OrderingLexicographic string comparison
isLess(ord: Ordering) r: BoolCheck if Less
isEqual(ord: Ordering) r: BoolCheck if Equal
isGreater(ord: Ordering) r: BoolCheck if Greater

Type Conversion

import core.convert

core/convert defines conversion helpers and the Convertible class-style surface used by stdlib conversion code.

Int conversions

FunctionSignature
Int_from_Float(value: Float) r: Int
Int_from_String(value: String) r: Int
Int_from_Bool(value: Int) r: Int

Float conversions

FunctionSignature
Float_from_Int(value: Int) r: Float
Float_from_String(value: String) r: Float

String conversions

FunctionSignature
String_from_Int(value: Int) r: String
String_from_Float(value: Float) r: String
String_from_Bool(value: Int) r: String

Casting with as

let x: Int = 42
let f = x as Float     // 42.0
let s = x as String    // "42"

ToString Trait

@trait class ToString {
    fun toString() r: String
}

Free function converters:

  • Int_toString(value: Int) r: String
  • Float_toString(value: Float) r: String
  • Bool_toString(value: Int) r: String
  • Char_toString(value: Int) r: String

core/to_string also exposes FromString for parse-like conversions.

Prelude and Helpers

core/prelude contains common functions available to ordinary programs through the compiler/runtime prelude, including printing, assertions, and basic constructors.

Other core modules:

ModulePurpose
core/binaryBinary encoding helpers
core/bitfieldBitfield helpers
core/compressCompression helpers
core/intrinsicsCompiler/runtime intrinsic declarations
core/json_deriveJSON derive support
core/packetPacket helpers
core/reflectReflection metadata
Architected in Kotlin. Rendered with Materia. Powered by Aether.
© 2026 Yousef.