Why U?
Most languages aim for one pit of success. U aims for two — one for developers, one for every tool that reasons about the code afterward. To our knowledge, U is the first language designed for two audiences at once: humans who write and review code, and LLMs that autonomously write, analyse, and reason about large codebases.
Pit 1 — For developers: the easy path is the safe path
A function written in U with no annotations is already correct by default. Parameters are local, immutable, and non-null. The compiled output uses no heap allocation, no ARC operations, no locks, no null checks. You get the safest and fastest possible program without writing a single modifier.
Every cost you might want to add — heap allocation, mutability, shared ownership, async suspension, nullable values — requires an explicit + annotation. You cannot accidentally pay for something you didn't ask for. You cannot accidentally make something unsafe without a visible opt-in. The pit of success means the path of least resistance is also the path of least risk.
// No annotations — you still get all of this for free: f process(data: [N], label: S): Stats total = data.reduce((acc, val) => acc + val, 0.0) r => { total, mean: total / data.length, label } // ✅ No heap allocation (-R default) // ✅ No null dereference (-N default) // ✅ No data race (-R: nothing shared) // ✅ No ARC cost (-R: no refcount) // ✅ Zero-copy return (r.field = DPS) // ✅ Bounds-safe iteration (.x() / .reduce())
Pit 2 — For tooling: declared structure beats inferred structure
Today when a compiler, static analyser, or LLM inspects a codebase, it performs expensive reconstruction work: inferring ownership patterns, guessing threading assumptions, rebuilding the call graph, reconstructing what each binding is supposed to mean. That work is paid on every query, produces approximations, and is discarded at session end.
In a U codebase, every binding site is a machine-readable declaration of intent. +R+M(MVCC) says exactly how a shared object behaves under concurrent writes. +N marks every nullable boundary. ! NetworkError declares exactly what can fail. The entire semantic structure of the program is explicit in the syntax — not buried in conventions, comments, or commit history.
Existing language — inference every time
// Tool must infer: // — is config shared or local? // — can it be null? // — what write policy applies? // — what errors can this throw? // — does this escape its scope? let config = loadConfig(); config.host = newHost; // Expensive. Approximate. Repeated.
U — structure declared once, read forever
// Tool reads directly: // — shared heap, MVCC writes // — non-null // — MVCC policy // — declares ! NetworkError // — +R = heap, will not escape as -R config: Config+R+M(MVCC) = load() config << { host: newHost } // O(1). Exact. Stable across queries.
This changes the economics of code analysis. An entire class of infrastructure bugs — data races, use-after-free, null dereference, async violations, injection attacks — is structurally impossible and doesn't need to be searched for at all. The bugs that remain are logic bugs, and they can be targeted precisely because the program's semantic structure is already declared.
Every language before U was designed for one audience: the human developer. LLMs arrived later and had to reconstruct implicit structure — ownership patterns, threading assumptions, nullable boundaries — through expensive inference, on every query, discarded at session end.
In U, that structure is declared at the binding site, verified by the compiler, and readable by any tool in O(1). The same annotations that make code correct for humans make it legible for LLMs. To our knowledge, U is the first language that treats LLMs as a first-class consumer rather than an afterthought.
Every binding in U has a statically known type at compile time. There is no any, no root Object, no untyped back door. The : type test is for narrowing only — checking whether a Shape is a Circle, whether an object implements Drawable. It is never needed to ask "is this typed?" because every value always is.
Java has Object casts. TypeScript has any. Go has interface{}. Swift has Any. U has none of these. If you cannot name the type of a value, the design is incomplete.
Contents
/* */ nesting supported
02Primitives & LiteralsI N S L B V — single-letter types, width suffixes
03.5ParenthesesNo {} · () for blocks and grouping · last expr is value
03.6ComprehensionsShorthand {host, port} · spread {...obj, key: val}
03VariablesInferred types · identifiers must be multi-letter
04Functions & Lambdasf named · => lambda · r return · zero-copy DPS
04.5Closures & Arrowsf hoisted + named · () => anonymous + captures t · modifier rules apply
05KeywordsAll 10, single letter — complete and settled
06Modifiers7 commutative dimensions · zero annotation = safest & fastest
05.5Namespaces & Moduleso keyword · import · export · t inference · multi-file extension
06.5+F Function ModifierT +F = any callable producing T · bare form most general
07Classes & Selfd · : inheritance · +P policy · no multiple inheritance
07.5Type Hierarchiesd Foo.Bar : Foo · enum replacement · typed dispatch · +G static
07.6Interfacesd Foo! · f method()! · never static · untyped params banned
08MapsDynamic keys · full modifier enforcement on values
08.5Magic Methods__hash · __equals · __serialize · __unserialize · __merge
09Null Safety-N default — null dereference is a compile error
10Conditionals?! : & | ?? — no if/else/switch/match keywords
11Iteration.x() replaces all loops · always bounded · pipelines
11.5Ranges1..5 · * step · scalar lift · array slicing · zero allocation
12Generatorsw loop · y yield · w+I intentionally infinite
13Error Handlinge throw · e.x() typed handler chain · object interfaces · ! ErrType
14Fibers & Red-BlueStackful · any depth can suspend · async coloring solved
15Async — a keywordAuto-await default · a f() opt-in · T +A pending type
15.5+A as Pending Typea and +A co-required · exactly two valid call forms
15.6Zero-Cost PrincipleLazy materialization · no cost unless both conditions hold
15.7BackpressureT +A return in .x() → bounded concurrency, no primitives
16Scheduler & Yielda; cooperative · a n timed · toposort · typed pub/sub
17Proxy Policies+R(RAII) / +M(Actor|MVCC|CRDT|Mutex) · class-level or binding-site
18Templates & i18nhtml/sql/msg interpolation escaped at compile time · injection = type error
19Arithmetic SafetySafe by default · ! to opt out · compiler elides proven checks
20Memory ModelTiered from type · ARC without atomics · no GC pauses
21Copy — .c()Only explicit copy mechanism · lazy COW · free when refcount=1
22Zero-Copy ReturnsDestination-passing style · compiler-guaranteed, not hoped for
23Defaults-R -M -N: zero annotation = max safety and max speed simultaneously
24Safety by Construction11 error categories — type errors, not runtime crashes
17.5Access Policies +P()RAII · ARC · MVCC · CRDT · Actor · vs GC languages
17.6MVCC DefaultDefault write policy · atomicity · rollback on exception
23.5vs C++, Java, Rust, GoExceptions · RAII · null safety — detailed comparison
25vs Go / JS / SwiftColoring solved · no microtask starvation · minimal fiber frames
26vs Rust / ZigMultiple writers via proxy · modifier replaces borrow checker + allocator param
27Formal Guarantees22 theorems · 8 corollaries · all proved in the λ_U calculus
Seven modifier dimensions replace escape analysis, alias analysis, null checks, ARC atomics, async coloring, injection vulnerabilities, and i18n errors. Each annotation is a proved safety invariant and a compiler oracle. The zero-annotation default is the safest path and the fastest path.
U — Where the Easy Path Is the Safe Path
U is a systems programming language built around one insight: type annotations serve two clients simultaneously. The programmer gets safety guarantees. The compiler gets optimization licenses. Same annotation. Both benefits.
-R -M -N is the safest path and the fastest path. Every cost — heap allocation, mutability, nullability, sharing, async survival — is opt-in with an explicit +. You cannot accidentally pay for something you didn't ask for.// No annotations — local, immutable, non-null, zero cost f main() greeting = "Hello, world!" // S -R -M -N — inferred console.log(greeting) // greeting is: local (no heap), immutable (no lock), non-null (no check) // The compiler emits zero allocation, zero null check, zero ARC operation.
Comments — like C, but /* */ supports nesting
Single-line // and block /* */, identical to C. The one difference: block comments nest. This means you can wrap any section of code in /* ... */ without first checking whether it already contains block comments.
/* already commented */ ends the outer comment early, leaving the rest as live code. U's nested /* */ means comment-out always works, regardless of what's inside.
// Single-line — to end of line /* Block — spans lines */ /* Nesting works — unlike C /* inner comment */ still commented out here */ /* Comment out any block safely, even if it has block comments inside: f oldVersion(data: [I]) /* deprecated */ process(data) */ f add(a: I, b: I): I // inline is fine too r => a + b
Primitives & Literals
All primitive types are single uppercase letters. Width specifiers suffix the letter. No verbosity — I not int32_t.
| Type | Meaning | Width variants | Literals |
|---|---|---|---|
| I | Signed integer | I8 I16 I32 I64 | 42 -7 0xff |
| U | Unsigned integer | U8 U16 U32 U64 | 255u 0b1010u |
| N | Float (number) | N32 N64 | 3.14 1.0e-9 |
| D | Exact decimal | D32 D64 D128 | 9.99d 0.001d |
| S | String (UTF-8) | — | "hello" |
| L | Boolean | — | true false |
| B | Byte (raw) | — | 0x00–0xFF |
| none | Null literal | — | type T+N |
| true | Boolean true | — | type L |
| false | Boolean false | — | type L |
count = 42 // I inferred small: I32 = -7 // I32 explicit width ratio = 3.14 // N float64 price = 9.99d // D exact decimal, no float rounding msg = "Hello!" // S UTF-8 string alive = true // L boolean nothing: I+N = none // nullable integer — requires +N annotation // Ranges — produce iterable values exclusive = 0..10 // [0,10) — 0,1,2,...,9 inclusive = 1..=5 // [1,5] — 1,2,3,4,5
RegExp — class, not literal syntax
Regular expressions use RegExp(pattern, flags) — a plain class constructor. No /pattern/flags syntax. The compiler optimizes calls with string literals to compiled patterns at build time.
email = RegExp("[a-z]+@[a-z]+\.[a-z]+", "i") // compiled at build time match = email.match(input) // returns [S]+N clean = RegExp("\s+").replace(text, " ")
Comprehensions & Spread
Shorthand literal syntax for constructing objects and maps from existing values. Works for class instantiation and map literals.
// Shorthand: variable name used as key host = "localhost" port = 8080 config = Config({ host, port }) // Config({ host: host, port: port }) // Spread + override: ... spreads all fields, then overrides newConfig = Config({ ...config, host: "newhost" }) newMap = { ...meta, "version": 4 } // map spread // Works in any expression context servers = configs.map((cfg) => Server({ ...cfg, active: true }))
Variables & Type Inference
U infers types from the right-hand side. The inferred type gets default modifiers -R -M -N. Annotations are optional — add them only when you want to change the defaults.
count not c, index not i. Descriptive names are structural.// Inferred — all default to -R -M -N count = 0 // I -R +M -N (local mutable, class default) ratio = 3.14 // N -R -M -N greeting = "hello" // S -R -M -N point = { x: 1.0, y: 2.0 } // {x:N,y:N} -R +M -N items = [1, 2, 3] // [I] -R +M -N // Explicit — override inferred type or modifiers shared: I+R+M = 0 // shared mutable integer on heap config: Config+R-M = load() // shared immutable Config maybe: User+N = none // nullable User width: I32 = 640 // explicit 32-bit width
Parentheses — Grouping and Block Scope
U has no {} curly braces. () are the only grouping construct. Inside parentheses, newlines are free — the expression continues until the closing ). The last expression inside a block is its value. This applies everywhere: argument lists, conditions, chained operations, multi-statement blocks.
(). Everything is an expression, so a () block produces a value.
// Grouping across newlines — continues until ) total = ( subtotal + tax + shipping ) // Block expression — multiple statements, last is value result = ( step1 = doFirstThing() step2 = doSecondThing(step1) step1 + step2 // ← value of the block ) // Complex condition spread across lines valid = ( user.age >= 18 & user.verified & !user.banned ) // Argument list — newlines freely between args response = submitOrder( orderId, items.x((i) => i.c(+R)), shipping.address, payment.token ) // Pipeline of operations that would be awkward inline processed = ( raw = a fetch(url) clean = sanitize(raw) valid = validate(clean) valid // ← returned value ) // Chained method calls broken across lines summary = ( orders .x((order) => order.paid) .x((order) => order.amount) .reduce((acc, amt) => acc + amt, 0.0) ) // Ternary branches using () for multi-line without indentation rules label = count > 0 ? ( plural = count > 1 plural ? "{count} items" ! "1 item" ) ! "empty"
Functions & Lambdas
Named functions use f. Lambdas use => alone — no f needed. Return is assignment to r. Building the return value field-by-field with r.field = ... writes directly into the caller's pre-allocated stack slot — no copy ever happens.
// Named function f add(left: I, right: I): I r => left + right // Short form — expression body f square(val: N) = val * val // Lambda — => implies anonymous, no f needed double = val => val * 2 increment = val => val + 1 // Multi-expression lambda — last expression is the return value clean = item => ( trimmed = item.trim() trimmed.lowercase() // returned ) // Return-by-construction — r.field writes into caller's pre-allocated slot // No copy on return. Destination-passing style, guaranteed by the type system. f buildUser(name: S, age: I): User r.name = name // writes directly to caller's frame r.age = age // no copy occurs at return // Default parameters f connect(host: S, port: I = 8080): Connection+R+M+N r => tcp.dial(host, port) // Higher-order — F(I):S means "function taking I, returning S" f applyTwice(fn: F(I):I, val: I): I r => fn(fn(val)) result = applyTwice(double, 3) // 12
Optional named parameters — {} at end
The last parameter may be an anonymous typed map, destructured by the compiler. Named params are optional, have declared types and defaults, and never break existing callers when extended.
• Positional params: required, ordered, no defaults — always honest
• One
{} at the end: anonymous destructured map, defaults allowed
• No defaults on positional params — ever (compiler error)
• No anonymous
{} in middle positions — use a named class there
// {} at end — optional named params with defaults f fetch(url: S, count: I, { timeout: I = 30, verbose: L = false }) fetch("api.com", 5) // all defaults fetch("api.com", 5, { verbose: true }) // one override fetch("api.com", 5, { timeout: 60, verbose: true }) // two overrides // Adding new optional never breaks callers: // f fetch(url: S, count: I, { timeout: I = 30, verbose: L = false, retries: I = 3 }) // All existing call sites still work unchanged // {} in middle? Use a named class instead: d FetchOpts { timeout: I = 30 } f weirdFunc(x: I, opts: FetchOpts, y: S) // explicit, named weirdFunc(5, FetchOpts({ timeout: 60 }), "hi") // ❌ No defaults on positional params — compile error: // f bad(x: I, y: I = 5) ← banned
Instantiation — ClassName({...})
No new keyword. ClassName({...}) creates an instance — familiar to JS developers. If no __construct is defined, the compiler auto-generates one from the declared fields.
d Config host: S = "localhost" port: I = 8080 debug: L = false cfg = Config({}) // all defaults prod = Config({ host: "prod.api.com", port: 443 }) // __construct overrides auto-generated init: d Cache maxSize: I items: {S: S}+M = {} // typed map f __construct({ maxSize: I = 100 }) validate(t.maxSize > 0) // custom logic // (Cache has no parent — parent calls only apply when extending a class)
Surplus-argument dropping
A handler may declare fewer parameters than it will receive. Surplus arguments are silently dropped from the right. This is not the same as default values — the caller supplies all arguments; the callee simply ignores the extras.
Primary use case: iteration handlers. Array and map methods pass
(value, key); handlers that only care about the value declare one parameter and the key is dropped.
// Array iteration: (value, index) passed, handler takes only value nums = [10, 20, 30] nums.x((n: I) => print(n.toString())) // index silently dropped nums.x((n: I, i: I) => print(i.toString() + ": " + n.toString())) // both // Map iteration: (value, key) passed scores: {S: N} = { "alice": 9.8, "bob": 7.4 } scores.x((score: N) => process(score)) // key silently dropped scores.x((score: N, name: S) => print(name)) // both — note value comes first // Named functions also obey the rule when used as handlers: f process(item: S): L r => item.length > 0 items.filter(process) // (S, I) passed, process takes (S) — I dropped // Compile error — declared param type must match what's supplied: // scores.x((score: I) => ...) ← ✗ N supplied, I declared
Closures & Arrow Functions
U has two function forms. They differ on naming, hoisting, and t capture.
f name(params) | (params) => expr | |
|---|---|---|
| Name | Required | Optional (usually anonymous) |
| Hoisted | Yes — callable before declaration | No — it's a value expression |
t (self) | Explicit parameter — not captured | Captured from enclosing scope |
| Multi-line | Indented body | (params) => ( ... block ... ) |
| Use for | Reusable named logic, methods | Callbacks, policies, inline transforms |
f functions. If you write f, name it. Names make functions findable, reusable, and documentable. Arrow functions are intentionally disposable — use them for one-shot inline logic.
-> for types, => for values — one symbol per role.(I)->I — a function type: "takes I, returns I". Appears in type annotations after :.(x: I) => x * 2 — a function value: "given x of type I, produce x * 2". Appears in expressions.The visual distinction is deliberate.
-> is the classical type-theory arrow (Haskell, Swift, Kotlin). => produces a value. Seeing (NetworkError)->() you immediately know it's a type; seeing (err) => retry(err) you know it's a closure.
// Named f — hoisted, t is explicit, not captured f greet(name: S): S r => "Hello, " + name greet("Alice") // fine even before the f declaration above (hoisted) // Arrow function — anonymous, captures t, is a value greet: (S)->S = (name) => "Hello, " + name // Multi-line arrow uses () block — last expr is the value process: (I)->S = (num) => ( doubled = num * 2 "result: {doubled}" ) // Closure — captures outer variable, subject to modifier rules f makeMultiplier(factor: I): (I)->I r => (num: I) => num * factor // captures factor (I is -R, value-copied in) double = makeMultiplier(2) // double: (I)->I double(5) // 10 // Capture rules — same modifier rules as any variable f setup() local: S = "hello" // -R stack msg: S+R = local.c(+R) // heap copy ok: (()->())+F-R = () => log(local) // ✅ non-escaping, in-scope only bad: (()->())+F+R = () => log(local) // ❌ ERROR: +F +R captures -R local fine: (()->())+F+R = () => log(msg) // ✅ +R captured into +F +R // In a class: arrow captures t, f() does not d Button clicks: I+M = 0 f onClick() // t is explicit — this is a method call t.clicks = t.clicks + 1 handler: (ClickEvent)->() = (e) => // arrow captures t from Button instance t.clicks = t.clicks + 1 // ✅ t is the Button // Function values carry all modifiers like any other value policy: (NetworkError)->()+R = (err) => retry(err) // heap, shareable policies: [(NetworkError)->()] = [logToSentry, retryOnRecoverable] // array // Passed to e.x() as a policy array — order defined, preserved e.x(policies)
Keywords — 11 + 3
Fourteen keywords total: eleven single-letter (a b c d e f o r t w y) and three multi-letter literals (none, true, false). You can memorize the entire language vocabulary in five minutes.
a f declaration = behavioral keyword marking function as suspendable. (2) a f() call site = opt into T +A pending (co-requires +A on LHS). (3) a; or a n = cooperative/timed yield.w generator/loop early.w loop.=> without f.r => value or r.field = ... for zero-copy return-by-construction.this in JS or self in Python.b reachable. w+I for intentionally infinite.w generator to the consumer.o Math.Linear imports, o Math.Linear => (...) exports. Four import forms: plain, .* glob, scoped (...), scoped glob .*(...).T+N. Use ?? to coalesce and +N to permit.L.L.// f — named function d — class definition d Stack items: [Any]+R+M f push(stack: Stack+R+M, item: Any) t.items.append(item) // t — self/this f pop(stack: Stack+R+M): Any t.items.isEmpty() & e StackUnderflow() // e — throw error r => t.items.removeLast() // r — return // w — generator loop y — yield b — break c — continue f evens(): I num = 0 w+I // w+I = intentionally infinite num % 2 != 0 & c // c — skip odd numbers y num // y — yield even number num = num + 1 // a — async function and suspension operator a fetchUser(id: I): User+N r => a db.find(id) // 'a' here = suspend (like await) // none — the null value (multi-letter literal) maybeUser: User+N = none
The Modifier System — ±R ±M ±N +V +C +A +F
Modifiers are single letters prefixed with + or -, placed after the type. Three binary axes plus three hardware domain modifiers. All default to the - (cheapest, safest) option.
-R Local, stack-resident, non-shared. Zero ARC cost.
+R Heap-resident, ARC-managed, shareable.
-M Immutable through this reference.
+M Mutable. Proxy-mediated when +R.
-N Guaranteed non-null. No null check emitted.
+N May be none. Must handle before use.
SIMD on CPU · warp execution on GPU. Applies to numeric types: N32+V, I8+V, I16+V. Invalid on L, S, B — compile error.
Near-memory, cache-line aligned. Compiler emits prefetch hints. Useful for hot loop data.
Survives fiber suspension. Saved to fiber frame at yield. Without +A, value stays on stack only.
// -R -M -N default: stack, immutable, non-null — zero cost f process(user: User, count: I): S // all -R -M -N r => "done" // +N nullable — result may be none f findUser(id: I): User+N // +N: may return none r => db.find(id) // +R -M shared immutable — safe to broadcast, no lock needed config: Config+R-M = loadConfig() workers.x(worker => worker.configure(config)) // zero-copy broadcast // +R +M shared mutable — proxy-mediated writes cache: Cache+R+M = Cache() +M(MVCC) cache.set(key, val) // routed through MVCC proxy // +V: vectorized execution (SIMD on CPU, warps on GPU) simdVec: [N32]+V = loadData() // CPU SIMD — data stays on CPU gpuVec: [N32]+R(GPU) = simdVec.c(+R(GPU)) // copy to GPU device memory runKernel(gpuVec) // dispatches as GPU warps // same matrix type, different location — same API weights: [[N32]] = loadModel() // CPU scalar weights: [[N32]]+V = loadModel() // CPU SIMD weights: [[N32]]+R(GPU) = loadModel() // GPU device memory weights: [[N32]]+R(Network) = loadModel() // remote cluster // +A survives fiber suspension a handle(): Response buf: [L] = alloc(4096) // -A: stack-local, NOT saved at suspension state: Req+R+A = buildReq() // +A: saved to fiber frame result = a net.get(state) // suspend — only state saved, not buf r => parse(result, state)
The 8-Combination Matrix
| Combination | Contract | Alloc | Sync | Null chk | ARC |
|---|---|---|---|---|---|
-R -M -N | local immutable non-null | stack | none | none | none |
-R -M +N | local immutable nullable | stack | none | on use | none |
-R +M -N | local mutable non-null | stack | none | none | none |
-R +M +N | local mutable nullable | stack | none | on use | none |
+R -M -N | shared immutable non-null | heap | lock-free | none | integer |
+R -M +N | shared immutable nullable | heap | lock-free | on use | integer |
+R +M -N | shared mutable non-null | heap | proxy | none | integer |
+R +M +N | shared mutable nullable | heap | proxy | on use | integer |
Namespaces & Modules — o
The o keyword ("outside") handles both import and export. Dots in class and function names are free namespacing — d Foo.Bar is simply a class named Foo.Bar, no special mechanism needed. o declares which namespace a file contributes to, and how to bring namespaces into scope.
Importing — four forms
o Math.Linear // qualified: Linear.matmul, Linear.Foo available o Math.Linear.* // glob: matmul, Foo available as bare names o Math.Linear ( // scoped qualified: only inside this block result = Linear.matmul(a, b) ) // Linear no longer in scope here o Math.Linear.* ( // scoped glob: only inside this block result = matmul(a, b) // bare name works here ) // matmul no longer in scope here
.* by default? Two modules both exporting transform or parse create silent conflicts. The explicit .* is a visible declaration: "I know I'm unpacking everything into this scope."
Exporting — o Name => (...)
The => direction makes intent unambiguous: this block produces into the namespace. Multiple files can contribute to the same namespace — open extension, like traits.
// file: math/linear.u f _helper(a: [N32+V], b: [N32+V]): N // _ prefix → private, never exported a.reduce((acc, i, v) => acc + v * b[i], 0.0) o Math.Linear => ( d Result // becomes Math.Linear.Result value: [[N32+V]] error: N f matmul(a: [[N32+V]], b: [[N32+V]]): [[N32+V]] // t absent → +G inferred r => a.x((i, row) => row.x((j, _) => _helper(row, b.col(j)))) f scale(factor: N): [[N32+V]] // t used below → instance method r => t.x((i, row) => row.x((j, v) => v * factor)) )
Static vs instance — inferred from t
The compiler scans the function body for the keyword t (self). Present anywhere → instance method. Absent → +G (static) inferred. No annotation needed. A function with no t has no business being an instance method — the rule is correct by definition, not just convenient.
o Geometry => ( d Circle radius: N f unitCircle(): Circle // no t → +G, called as Geometry.unitCircle() r => Circle({ radius: 1.0 }) f area(): N // t used → instance method r => Math.PI * t.radius ^ 2 f scale(factor: N): Circle // t used → instance method r => Circle({ radius: t.radius * factor }) ) // static callable on instance as sugar: c = Geometry.unitCircle() // direct c = someCircle.unitCircle() // also valid — desugars to above
Multi-file namespaces — open extension
// math/linear_basic.u o Math.Linear => ( f matmul(...) ) // math/linear_advanced.u — extends same namespace o Math.Linear => ( f svd(...) f lu(...) ) // conflict (same function name in two files) = compile error
External packages
o "github.com/u-lang/math" // external — resolved by package manager o "./utils" // relative — exposes utils/*.u namespaces
+F — The Function Domain Modifier
The modifier set gains a seventh dimension: +F, the function domain. All modifiers are commutative — the set is unordered. Three forms: bare, nullary, and typed.
Modifier Commutativity — The Fundamental Rule
T +R +M and T +M +R are identical. T +F +A +R and T +R +A +F are identical. The parser normalizes to canonical order for display; semantics are always position-independent.The Complete Seven-Dimension Modifier Set
| Modifier | Domain | Meaning | Default |
|---|---|---|---|
| ±R | Ownership | -R: stack-local · +R: heap, ARC | -R |
| ±M | Mutability | -M: immutable · +M: mutable, proxy-mediated | -M |
| ±N | Nullability | -N: non-null · +N: may be none | -N |
| V | Vectorized float | — | |
| +C | Cache | Near-memory, prefetch | — |
| +A | Async | Async domain: pending or suspendable | — |
| +F | Function | Callable producing the base type T | — |
Three Forms of +F
| Form | Meaning | Use case |
|---|---|---|
T +Fbare — no parens |
Any callable producing T. Input types unspecified. Compiler enforces T's full modifier stack without constraining inputs. | Heterogeneous callable collections, factories, hooks |
T +F()explicit nullary |
Explicitly zero-argument callable producing T. | Thunks, lazy initializers, event callbacks |
T +F(S)typed args |
Function taking S, producing T. Full type information. | Typed callbacks, typed transformers |
+N (nullable handling), +R (heap allocation), +A (async await) — without knowing or caring what arguments the callable takes. A collection typed [Config +R +F] guarantees every callable returns a shared Config, no matter its input shape.+F in Practice
// ── Bare +F: heterogeneous callables, homogeneous output ────── hooks: [Config+F] = [] // any callable producing Config hooks.append(loadFromFile) // Config +F(path: S) hooks.append(loadFromEnv) // Config +F() hooks.append(loadWithDefault(b)) // Config +F() +R (closure) // compiler: every result is Config — enforces modifiers on output configs: [Config] = hooks.x(hook => hook(...)) // ── +F(): explicit nullary ──────────────────────────────────── thunk: Config+F() = () => Config.default() cfg = thunk() // called with zero args // ── +F(S): fully typed ─────────────────────────────────────── parser: Config+F(S) = parseConfig // takes S, returns Config cfg = parser(rawJson) // ── Composing with other modifiers (commutative) ───────────── handler: Config+F(S)+R // escaping closure fetcher: Config+F(S)+A // async function maybe: Config+F(S)+N // nullable reference escAsync: Config+F(S)+R+A // escaping async closure // Order is irrelevant — all identical: Config+F+R+A == Config+A+R+F == Config+R+A+F // same type
+F Compiler Oracle
| Type | Compiler decision |
|---|---|
T +F (bare) | enforce full T modifier stack on output — no constraint on inputs |
T +F without +R | inline or static ptr — no indirection |
T +F +R | indirect call via closure vtable |
T +F +A | auto-await check inserted at call site |
T +F +R +A | vtable call + auto-await |
T +F +N | null check before call |
+F +A — Async Function Type
Config +F(S) +A = async function taking S, producing Config. When called without a: auto-await, Config delivered transparently. When called with a: Config +A pending.Commutativity confirms:
+F +A = +A +F = one type, one meaning. "Async function returning T" and "function returning T +A" collapse — the call site determines which you get.
+F +R — The Bound Closure Type
A method closure capturing t (self) needs heap allocation to outlive its call frame — that's exactly +F +R. No separate bound-method concept needed.
d Server f getHandler(server: Server+R): Response+F(Request)+R r => req => t.handleRequest(req) // captures t — needs +R handler: Response+F(Request)+R = server.getHandler() route.register(path, handler) // stored in routing table, survives
Bare +F for Dependency Injection and Plugin Systems
// Plugin system: all plugins produce S, inputs vary d PluginRegistry plugins: Map // keyed by name f register(registry: PluginRegistry+R+M, name: S, plugin: S+F) t.plugins[name] = plugin // S +F: any callable producing S f run(registry: PluginRegistry, name: S): S+N plugin: S+F+N = t.plugins[name] r => plugin & plugin(...) // null-guard + call // Compiler: result is S, handling enforced regardless of plugin internals
Classes, Inheritance & Policy — d, t, :
Classes use d. No separate struct keyword — a -R instance compiles identically to a C struct on the stack. t is self inside methods. : introduces a base class. No multiple inheritance.
The +M(policy) modifier declares how +R +M instances are mediated — either as a class-level default or overridden at the binding site.
// Basic class d Point x: N y: N f distance(other: Point): N dx = t.x - other.x // t = self dy = t.y - other.y r => (dx*dx + dy*dy).sqrt() // Inheritance — : introduces base class, no multiple inheritance d Animal name: S f speak(): S r => "..." d Dog : Animal // Dog inherits from Animal breed: S f speak(): S r => "Woof" // override // +P — policy modifier, class-level default // all +R +M instances of Counter are Actor-mediated by default d Counter+M(Actor) value: I f increment(t: Counter+R+M) t.value = t.value + 1 // Caller: no a needed — fiber handles Actor dispatch transparently counter: Counter+R+M = Counter() counter.increment() // enqueued and serialized by Actor policy // Binding-site override — same class, different policy c2: Counter+R+M+M(MVCC) = Counter() // override to MVCC // Policy + inheritance combined d LiveCounter+M(Actor) : Counter lastUpdated: S
+M on a binding grants mutation rights to +M properties. A -M property is const after initialization — the binding's +M does not override it. The most restrictive wins at each property access.
cfg.host = "x" where host is -M is a type error regardless of whether cfg is +M. The property's declaration wins.
Copy semantics — .c() is shallow by declaration
When you call .c() on a class instance:
-Rproperties (inline) — copied by value. COW applies for mutable ones: the copy shares backing data until the first write forces a real copy.+Rproperties (heap reference) — the reference is copied, not the object. Both the original and the copy point to the same heap object.
The class definition itself declares copy semantics through property modifiers — no separate clone() protocol needed. This is exactly PHP's clone behavior: inline values copy, references share.
// Inline nested structs — -R means value-embedded, copies recursively d Vec2 // small value type, always -R by default x: N y: N d Material+R(RAII) // GPU resource — always lives on heap shader: S f drop(t: Material+R) // called automatically when last ref drops gpu.release(t.shader) d Mesh origin: Vec2 // -R inline: Vec2 embedded, copies by value count: I // -R inline: scalar, copies by value vertices: [Vec2]+R // +R heap array — reference shared on .c() normals: [Vec2]+R // +R heap array — reference shared on .c() material: Material+R // +R heap object — reference shared on .c() a = Mesh{ origin: Vec2{ x: 0.0, y: 0.0 }, count: 3, vertices: [...], normals: [...], material: Material("pbr") } b = a.c() // b.origin → new Vec2 (inline — x and y duplicated) // b.count → 3 (scalar copy) // b.vertices → same heap array as a.vertices (reference shared) // b.normals → same heap array as a.normals (reference shared) // b.material → same Material as a.material (RAII refcount++) b.origin.x = 1.0 // OK — b.origin is its own copy a.origin.x // still 0.0 — unaffected // Want independent vertices? Copy the array explicitly: b.vertices = a.vertices.c() // b now has its own vertex buffer // +R on a local binding: heap-allocated, shareable via +R properties mat: Material+R = Material("wireframe") // heap, refcount=1 c: Mesh+R+M = Mesh(...) c.material = mat // OK: mat is +R — can be shared, refcount→2 // +R cannot reference a plain -R stack var — no refcount, compile error plain: Vec2 = Vec2{ x: 1.0, y: 2.0 } // -R stack c.material = plain // ❌ types differ: +R expected, -R given
Method overrides and explicit parent calls
To override a method, redefine it in the subclass. To call the parent version, use ParentClass.method(args) — t is passed implicitly. There is no super keyword and no auto-super magic.
t present in body → instance method. t absent → +G (static). This applies to overrides too — a static parent method overridden with a static child method just works. If a parent changes a method from static to instance, the subclass breaks at the next compile — surfacing the breaking change immediately, never silently at runtime.
d Bar name: S f __construct(a: I) t.name = a.toString() f greet(): S // instance — t used r => "Hello from " + t.name f version(): S // static — no t r => "Bar v1" d Foo : Bar x: S = "default" f __construct(a: I, b: S) Bar.__construct(a) // explicit — t passed implicitly t.x = b // own init after parent f greet(): S // overrides instance method base = Bar.greet() // call parent — t implicit r => base + ", also " + t.x f version(): S // overrides static — no t here either r => Bar.version() + "-Foo" // Not calling Bar.__construct is valid — deliberate choice // Compiler warns if __construct never calls parent's
Type Hierarchies — U's Enum Replacement
U has no enum keyword. Instead, named subtypes with dot-namespace syntax serve the same purpose — and more, because they participate in the event system, error system, and type dispatch natively.
d Foo.Bar : Foo declares a type Bar namespaced under Foo, inheriting from Foo. Zero-field types are auto-singletons — Color.Red as an expression IS the value, no () needed.
// Define a base type and its variants d Color d Color.Red : Color // zero-field → auto-singleton d Color.Green : Color d Color.Blue : Color // Color.Red IS the value — no () needed bg: Color = Color.Red bg : Color.Red // L true — isinstance bg : Color // L true — base type // Variants can carry data (unlike traditional enums) d Shape d Shape.Circle : Shape { radius: N } d Shape.Rect : Shape { width: N, height: N } d Shape.Triangle : Shape { base: N, height: N } // Dispatch via : type test area = shape : Shape.Circle ? Math.PI * shape.radius ^ 2 ! shape : Shape.Rect ? shape.width * shape.height ! shape.base * shape.height / 2 // Hierarchical namespaces d NetworkError d NetworkError.Transport : NetworkError d NetworkError.Transport.Timeout : NetworkError.Transport d NetworkError.Transport.Refused : NetworkError.Transport d NetworkError.Protocol : NetworkError d NetworkError.Protocol.SSL : NetworkError.Protocol
The pit of success: typed middleware over switch/match
U has no switch or match keyword. This is deliberate. Enumerating cases in a closed dispatch block couples the caller to every variant — adding a new case requires finding and updating every dispatch site. The open alternative is typed handlers:
// ❌ closed dispatch — every new Shape breaks this area = shape : Shape.Circle ? Math.PI * shape.radius ^ 2 ! shape : Shape.Rect ? shape.width * shape.height ! 0.0 // ← new shapes silently return 0 // ✅ open dispatch — new Shape? add one handler, no existing code changes renderer.x((s: Shape.Circle) => drawCircle(s.radius)) renderer.x((s: Shape.Rect) => drawRect(s.width, s.height)) renderer.x((s: Shape.Triangle) => drawTriangle(s.base, s.height)) // add Shape.Hexagon later? one new line, zero regressions // Same pattern already used for errors: e.x((err: NetworkError.Transport.Timeout) => retry()) e.x((err: NetworkError.Protocol.SSL) => alertSecurity()) // errors and enums are the same pattern. one mechanism.
Static fields — +G
+G is for class-level (static) fields — shared across all instances, not per-instance. Separate concern from type hierarchies.
d Config apiUrl: S +G = "https://api.example.com" // static constant timeout: I +G = 30 // static constant calls: I +G+M = 0 // static mutable counter host: S = "localhost" // instance field (no +G)
Interfaces & Abstract Methods — !
Append ! to a class declaration for a pure interface. Append ! to an individual method for an abstract method in a partial abstract class. Interfaces constrain instances — methods in interfaces are never static, never have properties.
d Foo! — pure interface, all methods abstract, no instantiationf method()! — abstract method in a partial classInterface methods are always instance methods —
+G not allowedNo properties in interfaces — only method signatures
Compiler verifies all abstract methods are implemented by concrete subclasses
// Pure interface — all methods abstract d Drawable! f draw(ctx: Context) // abstract — no body f bounds(): Rect // abstract — no body // Partial abstract class — some concrete, some abstract d Animal f speak()! // abstract — subclass must implement f breathe() // concrete — inherited as-is t.lungs.cycle() // Concrete implementation d Circle : Drawable radius: N f draw(ctx: Context) ctx.drawCircle(t.center, t.radius) f bounds(): Rect r => Rect({ x: t.center.x - t.radius, y: t.center.y - t.radius, width: t.radius*2, height: t.radius*2 }) // Type test works for interfaces shape: Drawable = Circle({ radius: 5.0 }) shape : Drawable // L true shape : Circle // L true — concrete type also works // Static interface methods: not allowed — interfaces are for instances // Use type hierarchies for static polymorphism instead: d Shape.Circle : Shape f create(radius: N): Shape.Circle // static — called as Shape.Circle.create(5.0) r => Shape.Circle({ radius })
Untyped parameters — not allowed
Every parameter must have a type annotation. f process(data) is a compile error. No untyped escape hatch — the type system has no any. Use interfaces or class hierarchies for polymorphism, __unserialize for external data.
f good(data: [N32+V]) // ✓ typed // f bad(data) ← ✗ compile error: no type annotation f fetch(url: S, { timeout: I = 30, verbose: L = false }) // { timeout } ← ✗ compile error: missing type in named param
Maps — {K: V}
When the shape of data is known at compile time, use a typed class. When keys are determined at runtime — JSON payloads, plugin config, metadata — use a {K: V} map.
In v1, arrays [T] and maps {K: V} are the only parameterized types. No full generics yet, but these two cover most needs. Maps accept all modifier annotations and have the same iteration methods as arrays. Iteration order is guaranteed to be insertion order — this is a language guarantee, not an implementation detail. Map iteration handlers receive (key, value) pairs.
S, I, N, L) work automatically. For classes, implement f __hash(): I and f __equals(other): L — these make any class usable as a map key. Override both or neither — the compiler enforces this. If you declare {MyClass: V} on a class with __equals but no __hash, it is a type error.
// Map literal — runtime key-value store meta: {S: Any} = { "author": "Alice", "version": 3 } // Any comparable type as key userById: {I: User} = {} // integer keys byPoint: {Point: I} = {} // class key — Point must implement hash() and == // Dynamic access — returns +N (key may not exist) author: S+N = meta["author"] version: I = meta["version"] ?? 1 "author" in meta // L — O(1) membership // Modifiers — same as classes roConfig: {S: S}+R-M = loadConfig() // shared immutable liveState: {S: Any}+R+M+M(MVCC) = {} // shared mutable + MVCC // Class as key — implement hash() and == d Point x: I, y: I f __hash(): I => (t.x * 31 + t.y) * 31 f __equals(other: Point): L => t.x == other.x & t.y == other.y grid: {Point: S} = {} // works because Point has __hash and __equals grid[Point({ x: 0, y: 0 })] = "origin"
Map iteration — same methods as arrays
All map iteration receives (key, val) pairs. Three-signal convention: none = include/continue, false = skip, true = stop.
// .x() — side effects meta.x((key, val) => log("{key}: {val}")) // .filter() — returns new Map strings = meta.filter((key, val) => val : S ? none ! false) // .map() — transform values, keys preserved upper = meta.map((key, val) => val : S ? val.uppercase() ! val) // .find() — returns (K, V) +N hit: (key: S, val: Any)+N = meta.find((key, val) => val == target ? none ! false) // .reduce() — fold total = prices.reduce((acc, key, val) => acc + val, 0.0) // Promise-aware: .all() and .any() work on {K: V +A} maps fetching: {S: Response+A} = endpoints.map((key, url) => a fetch(url)) results: {S: Response} = fetching.all() // await all, same keys preserved first: Response+N+A = fetching.any() // first to resolve
Maps as Sets — {K: L}
A {K: L} map where the value is a boolean sentinel is a Set. The in operator gives O(1) membership. Set operations fall out from .filter().
admins: {S: L} = { "alice": true, "bob": true } "alice" in admins // true — O(1) admins["carol"] = true // add admins["bob"] = none // remove editors: {S: L} = { "bob": true, "carol": true } both = admins.filter((key, _) => key in editors ? none ! false) // intersection only = admins.filter((key, _) => key in editors ? false ! none) // difference all = admins.c(+M).merge(editors) // union // No Set<T> type in v1 — no need for one. // {K: L} maps with the in operator cover all set semantics.
Map iteration — (key, value) pairs, insertion order guaranteed
scores: {S: N} = { "alice": 9.8, "bob": 7.4, "carol": 8.1 } // .x() — iterate (key, value) in insertion order scores.x((score, name) => print(name + ": " + score.toString())) // value first // alice: 9.8 / bob: 7.4 / carol: 8.1 — guaranteed order // .map() — transform values, key passed through grades: {S: S} = scores.map((score, name) => score >= 9.0 ? "A" ! "B") // .filter() — keep entries where predicate holds topScores: {S: N} = scores.filter((score, name) => score >= 9.0 ? none ! false) // .all() / .any() — synchronous predicates allPassed: L = scores.all((score, name) => score >= 5.0) // true anyHonours: L = scores.any((score, name) => score >= 9.5) // false // .reduce() — fold over entries total: N = scores.reduce((acc, score, name) => acc + score, 0.0) // .find() — first matching entry, returns value+N winner: N+N = scores.find((score, name) => score >= 9.0 ? none ! false) // .keys() / .values() / .entries() — explicit projection names: [S] = scores.keys() // [S] in insertion order vals: [N] = scores.values() // [N] in insertion order pairs: [[S, N]] = scores.entries() // [[key, value], ...] in insertion order
{ "a": 1, "b": 2 } always iterates a first, b second — in literals, after insertions, after mutations. The compiler implements maps as ordered hash maps. This guarantee makes map iteration testable and predictable.
Why Symbol, WeakMap, and a separate Map type are unnecessary
| JS concept | Why it exists in JS | U equivalent |
|---|---|---|
| Map | Objects only allow string keys; Map allows any type | {K: V} with any key type — it IS the map |
| WeakMap | Attach metadata without preventing GC collection | ARC: objects have deterministic lifetimes. Weak refs if needed are a modifier, not a separate collection type. |
| Symbol | Unique non-string keys, private properties, protocol hooks | Type system (uniqueness), class visibility (privacy), .x() protocol (iteration hooks) |
| Set | Unique-value collection with O(1) membership | {K: L} map + in operator — same semantics, no separate type |
[T] and {K: V}. These are the only parameterized types — and they compose. [[T]] is a matrix, [[[T]]] a rank-3 tensor, arbitrary rank by nesting. No dependent types, no rank parameters, no new mechanism. [[V32]]+R(GPU) is a GPU matrix; same story for any element type and any location policy.
Magic Methods
Six double-underscore methods form the v1 protocol. The compiler recognises them by name and calls them automatically.
| Method | Signature | Called when | Constraint |
|---|---|---|---|
__construct | f __construct({...}) | Object created via ClassName({...}). If absent, compiler auto-generates one from declared fields. | No auto-super. Call parent explicitly: Bar.__construct(args) — t passed implicitly. |
__hash | (): I | Object used as map key — bucket placement | Must be consistent with __equals: if a.__equals(b) then a.__hash() == b.__hash() |
__equals | (other: T): L | a == b operator; map key collision resolution | Must be consistent with __hash. Override both or neither. |
__serialize | (): S | Object serialised to string (storage, network) | Should round-trip with __unserialize |
__unserialize | (data: S): T | Object reconstructed from string — class-level factory | Defined inside the class; compiler treats it as static. Should round-trip with __serialize. |
__merge | (base: T, theirs: T): T | MVCC conflict resolution — two fibers write same object | base = common ancestor, t = your changes, theirs = other fiber's commit. Without it: last write per subtree wins. +M(CRDT) = MVCC with commutative idempotent __merge. |
__hash nor __equals get structural defaults: all fields compared for equality, hash derived from all fields. This means any class can be used as a map key without writing anything — override only when you need a subset of fields to determine identity.
d User id: I name: S email: S // Identity by id only — name and email changes don't affect map keys f __hash(): I => t.id f __equals(other: User): L => t.id == other.id // Serialization — round-trips through __unserialize f __serialize(): S r => "{t.id}|{t.name}|{t.email}" // Class-level factory — called as User.__unserialize(str) f __unserialize(data: S): User parts = data.split("|") r => User{ id: parts[0].toI(), name: parts[1], email: parts[2] } // Usage userMap: {User: Session} = {} // User as map key — uses __hash and __equals alice = User{ id: 1, name: "Alice", email: "a[at]x.com" } str = alice.__serialize() // "1|Alice|a[at]x.com" back = User.__unserialize(str) // User({ id:1, name:"Alice", ... } alice == back // true — same id, __equals passes // Conflict resolution — called when two fibers write same Config f __merge(base: Config, theirs: Config): Config Config{ host: theirs.host, // theirs wins for host port: t.port, // keep my port flags: t.flags.merge(theirs.flags) // union flags map } // Default: no magic methods needed for simple value types d Color { r: I, g: I, b: I } // structural __hash and __equals auto-generated colorCount: {Color: I} = {} // just works
Null Safety
Non-null is the default. +N explicitly opts into nullability. The compiler never emits a null check for -N values — the type proves it unnecessary.
// -N default: can never be null — no check emitted name: S = "Alice" // -N: compiler skips null check entirely count: I = 42 // +N: may be none — must handle before use user: User+N = findUser(id) // ?? coalesce — provide fallback value display = user?.name ?? "Guest" // S -N (narrowed to non-null) port = config.port ?? 8080 // & guard — execute only if non-null user & sendWelcomeEmail(user) // runs only if user != none // ?. safe chain — none propagates through the whole chain city: S+N = user?.address?.city // +N if any step is none name: S = user?.address?.city ?? "unknown" // -N with fallback // Compiler emits exactly 2 null tests (user, address) // city is -N on User.address, so no test there // Early return on none — clean handler pattern f handleLogin(uid: I): Response+N user = findUser(uid) user ?? r => Response.notFound() // early return if none // user is narrowed to User -N here — no more null checks needed session = createSession(user) r => Response.ok(session.token) // Compile error: cannot dereference +N without handling bad = user.name // ❌ COMPILE ERROR: user is +N — must check first
name.length() where name: S +N is a type error — the compiler requires a null guard before any method call or property access on a +N value.
Conditionals — ?! & | ?? :
No if, no else, no switch, no match. Five operators handle all conditional logic.
| Operator | Semantics | Use case |
|---|---|---|
cond ? a ! b | if cond then a else b — cond must be L | Ternary / if-else. ? = "yes", ! = "not" |
expr : Type | true if expr is-a Type — returns L | Type test, dispatch |
a & b | if a then b — a must be L | Guard: run b only if a is true |
a | b | first truthy value — any type | Fallback chain |
a ?? b | b if a is none, else a — any +N type | Null coalesce |
? and ! are a natural pair. The ternary reads "is it? yes: … not: …". Freeing : makes it available for type tests (expr : Type) and inheritance (d Dog : Animal) — both mean is-a, consistently.
// Syntax rules: ? and ! at condition indent level // Arbitrary spaces after ? or ! to align. Continuations indented. // Inline label = count > 1 ? "items" ! "item" // Multi-line block — last expr in each branch is the value greeting = time < 12 ? name = user.firstName "Good morning, " + name // indented → still in ? branch ! name = user.nickname | user.firstName "Good afternoon, " + name // indented → still in ! branch // Nested status = user != none ? user.active ? "active user" ! "inactive user" ! "no user" // Switch-like: ! at condition level, spaces after ! for alignment grade = score >= 90 ? "A" ! score >= 80 ? "B" ! score >= 70 ? "C" ! "F" // : type test — expr : Type returns B shape : Circle & drawCircle(shape) shape : Rectangle & drawRect(shape) // Type dispatch with ?! — replaces switch/match/instanceof area = shape : Circle ? Math.PI * shape.radius ^ 2 ! shape : Rectangle ? shape.width * shape.height ! 0.0 // & | ?? — short-circuit value operators admin & showAdminPanel() // guard valid & r => compute() // conditional return label = user.nickname | user.firstName | "Anonymous" // fallback port = config.port ?? 8080 // null coalesce
1.
? and ! sit at the same indent level as the condition line.2. Arbitrary spaces after
? or ! before first content — for alignment.3. Continuation lines must be indented (tab) to stay in the branch.
? condition and & left side.
5 ? 2 ! 8 — ERROR: 5 is I, not B.
Convert explicitly: L(expr) or !!(expr).
| and ?? accept any type — they select values, not test conditions.
Iteration — Array Methods
No for, no while. All iteration uses named array methods — all native, all bounded, all sharing the same underlying engine. The three-signal convention applies to any method that searches or filters:
| Return from handler | Meaning |
|---|---|
none (default) | Include this item, continue |
false | Skip this item, continue |
true | Stop here, include this item |
| Method | Returns | Notes |
|---|---|---|
.x(handlers) | — | Each. Passes (value, key) — declare one param to drop the key. none=continue, true=stop chain. |
.filter(pred) | [T] | none=include, false=skip, true=stop-and-include. Like JS filter but with early-exit. |
.map(fn) | [U] | Passes (value, key). Return value is the new element. |
.reduce(fn, init) | U | (acc, item) => newAcc. Standard fold. |
.find(pred) | T +N | Stops at first Non-false return. Returns the item or none. Caller knows what they called. |
.all(pred) | L | Synchronous: true if every element satisfies pred. Short-circuits on first false. |
.any(pred) | L | Synchronous: true if any element satisfies pred. Short-circuits on first true. any(f) = !all(!f) by De Morgan. |
.all() | [T]+A | Async join on [T+A] only. Awaits all concurrently; results in input order. |
.any() | T+N+A | Async race on [T+A] only. Resolves with first completed value or none. |
// .filter() — three signals active = users.filter((user) => user.active ? none ! false) // include if active first10 = items.filter((item) => ( taken = taken + 1 taken <= 10 ? none // include ! true // stop )) // .map() — return value is the new element names = users.map((user) => user.firstName + " " + user.lastName) doubled = nums.map((num) => num * 2) // .reduce() — fold total = orders.reduce((acc, order) => acc + order.amount, 0.0) // .find() — returns T +N, caller knows what they called user: User+N = users.find((user) => user.id == target ? none ! false) user != none & process(user) // or: user ?? defaultUser // .all() — Promise.all: await all +A values, results in input order pending: [S+A] = urls.map((url) => a fetch(url)) // N concurrent fibers pages: [S] = pending.all() // await all, ordered // .any() — Promise.race: returns T +N +A, caller knows winner: S+N+A = pending.any() // first to resolve, or none winner != none & render(winner) // .x() stays for events, errors, and side-effect iteration users.x((user) => log(user.name)) // for-each with side effect e.x(MyLib.networkPolicies) // error handler registration clicks.x((evt) => handleClick(evt)) // event subscription
[S, S +A, S +A] arrays work naturally — regular values pass through instantly, +A values are awaited concurrently. Results always come back in input order. If any +A value rejects, it throws — caught by e.x() handlers. No .catch() needed.
Ranges — .. and ...
Range syntax produces array values directly — no special Range type. [0..10] is an array literal. Arithmetic on it is element-wise, same as any array. The compiler recognizes range-derived arrays in .x() and emits a tight loop without materializing the array.
[a...b] — inclusive both ends (like Ruby ..)[a...b] — exclusive end (like Ruby ...)Arithmetic is element-wise:
[0..4]*2 = [0,2,4,6,8]
// Inclusive — both ends included arr = [1..5] // [1, 2, 3, 4, 5] arr = [5..1] // [5, 4, 3, 2, 1] — start > end counts down // Exclusive end arr = [0...10] // [0, 1, 2, ..., 9] (not 10) arr = [0..10] // [0, 1, 2, ..., 10] (includes 10) // Arithmetic is element-wise — produces new array [0..4]*2 // [0,1,2,3,4]*2 = [0, 2, 4, 6, 8] [4..0]*2 // [4,3,2,1,0]*2 = [8, 6, 4, 2, 0] [0...10]*2 // [0,1,...,9]*2 = [0, 2, 4, ..., 18] // Offset pattern — scalar arithmetic lifts over array (foo - [1..5]*2).x((i, v) => process(v)) // foo-2, foo-4, foo-6, foo-8, foo-10 (base + [0...n]*stride).x((i, v) => arr[v]) // stride pattern, n steps // .x() on range — compiler emits tight loop, no allocation [0...n].x((i, v) => draw(v)) [0...rows].x((row) => // iterate rows [0...cols].x((col) => // iterate cols matrix[row][col] * scale ) ) // Array slicing arr[1..4] // elements 1,2,3,4 — inclusive arr[1...4] // elements 1,2,3 — exclusive end arr[4..1] // reversed slice [4,3,2,1]
.x() is called on a range-derived array, the compiler recognizes the pattern and emits a counter loop — same machine code as hand-written C, no array allocated.Generators — w, y, b, c
The w keyword creates a generator loop. Generators are stackless — they can only yield from the top level, not from nested function calls. (For deep suspension from any call depth, use fibers with a.) w+I declares intentionally infinite — required for infinite generators, or the compiler warns.
// Bounded loop with break w event = nextEvent() event.isDone & b // b = break process(event) // Generator function — yields values lazily f naturals(): I num = 0 w+I // w+I = intentionally infinite, no warning y num // y = yield num = num + 1 // Fibonacci f fibonacci(): I prev = 0 curr = 1 w+I y curr next = prev + curr prev = curr curr = next // Consume a generator with .x() fibonacci().x(n => n > 1000 & b) // stop when > 1000 // continue skips current iteration w line = readLine() line.isEmpty() & c // c = continue, skip blank lines line.startsWith("#") & c // skip comments processLine(line) eof() & b
Error Handling — e
e is dual. At the definition site: e ErrType(...) throws. At the call site: e.x() registers typed handlers — the same .x() subscription used everywhere. Error handlers are typed event listeners.
What .x() accepts
| Form | Behavior |
|---|---|
e.x(handler) | Append one typed function to that type's chain |
e.x(h1, h2, h3) | Append all in order — equivalent to three separate .x() calls |
e.x(policyArray) | Spread an array of typed functions onto the chain in order — array order is defined and preserved |
.x() is array-set-by-type, not push. Early exit (returning true) stops only that specific type's chain — other type chains are independent. Library policies are exported as arrays, not objects — array order is defined, method iteration order on objects is not.
// ── Definition site ─────────────────────────────────────────────────── d NetworkError : BaseError { msg: S, code: I, retryable: L } d TimeoutError : NetworkError { elapsed: I } a f fetch(url: S): S ! NetworkError ! TimeoutError connected | e NetworkError{ msg: "offline", retryable: true } elapsed > limit & e TimeoutError{ elapsed: elapsed } r => body // ── Single and multi-arg ────────────────────────────────────────────── a f run(url: S) e.x(logTimeout, retryOnTimeout) // push both onto TimeoutError chain e.x((err: NetworkError) => err.retryable ? retry(url) ! logAndFail(err.msg)) result = a fetch(url) process(result) // ── Library policy arrays — ordered, exported, composable ──────────── // In MyLib — exported as arrays, NOT objects (object method order is undefined) networkPolicies: [(NetworkError)->()] = [ logToSentry, notifyOncall, retryOnRecoverable // order defined and preserved ] // Call site — array spreads onto chain in order a f run(url: S) e.x(MyLib.networkPolicies) // spread array: all three appended in order e.x(MyLib.networkPolicies, extraHandler) // append more after the array result = a fetch(url) process(result) // ── Pit of success — library symbols ───────────────────────────────── e.x( MyLib.handleNetworkError, Foo.failClosedOnSyntaxError ) result = a fetch(url) // happy path process(result) // ── Early exit is per-type, independent chains ──────────────────────── e.x((err: NetworkError) => { reconnect() | (r => false) }) // false = stop NetworkError chain e.x((err: NetworkError) => logAndFail(err.msg)) // skipped if above returns false e.x((err: TimeoutError) => retry(url)) // TimeoutError chain unaffected // ── The rule: declare what you originate, propagation is inferred ───── // You ORIGINATE this throw → must declare ! NetworkError in your signature a f fetch(url: S): S ! NetworkError ! TimeoutError connected | e NetworkError{ msg: "offline" } // ← originated here elapsed > limit & e TimeoutError{ elapsed } // ← originated here r => body // You PROPAGATE from a callee → inferred automatically, no declaration needed a f run(url: S): S // no ! needed e.x((err: NetworkError) => retry(url)) // handled r => a fetch(url) // TimeoutError propagates — compiler infers it // no ! TimeoutError required in run()'s signature // Optional: explicitly seal your surface — compiler verifies accuracy a f run(url: S): S ! TimeoutError // declares AND verifies: only this escapes // Block-scoped catching: () is your try block result = ( e.x((err: NetworkError) => r => fallback) // only inside this block a fetch(url) )
.x() as every — and any via De Morgan
The same chain model applies to iteration. .x() runs all handlers; returning a truthy value stops the chain early and returns that item. Returning none (the default) continues. Any is the De Morgan inverse: any(f) = !every(!f). See the Fibers section for .all() and .any() on promise arrays.
// every — false stops chain early allPaid = orders.x((order) => order.paid) // false if any not paid noneOverdue = orders.x((order) => !order.overdue) // false if any overdue // any via De Morgan: any(f) = !every(!f) hasAdmin = !users.x((user) => !user.isAdmin) // true if any user is admin anyOverdue = !orders.x((order) => !order.overdue) // true if any order overdue
Fibers, Program-as-Graph & Promise Semantics
The program IS the dependency graph
Every +A value is a node in a dependency graph. Fibers execute when their +A dependencies resolve. The scheduler runs whatever fiber has all inputs ready, suspends fibers that are waiting, and resumes them on resolution. You write ordinary code; +A annotations declare which values cross fiber boundaries.
Rejection throws
When you auto-await a +A value that was rejected, it throws. The exception hits the e.x() handler chain — the same path used for all other errors. There is no separate "rejection handler" or .catch(). One mechanism for all failure paths.
.x() on arrays — Promise.all semantics
.x() on an array of mixed values and +A values is Promise.all-aware. Regular values pass through instantly; +A values are awaited concurrently. Results are returned in input order regardless of resolution order. The return is always [T] +A — always async, even if all inputs are already resolved.
none = continue, truthy = stop. The default return from any handler is none (falsy), meaning "continue". Returning any truthy value — including true — stops the chain. When stopped early, .x() returns T +A (the single value that triggered the stop). When all elements are processed, it returns [T] +A. This convention is uniform across data iteration and e.x() error/event handler chains.
// Start N concurrent fibers — all run in parallel pending: [S+A] = urls.x((url) => a fetch(url)) // all — collect all results in input order (auto-await) pages: [S] = pending.all() // waits for all, returns [S] in order // time = max(fetch times), not sum // any / race — first to resolve wins (returns T +A, not array) first: S+A = pending.any() // stops at first resolved — Promise.race // .all() and .any() are just functions: // .all() = include all, never stop — include all, never stop // .any() = stop at first resolved — stop at first, return it // Custom: stop when result passes a condition bigPage: S+A = pending.x((page) => page.length > 10000 ? page ! none) // returns first page longer than 10k chars, or continues // Start as new fiber — get [S] +A back, caller continues results: [S]+A = a pending.all() // Rejection: if any fetch throws, e.x() handlers fire e.x((err: NetworkError) => logAndFail(err.msg)) pages = pending.all() // any rejection → throws → e.x() above fires // De Morgan — any(f) = !every(!f) still works on plain arrays hasAdmin = !users.x((user) => !user.isAdmin) // true if any is admin anyOverdue = !orders.x((order) => !order.overdue)
Stack preservation
JavaScript async/await loses call frames across await points — the continuation runs in a new microtask with no knowledge of its caller. U fibers are stackful: the full call stack is preserved across suspension. An exception thrown anywhere in a fiber carries the complete trace from main through every intermediate caller.
// Stack frames lost across await async function run(id) { const order = await fetch(id); // frame LOST await save(order); // new stack } // Error in save(): trace shows // save() internals only — run() gone
// Full stack preserved across suspension a f run(id: I) order = a fetch(id) // stack preserved a save(order) // stack preserved // Error in save(): trace shows // save → run → main — all intact
Red-blue freedom
In JavaScript, Rust, and Python, async functions have a different "color" — once a function does anything async, every caller must become async too. U solves this: stackful fibers with +A annotations keep suspension frames minimal, and regular functions call async functions without adopting a different color.
f buildReport(): S // plain f — not a f data: S+A = a fetchData() // starts new fiber r => render(data) // auto-awaits — no color infection // JS: buildReport must be async, every caller must be async, cascade
The a Keyword — Async Done Right
The a keyword is a behavioral capability keyword (not a modifier). It has three syntactic positions and one meaning: engagement with the async domain.
| Position | Syntax | Meaning |
|---|---|---|
| Function declaration | a f fetch() | Behavioral keyword: this function may suspend. NOT a modifier. Like f or d. |
| Call site opt-in | pending: T +A = a f() | Opt into async domain. Produces T +A. Co-requires +A on LHS. Starts new fiber, caller continues. |
| Cooperative yield | a; | Yield to scheduler immediately. Requires a f declaration. |
| Timed yield | a 5 (literal only) | Yield at least 5ms (lower bound). Literal integer only. Requires a f declaration. |
a is a keyword, not a modifier. Modifiers on a declaration describe the return value and parameters only. a f fetch(url: S): S +N — the +N is on the return value, a is on the function keyword.// ── Declaration: behavioral keyword, not a modifier ────── a f lookup(key: S): Config+N // 'a' marks function as suspendable // ── Form 1: Auto-await (default, zero annotation) ──────── cfg = lookup(key) // fiber suspends transparently if needed // same CALL instruction regardless of sync/async // ── Form 2: Async opt-in (a + +A co-required) ──────────── pending: Config+N+A = a lookup(key) // new fiber, caller continues // ── TYPE ERRORS ─────────────────────────────────────────── cfg = a lookup(key) // ❌ 'a' without +A on LHS pending: Config+A = lookup(key) // ❌ +A without 'a' at call site // ── Cooperative yields ──────────────────────────────────── a f heavyWork() data.x((item, index) => process(item) idx % 1000 == 0 & a; // yield every 1000 items ) a f poll() w+I checkAndProcess() a 5 // yield at least 5ms (literal only)
Proxy Policies — +M(policy)
All +R +M objects are proxy-mediated. The +M(policy) modifier declares how writes and reads are handled. It can appear on the class definition as a default, or at the binding site as an override. Multiple concurrent writers are possible — structurally impossible in safe Rust.
| Modifier | Semantics | Cleanup | Best for |
|---|---|---|---|
+R(RAII) | Lifetime policy on +R: drop() fires when last ref drops | Immediate, ref-counted | File handles, GPU resources, DB connections |
+R(Network) | Lifetime policy on +R: object lives remotely, reads/writes are RPC | Remote lifetime | Microservices, distributed objects |
+R(GPU) | Lifetime policy on +R: object lives in GPU device memory | GPU driver | ML weights, tensors, geometry buffers |
+M(Actor) | Write policy on +M: all mutations serialised through message queue | Refcounted | Mutable state with concurrent writers, UI |
+M(MVCC) DEFAULT | Write policy on +M: optimistic versioning — readers never block, writers create new version | Old versions freed when no readers | Config, shared state with rare writes |
+M(CRDT) | Write policy on +M: commutative merge — all writes eventually consistent | Refcounted | Distributed counters, sets, logs |
+M(Mutex) | Write policy on +M: exclusive lock — one writer at a time | Refcounted | Low-level critical sections |
+P on the class definition is the default for all +R +M instances. +P at the binding site overrides it. If neither is specified, the binding site must declare one when using +R +M.
// Class-level default policy d AppState+M(MVCC) data: [S] state: AppState+R+M = AppState() // uses MVCC from class snap = state.c() // instant snapshot, no lock state.update(delta) // serialized write through proxy // Binding-site policy — class has no default, policy declared here inbox: Queue+R+M+M(Actor) = Queue() inbox.push(msg) // enqueued, processed in order votes: GCounter+R+M+M(CRDT) = GCounter() votes.increment(nodeId) // order doesn't matter, same result // RAII — cleanup fires when last reference drops d FileHandle+R(RAII) fd: I f drop(t: FileHandle+R) // called automatically on last-ref-drop os.close(t.fd) // Override class default at binding site c1: Counter+R+M = Counter() // uses class default c2: Counter+R+M+M(MVCC) = Counter() // override
Context-Aware Templates, i18n, and JSON
Template literals are literals
The tag (html, sql, msg) must appear literally at the call site — it cannot be stored in a variable or passed as a parameter. This is what makes compile-time injection safety possible: the compiler sees the tag and applies the correct escaping rules before the program runs. A dynamic tag would mean the escaping decision is a runtime choice, which breaks the guarantee.
tag = html; page = tag`{input}` — the tag must be the literal word html, sql, or msg at the call site, not a variable. The same reason "hello" is a string literal and not a variable named string.
// html — {expr} auto-escaped, XSS structurally impossible page = html`<h1>{title}</h1><p>{userInput}</p>` // both escaped ✅ frag = html`<img src="{avatar?}">` // {expr?} = omit if none raw = html`<div>{{trusted}}</div>` // {{expr}} = raw unsafe ⚠ // sql — params sent separately, SQL injection impossible rows = sql`SELECT * FROM users WHERE id = {uid}` // → sends uid as $1 parameter, never interpolated into the query string // msg — locale keys and placeholders verified at compile time hi = msg`{greeting, name: user.name}` // ✅ key + placeholder matched err = msg`{welcome}` // ❌ compile error: key not in bundle er2 = msg`{greeting}` // ❌ compile error: {name} missing // Tags are literals — cannot be stored or passed tag = html // ❌ compile error: html is not a value f render(tag, data) = tag`{data}` // ❌ compile error: dynamic tags disallowed
JSON with comments
U's JSON literals support /* */ block comments (and // line comments) via a regex-strip pass before parsing. This is the same approach VS Code uses for .json config files. The comments never reach the JSON parser — they are stripped at compile time for inline literals, or at load time for json-tagged strings.
// JSON literals in U support /* */ and // comments config = { /* database */ "host": "localhost", // local dev "port": 5432, /* default postgres port */ "name": "mydb" } // Also works in json`` template literal for loading dynamic content data = json`{rawString}` // strips comments from rawString before parsing
Html or Sql types reject raw S strings — the only way to produce Html is via html`...` which escapes all interpolations.
Arithmetic, Bitwise, and Power Operators
Bounds checks, divide-by-zero checks, and overflow detection are on by default. ! is the universal opt-out suffix. Since & and | are the guard and fallback operators, bitwise operators use the ~ prefix — keeping single-character operators for the more common logical forms.
Operator table
| Operator | Meaning | Notes |
|---|---|---|
+ - * / % | Arithmetic | Safe by default · ! suffix to opt out |
^ | Power / exponentiation | x^2, 2^n, 10^k · ^ reads as superscript in math |
! | Logical NOT (unary) | !valid, !empty |
& | ?? | Guard · fallback · null-coalesce | Short-circuit · see Conditionals |
~& | Bitwise AND | flags ~& mask |
~| | Bitwise OR | a ~| b |
~^ | Bitwise XOR | a ~^ b · ~ prefix = bitwise domain |
~! | Bitwise NOT (unary) | ~!value |
~< ~> | Left / right shift | x ~< 3 · x ~> 1 |
& is guard; ~& is AND-bits. | is fallback; ~| is OR-bits. ! is logical NOT; ~! is bitwise NOT. ^ is power; ~^ is XOR. The ~ prefix is a one-character annotation that shifts the entire symbol into the bitwise domain.
^ as power: C programmers used to ^ meaning XOR will need to adjust. In U, ^ means power and XOR requires ~^. The design is internally consistent — since all bitwise operators carry the ~ prefix, there is no bare bitwise ^ to confuse with. The gain: x^2, 2^n, and 10^k read as they would in a math textbook.
// Arithmetic — safe by default total = big + small // overflow-checked ratio = num / divisor // zero-checked item = arr[index] // bounds-checked total = big +! small // ! = opt out of overflow check item = arr[index!] // ! = opt out of bounds check // Power — ^ is exponentiation area = side ^ 2 // x squared scale = 2 ^ bits // 2^n for bit counts mag = 10 ^ exponent // order of magnitude // Bitwise — all use ~ prefix masked = flags ~& 0xFF // AND bits merged = a ~| b // OR bits toggled = a ~^ b // XOR bits flipped = ~!value // NOT bits (unary) shifted = bits ~< 3 // left shift aligned = bits ~> 2 // right shift // Mix — ~ prefix makes bitwise vs logical unambiguous at a glance valid = (flags ~& MASK) & notExpired // ~& bitwise, & guard
Memory Model — Tiered Allocation
The modifier system gives the allocator perfect information at compile time. Every allocation strategy is determined from the type annotation. No runtime profiling, no GC, no stop-the-world pauses.
| Modifier | Where allocated | ARC | Freed when |
|---|---|---|---|
| -R | Stack frame | none | Scope exit — O(1) stack pointer move |
| +R refcount=1 | Per-fiber nursery (bump ptr) | integer | Nursery reset — O(1) if never shared |
| +R refcount>1 | Main heap (size classes) | integer | Refcount reaches 0 — deterministic |
| +R -M | Immutable pool | integer | Refcount → 0, may be hash-consed |
| +R (cycles) | Heap, candidate list | integer | Background cycle detector — bounded pause |
| +V | GPU device memory | none | Last +V ref drops — DMA dealloc |
atomic_fetch_add, no memory fences, no cache coherence traffic. 10–50× cheaper than Swift or Objective-C ARC.+R object has refcount=1 — it's "genesis" state, effectively still local. The per-fiber nursery allocates with a bump pointer (O(1)). Only when refcount goes above 1 does the object promote to the main heap. Most objects never promote.Copy — .c()
.c() is the only way to create a copy. No implicit copies anywhere. The compiler has a static copy budget per function — the exact number of allocations it can cause.
What .c() copies — determined by the class definition
.c() is a shallow copy by property declaration. Whether a property is duplicated or shared depends on its modifier, declared on the class:
-Rproperties (inline) — value is copied into the new object. For mutable ones, COW applies: the copy shares backing data until the first write.+Rproperties (heap reference) — the reference is copied, not the heap object. Original and copy point to the same object. Exactly like PHP clone: object properties are shared, not duplicated.
The class definition is the copy contract. No separate clone() method or copy protocol. The programmer controls copy depth declaratively by choosing -R vs +R per property.
// Copy vocabulary — only these four forms exist ref = obj // retain: refcount++ only, zero allocation ref = obj.c() // copy: -R props by value, +R props share ref ref = obj.c(+V) // domain copy: DMA to GPU memory ref = obj.c(+R) // promote: -R stack value → +R heap allocation // COW: .c() is lazy for -R +M properties — no allocation until write snap = state.c() // marks COW intent, no allocation yet readFrom(snap) // reads shared data, zero cost snap.field = newVal // NOW allocates + copies, then writes // Copy elision: refcount=1 at .c() call site → zero cost cfg = loadConfig() // +R, refcount=1 (genesis) local = cfg.c() // refcount was 1 → compiler elides entirely
.c() calls determines it.
Zero-Copy Returns
Returning a -R value via r.field = ... writes directly into the caller's pre-allocated stack slot. The callee's frame "popping" doesn't copy anything — it just moves the stack pointer. This is Named Return Value Optimization, but guaranteed by the type system rather than hoped for from the optimizer.
// Callee allocates, caller receives copy Result makeResult() { Result r; // callee's stack r.val = compute(); return r; // COPY to caller }
// Callee writes into caller's slot f makeResult(): Result r.val = compute() // writes to caller's frame // no copy. Ever.
For +R return types, the heap object is allocated once during construction. The return value is an 8-byte pointer. No copy of the object contents occurs at any point.
Defaults — Safe and Fast Require No Annotations
Every default is chosen to be cheapest and safest. You pay for costs by annotating +.
| Context | Default | Meaning |
|---|---|---|
| Function parameters | -R -M -N | Local, immutable, non-null — zero cost |
| Local variables | -R +M -N | Local, mutable (reassignable), non-null |
| Class instances | -R +M -N | Local mutable — can be promoted to +R with .c(+R) |
| Return types | -R +M -N | DPS — zero copy guaranteed |
| Closures | -R | Stack-allocated, doesn't escape scope |
| Fiber frame values | -A | NOT saved at suspension unless annotated +A |
| Integer literals | I | 64-bit signed |
| Decimal literals | N | 64-bit float |
// A function with zero annotations f stats(data: [N]): Stats total = data.x((acc, val) => acc + val, 0.0) mean = total / data.length r => { total, mean } // What you get for free, by default: // ✅ No null dereference (-N default) // ✅ No heap allocation (-R default) // ✅ No ARC cost (-R: no refcount) // ✅ No race condition (-R: no sharing) // ✅ No dangling reference (-R: scope lifetime) // ✅ No iterator invalidation (.x(): safe) // ✅ Zero-copy return (r.field = DPS) // ✅ No async coloring (fibers)
+A as a Pending Type
The +A modifier marks the async domain — values whose lifetime spans fiber suspension boundaries. This has two consequences from the same rule. Both are instances of lazy materialization.
Two Consequences, One Rule
| Position | Meaning | Example |
|---|---|---|
state: Req +Alocal variable |
Value crosses suspension boundary from inside — save to fiber frame at yield | state: Req +A = buildReq() |
pending: S +Apending type |
Value crosses suspension boundary from outside — a fiber computing this result | pending: S +A = a fetch(url) |
a f fetch()declaration |
This function exists in the async domain — may suspend | a f lookup(key: S): Config |
The Two Valid Call Forms — and Nothing Else
a f lookup(key: S): Config+N // declared async — may suspend // FORM 1: Auto-await (default, no annotation needed) cfg = lookup(key) // get Config — transparent suspension if needed // If lookup doesn't suspend: returns Config directly. One branch check. // If lookup suspends: fiber pauses, resumes when done, cfg gets Config. // Call site code: IDENTICAL either way. Zero annotation required. // FORM 2: Async opt-in (explicit, requires +A on left) pending: Config+N+A = a lookup(key) // get pending Config // New fiber starts. Caller continues immediately. pending is a pending Config. // 'a' and +A are co-required — compiler enforces both or neither.
The Co-Requirement — Compiler Enforces Both
// TYPE ERROR — 'a' requires +A on LHS cfg = a lookup(key) // ❌ 'a' produces Config +A but LHS expects Config // "remove 'a' — auto-await does this already" // TYPE ERROR — +A requires 'a' at call site pending: Config+A = lookup(key) // ❌ LHS is Config +A but call site has no 'a' // "add 'a' to opt into async domain" // The error messages write themselves from the rule. // You cannot have one without the other.
Using a Pending Value
pending: Config+N+A = a lookup(key) // Auto-resolve: LHS expects Config — triggers resolution cfg: Config+N = pending // fiber suspends if still pending // Copy: stays pending other: Config+N+A = pending // no resolution, stays +A // Chain: schedule work on resolution — returns S +A rendered: S+A = pending.x(cfg => render(cfg)) // Multiple subscribers — event emitter pattern falls out naturally pending.x(cfg => log(cfg)) pending.x(cfg => cache(cfg)) pending.x(cfg => notify(cfg)) // all three run when pending resolves // No EventEmitter class. No .on() method. Just .x().
result: S = a fetch(url) (a without +A) and pending: S +A = fetch(url) (+A without a) are both type errors. Auto-await in a non-a f function is also a type error.
Lazy Materialization — Zero Cost by Default
U has two cost mechanisms: .c() copying and +A async. Both follow the same rule. Both are zero-cost in the common case. Both provide caller stability without recompilation.
1. Multiplicity — more than one participant needs what the operation produces
2. Declaration — programmer explicitly opted in (
.c(), T +A, or a call)When either is absent, the operation is a no-op at runtime. Present in source. Absent in execution.
.c() — Zero Cost at Genesis
// Condition 1 absent: refcount = 1 (genesis) cfg = loadConfig() // refcount=1 local = cfg.c() // .c() declared... // ...but refcount=1 → same pointer returned // Zero allocation. Zero memcpy. // .c() in source, absent at runtime.
// Both conditions met: refcount > 1 + mutation shared = cfg.c(+R) // refcount now 2 shared.update(newValue) // mutation follows // NOW the copy actually happens. // Cost paid only when genuinely needed.
+A — Zero Cost on Inline Completion
// Condition 1 absent: callee doesn't suspend // (cache hit, sync path, computed value) pending: Config+A = a lookup(key) // fiber runs inline to completion // one branch check: "suspend?" → no // returns Config directly. Zero fiber start.
// Both conditions met: callee suspends + fiber waiting pending: Config+A = a lookup(key) // actual network call inside lookup // new fiber starts, caller continues // Cost paid: fiber start + pending alloc
Caller Stability — Zero Recompilation
When a function gains suspension or sharing, no call site needs to change. This is the practical payoff of lazy materialization.
// ─── PHASE 1: everything sync ───────────────────────────────── f lookup(key: S): Config // sync f handleReq(key: S): S cfg = lookup(key) // [A] CALL → Config immediately r => render(cfg) // ─── PHASE 2: lookup becomes async ──────────────────────────── a f lookup(key: S): Config // added 'a' — ONLY CHANGE // handleReq source is IDENTICAL — zero recompile f handleReq(key: S): S cfg = lookup(key) // [A] same CALL instruction // fiber suspends if lookup suspends // cfg gets Config — caller unchanged r => render(cfg) // ─── PHASE 3: a different caller opts into concurrency ──────── f handleBatch(keys: [S]): [S] // Explicit async: fan out all lookups concurrently jobs: [Config+A] = keys.x(k => a lookup(k)) // Auto-resolve: [Config +A] used as [Config] triggers resolution cfgs: [Config] = jobs r => cfgs.x(cfg => render(cfg)) // Phase 3 also stable: if lookup later becomes sync again, // 'a lookup(k)' produces trivially-resolved Config +A. Still correct.
The Forward Declaration
pending: T +A = a f() when f is currently sync is a forward declaration of intent:"If this function later suspends, treat the result as pending."
Today: new fiber, instant-resolved, near-zero cost.
When
f later becomes a f: same source, same call site, the result is now a pending computation.The code using the result does not change in either case.
Summary Table
| Operation | Zero-cost condition | Cost paid when | Caller changes? |
|---|---|---|---|
.c() | refcount = 1 | refcount > 1 AND mutation | Never |
auto-await result = f() | callee completes inline | callee suspends | Never |
opt-in pending: T+A = a f() | callee sync (instant resolve) | callee actually suspends | Never |
T +A forward decl | callee currently sync | callee later becomes async | Never — that's the point |
Automatic Backpressure in .x() Pipelines
When a .x() lambda returns T +A (via a at the call site), the type signals to the scheduler that this pipeline stage is concurrent. Backpressure is automatic — no semaphore, no library, no configuration.
// Sequential — inline to tight loop by compiler items.x((item) => process(item)) // Async method reference — a before the ref = async dispatch items.x(a Cool.processItem) // backpressure automatic // Async lambda with block body items.x(a (item) => ( result = a fetch(item) // suspends here if slow a db.write(result) // suspends again if needed log(result) )) // fiber suspends at each 'a' call — next item waits — that IS backpressure // no semaphore, no channel, no configuration needed // Concurrent pool — a before the outer handler items.x(a (item) => a fetch(item)) // [T +A] — bounded pool // scheduler fills pool up to limit // pool full: new items wait — backpressure // slot frees: next item starts // Await the whole batch results: [S] = a items.x(item => a fetch(item)) // outer 'a': don't return until all items resolved // Pipeline: stages compose naturally urls .x(url => a fetch(url)) // [S +A] — concurrent, backpressure applied .x(result => parse(result)) // [S] — sequential (no 'a' = auto-await per item) .x(parsed => store(parsed)) // [void] — sequential sink // items can be: array, generator, stream, another .x() chain // backpressure applies uniformly — source type doesn't matter
Default algorithm and middleware override
The default backpressure for async .x() is sequential — one item at a time. The handler suspends at each inner a call; the next item waits until the current fiber completes. Zero configuration needed.
Parallelism is opt-in via a middleware policy prepended to the handler chain. A policy handler returns none (admit), true (drop/stop), or suspends until capacity allows — same three-signal convention as all .x() handlers:
// Default: sequential, automatic backpressure items.x(a processItem) // Opt-in parallel pool — admit up to 10 concurrent items.x(Concurrency.pool(10), a processItem) // Drop when full items.x(Concurrency.dropLatest, a processItem) // Custom policy — same interface as any handler myPolicy = (item) => rateLimit.check(item) ?? r => true | r => none items.x(myPolicy, a processItem)
| Language | Concurrent iteration | Backpressure | How |
|---|---|---|---|
| U | .x(item => a f(item)) | automatic | type system: +A return triggers bounded pool |
| JavaScript | Promise.all(items.map(f)) | none — all start at once | OOM if items is large |
| JavaScript (library) | pLimit(10)(f) | manual semaphore | separate library, no type safety |
| Go | goroutines + WaitGroup | channel buffer | manual chan + wg.Add/Done/Wait |
| Swift | TaskGroup + addTask | structured scope | verbose, requires async context |
| Rust | stream::buffered | explicit size | Stream adaptor, manual buffer |
The Fiber Scheduler
Three Mechanisms That Cause a Fiber to Yield
| Mechanism | Syntax | When | Requires a f? |
|---|---|---|---|
| Auto-await resolution | result = pending | pending not yet resolved | no — automatic |
| Cooperative yield | a; | explicitly, let others run | yes |
| Timed yield | a n (integer) | at least n ms (lower bound) | yes |
a f. Callers then choose: auto-await (inherit the pause) or opt-in with a f() to run it on a new fiber and avoid the pause. The same co-requirement applies — timed yields are just another reason to mark a function a f.a f contains no suspension points. It runs to completion before yielding — provably synchronous, deterministic, bounded. The compiler enforces this: any a expression inside a non-a f function is a type error. No other language can state this guarantee statically.// CPU-intensive loop — sprinkle a; to stay cooperative a f processLargeDataset(data: [Item]) data.x((item, index) => heavyCompute(item) idx % 1000 == 0 & a; // yield every 1000 items ) // Timed yield — be nice for at least 5ms a f pollingLoop() w+I result = checkForUpdates() result & processUpdate(result) a 5 // yield at least 5ms between polls // a n is a lower bound — scheduler may not wake you in exactly n ms // Only hurts your fiber and callers — cannot harm other fibers // Callers defend with: job: T +A = a pollingLoop() — runs on own fiber
The Event Loop — No Macrotask/Microtask Split
// Macrotask queue: ONE per tick // setTimeout, setInterval, I/O callbacks // Microtask queue: ALL drained per tick // Promise.then, await continuations // Microtasks can starve I/O callbacks: async function spin() { while (true) { await Promise.resolve() // microtask // I/O callbacks NEVER run } }
// One run queue. All fibers equal. // No macrotask/microtask distinction. // a; yields fairly — fiber goes to // back of queue, others run first a f spin() w+I a; // fair yield — I/O fibers run
Declarative Toposort — Dependencies from Types
The dependency graph is embedded in the +A types. The scheduler executes in topological order automatically — no manual orchestration.
// Independent computations — scheduler runs concurrently cfg: Config+A = a loadConfig() schema: Schema+A = a loadSchema() // independent of cfg // Dependent — scheduler waits for both before running render page: S+A = a render(cfg, schema) // The scheduler reads the type graph: // page depends on cfg and schema // cfg and schema are independent // → run loadConfig + loadSchema concurrently // → run render when both resolve // Zero manual dependency declaration. // The dependency graph IS the program.
Pub/Sub from the Modifier System
Multiple .x() calls on the same T +A value register subscribers that all run on resolution. This is Node.js EventEmitter — derived from the type system, not a separate API.
const emitter = new EventEmitter(); emitter.on('data', cfg => render(cfg)); emitter.on('data', cfg => cache(cfg)); emitter.on('data', cfg => log(cfg)); emitter.emit('data', loadedCfg); // untyped, memory leak risk // no backpressure, no topology
data: Config+A = a loadConfig() data.x(cfg => render(cfg)) data.x(cfg => cache(cfg)) data.x(cfg => log(cfg)) // type-safe (Config, not any) // backpressure via .x() pool // topological order automatic
| Property | U T +A | Node EventEmitter |
|---|---|---|
| Type safety | full (T is the event type) | none (any) |
| Dependency tracking | compile-time from types | manual |
| Multiple subscribers | multiple .x() calls | .on() API |
| Backpressure | automatic pool limit | none |
| Memory leak risk | no (fiber lifecycle) | yes (forgotten listeners) |
| Ordering guarantee | topological from type graph | emission order |
Modifiers on Functions — The Clean Rule
a f fetch(url: S): S +N:—
a is a keyword (like f or d), not a modifier—
+N is a modifier on the return value— parameter modifiers describe the parameter values
Modifiers on function types as values are fine:
F() +R (escaping closure), F() +N (nullable function reference). These describe the reference, not the function's behavior.
Safety by Construction — Compile Errors
Every major error category below is not caught at runtime, not detected by a linter, not documented in a style guide. Each is a compile-time type error. The program does not build.
Non-Boolean Condition
The condition in ?! and the left side of & must be type L. Integers, strings, and nullable values cannot be used directly as conditions. Convert explicitly with L(expr) or !!(expr).
// ❌ integer as condition 5 ? 2 ! 8 // ERROR: 5 is I, not B a = 5 ? 2 ! 8 // ERROR: assignment returns I count & process() // ERROR: count is I user & show() // ERROR: user is User +N // ✅ explicit condition a == 5 ? 2 ! 8 // OK: == returns B count > 0 & process() // OK user != none & show() // OK B(count) ? "y" ! "n" // OK: cast !!(name) ? "y" ! "n" // OK: double-not // | and ?? are exempt — value selectors label = name | "default" // OK: S, not B
Use-After-Free / Scope Escape
A -R (stack) variable has no refcount and cannot outlive its scope. Assigning it to a +R slot or returning it as +R is a type error.
// ❌ stack var assigned to heap slot local: Vec2 = Vec2{1.0, 2.0} // -R ref: Vec2 +R = local // ERROR: -R → +R // ❌ returning stack var as heap ref f makePoint(): Vec2 +R p: Vec2 = Vec2{1.0, 2.0} // -R r => p // ERROR: -R escapes scope // ✅ explicitly promote to heap r => pt.c(+R) // OK: copies to heap first
Null Dereference
-N is the default. Any use of a +N value without a null guard is a type error. The compiler tracks nullability through every binding.
// ❌ accessing +N without check name: S +N = query() len = name.length() // ERROR: name is +N // ✅ guard before use name != none & len = name.length() name?.length() // OK: optional chain display = name ?? "—" // OK: null coalesce // ❌ returning +N where -N expected f getUser(): User r => db.find(id) // ERROR: db.find returns User +N f getUser(): User +N // ✅ declare it nullable
Data Race
+R +M without a +P policy is a type error. Every shared mutable object must declare how concurrent writes are mediated.
// ❌ shared mutable without policy state: Config +R +M = Config() // ERROR: +R +M requires +P policy // ✅ declare the policy state: Config +R +M +M(MVCC) = Config() state: Config +R +M +M(Actor) = Config() // ❌ two +M refs to same object a: Vec2 +R +M = Vec2() b: Vec2 +R +M = a // ERROR: +M alias without policy // ✅ policy handles concurrent access a: Ctr +R +M +M(MVCC) = Ctr() b: Ctr +R = a // OK: b is +R -M (read only)
Async Violations
a at a call site and +A on the LHS are co-required. Auto-await in a non-a f function is also a type error.
// ❌ a without +A on LHS result: S = a fetch(url) // ERROR: a needs +A // ❌ +A without a at call site pending: S +A = fetch(url) // ERROR: +A needs a // ✅ both together pending: S +A = a fetch(url) // OK // ❌ auto-await in non-a f function f sync() result = fetch(url) // ERROR: fetch is a f, // sync() can't suspend // ✅ declare the function suspendable a f sync() // or: use a fetch() for new fiber
Const Property Mutation
-M on a property is a const declaration. No amount of +M on the enclosing binding overrides it. Mutation requires +M at every step of the access chain.
// ❌ mutating -M property d Config host: S // -M (default) — const port: I +M // explicitly mutable cfg: Config +R +M = Config() cfg.host = "x" // ERROR: host is -M // binding's +M does not override cfg.port = 8080 // ✅ port is +M // ❌ writing through immutable binding pt: Vec2 = Vec2() // -M binding (default) x.y = 1.0 // ERROR: x is -M
Escaping Closure Capturing -R
An escaping closure (+F +R) may outlive the current scope. It cannot capture -R stack variables — those will be gone when the closure runs.
// ❌ escaping closure captures stack var f setup() msg: S = "hello" // -R stack cb: (->S) +F +R = () => console.log(msg) // ERROR: cb is +F +R, // msg is -R — will escape // ✅ non-escaping: must be called within scope cb: (->S) +F -R = () => console.log(msg) // OK: -R closure, in-scope only // ✅ or promote msg to heap msg: S +R = "hello".c(+R) cb: (->S) +F +R = () => console.log(msg)
Injection Attack
Functions expecting Html or Sql types reject raw S strings. The only way to produce Html is via html`...` which escapes all interpolations at compile time.
// ❌ raw string where Html expected f render(page: Html) ... content: S = "<h1>" + input + "</h1>" render(content) // ERROR: S is not Html // ✅ html template: input is escaped content = html`<h1>{input}</h1>` // type: Html render(content) // OK // ❌ dynamic template tag tag = html page = tag`{input}` // ERROR: tag must be literal
Implicit Copy / Surprise Allocation
There are no implicit copies. Assignment retains (refcount++). Only .c() copies. The compiler has a static copy budget per function.
// ❌ no hidden copies anywhere a: [I] +R = [1, 2, 3] b = a // retain: refcount++, no copy b.append(4) // ERROR: b is not +M // (and mutation would affect a) // ✅ explicit copy when you need independence b = a.c() // explicit copy, now independent b +M .append(4) // OK: b is its own array // ❌ function with unknown copy count // Every .c() is visible — static copy budget // is proven at compile time
Summary — Error Categories Eliminated
| Error | How U prevents it | Languages where it's runtime |
|---|---|---|
| Unhandled error type | Declared ! ErrType errors checked for exhaustive handling at call site | All languages (runtime) |
| Non-boolean condition | ?! condition and & require L; 5 ? 2 ! 8 is a type error | C, JS, Python, Ruby |
| Use-after-free | -R cannot be assigned to +R — type error | C, C++, Zig (manual) |
| Null dereference | -N default — +N access without guard is type error | C, Java, JS, Go, Swift (partial) |
| Data race | +R +M defaults to +M(MVCC) — explicit unsafe sharing impossible | Go (race detector), C, C++ |
| Async cascade / coloring | a/+A co-requirement — mismatch is type error | JS, Swift, Python, Rust async |
| Use-after-await | +A annotation on locals — missing it is type error | JS (closure capture bugs) |
| Const mutation | -M property — assignment is type error regardless of binding | C++ (UB), Java (partial), JS |
| Closure scope escape | +F +R cannot capture -R — type error | C++ (UB), Swift (partial) |
| XSS injection | Raw S ≠ Html — type error at function boundary | All languages without template types |
| SQL injection | Raw S ≠ Sql — type error at function boundary | All languages without typed queries |
| Surprise allocation | No implicit copies — static copy budget proven per function | C++, Rust (some cases), Swift |
| i18n missing keys | msg`{key}` — missing locale key is compile error | All languages (runtime crash) |
Access Policies — +P()
Every +R +M binding requires a +M(Policy) declaration. Write policies go on +M (+M(Actor), +M(MVCC), etc.) and govern how concurrent writes are mediated. Lifetime/cleanup policies go on +R (+R(RAII)) and fire when the last reference drops. GC is one policy among many — and not the default. The default for +R is ARC without atomics (single-threaded fiber scheduler means no cross-thread refcount races).
| Policy | Semantics | Cleanup | Best for |
|---|---|---|---|
+R(RAII) | drop() fires when last ref drops — deterministic | Immediate, ref-counted | File handles, GPU resources, DB connections |
+M(MVCC) DEFAULT | Optimistic: readers never block, writers get a new version; conflicts retry | Old versions GC'd when no readers hold them | Config, shared state with rare writes |
+M(CRDT) | Commutative merge: all writes eventually consistent, no conflicts | Refcounted | Distributed counters, sets, logs |
+M(Actor) | Serialized message queue: all access goes through the actor's inbox | Refcounted | Mutable state with concurrent writers, UI components |
+M(Mutex) | Exclusive lock: one writer at a time, readers block | Refcounted | Low-level critical sections |
+R(Network) | Remote proxy: reads/writes are serialized RPC calls | Remote lifetime | Microservices, distributed objects |
// RAII: drop() fires deterministically on last ref d DbConn+R(RAII) handle: I f drop(conn: DbConn+R) => db.close(conn.handle) f query(sql: S): S conn: DbConn+R = DbConn.open() // refcount=1 result = conn.exec(sql) r => result // conn refcount→0: drop() fires, connection closed // No finally, no try-with-resources, no defer // MVCC: readers never block, writers get a new version config: AppConfig+R+M(MVCC) = AppConfig.load() config.reload() // new version; existing readers see old version until done // Actor: all access serialized through message queue d Counter+M(Actor) count: I+M = 0 f increment() => t.count = t.count + 1 f get(): I => r => t.count // Concurrent callers are queued — no data race, no mutex annotation
Comparison: how other languages manage state lifetime
| Language | Default | Deterministic cleanup? | Shared mutable | Notes |
|---|---|---|---|---|
| Java | GC (non-deterministic) | No — finalize() deprecated | synchronized, volatile | try-with-resources for manual RAII. GC pauses unpredictable. |
| C++ | Manual + RAII pattern | Yes — destructors | std::mutex, std::atomic | shared_ptr = ARC but with atomic refcount overhead. Easy to misuse raw pointers. |
| Go | GC | No — use defer | Channels, sync.Mutex | defer is explicit and forgettable. No deterministic cleanup. |
| Rust | Ownership + Drop | Yes — ownership enforces it | Arc<Mutex<T>> | Deterministic, zero-overhead. Borrow checker annotation burden. No MVCC/CRDT out of box. |
| JavaScript | GC | No | none — single thread | No deterministic cleanup. WeakRef / FinalizationRegistry best-effort only. |
| U | -R stack (free), +R ARC without atomics | Yes — +R(RAII) on last ref drop | +M(Actor|MVCC|CRDT|Mutex) | Policy declared at binding site. GC available as a policy but not the default. Single-threaded fiber scheduler means ARC needs no atomic operations. |
+R +M without an explicit write policy is +M(MVCC). Readers never block. No deadlocks. Write conflicts retry automatically. When you have a measured reason to trade correctness for throughput: +M(Actor) for serialized writes, +M(Mutex) for raw lock performance, +M(CRDT) for eventual consistency. The same direction as Rust's safety model — safe by default, opt into unsafe when you need to.
-R) is zero cost — they disappear at scope exit. The default for heap values (+R) is ARC — deterministic, immediate cleanup, no GC pauses. For cases where you genuinely want GC semantics (long-lived object graphs with complex reachability), +R(GC) is available. You opt into the tradeoff explicitly rather than having it imposed on everything.
MVCC — Default Write Policy
+R +M without an explicit write policy defaults to +M(MVCC). You never write it — it's just what happens. Override to a cheaper policy when you have profiled a reason.
| Semantics | |
|---|---|
| Readers | Never block. Each reader sees a consistent snapshot at the moment it starts reading. |
| Writers | Optimistic. Write completes; if another fiber modified the same object between your read and write, your write retries automatically. |
| Atomicity unit | The +R +M(MVCC) object plus all its inline (-R) properties and inline maps. They change as one version. +R properties inside have their own separate versioning. |
| Cross-object transactions | Not in v1. If A and B must change together, make them fields of one object. |
// +R +M defaults to MVCC — no annotation needed config: Config+R+M = Config.load() d Config host: S // inline -R — atomic with Config port: I+M // inline -R — atomic with Config flags: {S: L} // inline map — atomic with Config cache: Cache+R(RAII) // separate heap object — its own versioning // Writing host + port + flags atomically — one version, one commit config.host = "newhost" config.port = 9090 config.flags["debug"] = true // All three committed as one unit — other fibers see old or new, never partial
The << patch operator
The atomic write primitive. obj << { field: newVal } is one MVCC version swap — recursively patches inline (-R) fields, stops at +R boundaries (those are separate objects). For large arrays and maps, the runtime uses path-copying persistent data structures: O(log n) writes, structural sharing, disjoint patches never conflict.
// Atomic multi-field patch — one MVCC version swap config << { host: "newhost", port: 9090 } // atomic, retries on conflict // Nested inline — recursively patches -R fields server << { address: { host: "new" }, port: 443 } // address.scheme unchanged // Array element patch — O(log n), structural sharing items << { [500]: updatedItem } // path-copies only the path to index 500 // Two concurrent fibers — no conflict if different indices // Fiber A: items << { [500]: valA } ✅ different subtrees // Fiber B: items << { [700]: valB } ✅ both commit // On -R local: same syntax, no MVCC overhead (compiler knows) localConfig << { port: 9090 } // plain field update, -R = no versioning
Exception handling and rollback
The fiber's uncommitted write-set is rolled back or committed based on how its exception handler responds. No begin/commit/rollback keywords.
e.x() handler returns | Write-set | Fiber |
|---|---|---|
true | Committed — handler affirmed the writes are valid | Continues |
none or false | Rolled back — silence means unhandled, fail closed | Exception propagates |
| Uncaught exception | Always rolled back | Fiber exits |
e.x((err: ValidationError) => ( log(err.msg) r => true // handled — writes committed, fiber continues )) e.x((err: CorruptStateError) => ( alert(err.msg) // returns none — unhandled, writes rolled back, propagates up )) // Fail closed: forgetting to return true = rollback, not silent commit // You must consciously affirm the write-set is valid
+M(Actor) for serialized writes with lower memory overhead, +M(Mutex) for raw lock performance, +M(CRDT) for eventual consistency. The default protects you; the overrides let you trade correctness guarantees for throughput.
Exceptions, RAII & Null — U vs C++, Java, Rust, Go
Exception handling
| Language | Mechanism | Typed? | Exhaustiveness | Happy path noise |
|---|---|---|---|---|
| C++ | try/catch — throw anything, even ints | No | none | High — try/catch blocks everywhere |
| Java | Checked + unchecked. throws Exception on everything | Partially | Checked only — widely bypassed | High — try/catch/finally verbosity |
| Python | try/except/finally — any object throwable | No | none | High |
| Go | Return (T, error) — no exceptions | Yes | Ignored silently if you forget to check | High — if err != nil everywhere |
| Rust | Result<T,E> + ? operator — no exceptions | Yes | Compiler enforces handling | Medium — ? at every fallible call |
| JavaScript | try/catch/finally — untyped, Promise.catch async | No | none | High + async split |
| U | e.x() typed handlers, object interfaces, library policies | Yes | Compiler checks ! Type vs e.x() registrations | Zero — handlers declared once, happy path clean |
throws Exception everywhere, defeating the purpose. U solves this with inheritance: ! NetworkError covers TimeoutError : NetworkError and every future subtype. One declaration covers the whole family.
Policy arrays vs try/catch — side by side
The same error handling scenario in Java, C++, and U. The Java and C++ versions are not pathological — they are idiomatic. The noise is intrinsic to the mechanism.
// Every caller must list all thrown types // or add throws Exception — defeating the purpose public Response fetch(String url) throws NetworkException, TimeoutException, SSLException { // ... } try { var result = fetch(url); // happy path process(result); // buried under catch blocks } catch (NetworkException e) { logger.warn(e.getMessage()); retry(); } catch (TimeoutException e) { backoff(e.getDelay()); } catch (SSLException e) { alertSecurity(e); } finally { cleanup(); } // Reuse? Copy-paste. No policy objects.
// Untyped — anything throwable // No exhaustiveness checking Response fetch(std::string url); // (what does it throw? read the docs, maybe) try { auto result = fetch(url); process(result); } catch (const NetworkError& err) { logger.warn(err.what()); retry(); } catch (const TimeoutError& err) { backoff(err.elapsed); } catch (...) { // silently swallows anything else } // Stack unwinding fires on every throw // Reuse? Inline only. No composable policies.
// Policies are typed arrays — defined once, reused everywhere networkPolicies: [(NetworkError)->()] = [ logToSentry, // ordered, defined by library notifyOncall, retryOnRecoverable ] // Every call site — one line, happy path clean a f run(url: S) e.x(MyLib.networkPolicies) // spread array onto chain e.x(MyLib.sslPolicies) // multiple arrays composable // compiler: all ! NetworkError ! SSLError covered ✅ result = a fetch(url) // happy path reads first, clean process(result) // Inheritance: ! NetworkError covers TimeoutError : NetworkError // No need to list every subtype — the Java checked-exception trap avoided // Zero-cost happy path — handler tables built statically, no stack unwinding
- Define handlers once in a library, use at 100 call sites —
e.x(MyLib.networkPolicies) - Compiler verifies all declared
! Typeerrors are covered — no missed cases - Early-exit chain: one handler returning
falsestops that type's chain, others unaffected - Happy path appears first and reads clean — error handling is a preamble, not a wrapper
- Inheritance means
! NetworkErrorcovers all subtypes — no Java-style subtype explosion - Static dispatch tables — zero cost when no exception is thrown, no stack unwinding on throw
RAII — resource cleanup
| Language | Mechanism | Automatic? | Notes |
|---|---|---|---|
| C++ | Destructors on stack objects. Smart pointers (unique_ptr, shared_ptr) | Yes | RAII is a pattern — not enforced. Easy to misuse raw pointers. shared_ptr has atomic refcount overhead. |
| Java / Python / JS | GC — no deterministic cleanup. try-with-resources / with / using as workarounds | No | Cleanup is non-deterministic. File handles, DB connections left open until GC decides to run. |
| Rust | Drop trait. Ownership ensures exactly-once drop. No GC. | Yes | Deterministic, zero overhead. But borrow checker annotation burden. No shared ownership without Arc<Mutex<T>>. |
| Go | defer — explicit, not automatic | No | You must remember to write defer file.Close(). Forgotten defers = resource leaks. |
| U | +R(RAII) on class — drop() fires when last reference drops | Yes | ARC without atomics (single-threaded fiber scheduler). Deterministic. No borrow checker. Works with shared +R refs — drops when refcount hits zero. |
// +R(RAII): drop() called automatically when last +R ref drops d FileHandle+R(RAII) fd: I f drop(t: FileHandle+R) // compiler calls this on last-ref-drop os.close(t.fd) // No defer, no try-with-resources, no explicit close() f readConfig(): S fh: FileHandle+R = open("/etc/config") // refcount=1 data = fh.read() r => data // fh refcount→0 here: drop() fires, fd closed // vs C++: shared_ptr uses atomic refcount (expensive cross-thread) // U: ARC is plain integer arithmetic — no atomics (single-threaded fibers)
Null safety
| Language | Null representation | Null dereference | Default |
|---|---|---|---|
| C / C++ | Null pointer (nullptr) | Undefined behavior — crash or worse | Nullable by default |
| Java | null reference | NullPointerException at runtime | Nullable by default |
| JavaScript | null and undefined | TypeError at runtime | Nullable by default |
| Swift | Optional<T> — must unwrap | Compile error (if you use ! force-unwrap: crash) | Non-null default |
| Kotlin | T? nullable type | Compile error | Non-null default |
| Rust | Option<T> — must match/unwrap | Compile error | Non-null default |
| Go | Nil pointers, nil interfaces | Runtime panic | Nil by default |
| U | T +N — explicit nullable annotation | Compile error — +N value requires guard before access | -N by default — non-null without annotation |
if let, ?.let). Rust requires pattern matching. U uses name != none & use(name) or name ?? fallback — the same operators used for every other conditional. No special null-unwrapping syntax to learn.
Async & Concurrency: U vs Go, JavaScript, Swift+GCD
U vs JavaScript — Structure vs Convention
JS async/await unwinds the entire call stack at each await. Every local variable surviving the suspension is serialized to a heap-allocated Promise closure. This is why async infects callers — the return type changes from T to Promise<T>.
// Every await: full stack unwind to event loop // Local state serialized to heap Promise closure // async infects every caller in the chain async function main() { await processAll(items) // infected } async function processAll(list) { for (const item of list) { await fetch(item) // infected } } // Two queues: macrotask (1 per tick) + // microtask (ALL drained per tick) // Microtasks can STARVE I/O callbacks
// Auto-await: fiber stack stays in memory // No serialization. No heap per await. // No annotation on main() — no coloring f main() processAll(items) // plain call f processAll(list: [Item]) list.x(item => result = fetch(item) // auto-await store(result) ) // One scheduler. No queue distinction. // I/O never starved.
| Property | U | JavaScript |
|---|---|---|
| Await syntax | none (auto-await default) | await everywhere |
| Async opt-in | a f() → T +A | return Promise, await caller |
| Heap per await | no — fiber stack preserved | yes — Promise closure |
| Coloring | solved | present |
| Queue starvation | impossible | microtasks starve I/O |
| Backpressure | automatic (.x(k => a f(k))) | library only (p-limit) |
| Generator yield depth | any depth (stackful fibers) | top-level only (stackless) |
U vs Go — Same Ergonomics, Better Guarantees
Go is the closest language to U's concurrency ergonomics. Goroutines solve coloring — any function can block, no annotation needed. The differences are frame size, the absence of a pending type, and safety.
// Fan-out/fan-in requires ceremony var wg sync.WaitGroup results := make([]Config, len(keys)) for i, key := range keys { wg.Add(1) go func(i int, key string) { defer wg.Done() results[i] = lookup(key) // full stack saved }(i, key) // subtle closure bug risk } wg.Wait() // goroutine saves ENTIRE stack // no equivalent of +A to minimize // nil pointers: runtime panics
// Fan-out/fan-in — two lines jobs: [Config+A] = keys.x(k => a lookup(k)) cfgs: [Config] = jobs // auto-resolve // Fiber frame = only +A values saved // (not entire stack) // -N default: null = compile error // No WaitGroup. No closure bug. // No pre-allocated result slice.
| Property | U | Go |
|---|---|---|
| Coloring | solved | solved (goroutines) |
| Frame at suspension | only +A values | full goroutine stack |
| Pending type | T +A | none (channels/WaitGroup) |
| Fan-out/fan-in | .x(k => a f(k)) | WaitGroup + goroutines |
| Null safety | -N default (type error) | nil panics at runtime |
| Injection safety | type error | none |
| GC | none (ARC) | GC pauses |
U vs Swift + GCD — Annotations vs Structure
Swift evolved from GCD completion handlers, to Combine, to async/await (5.5+). Each model accumulated annotations. U encodes the same constraints structurally.
// Actor: new keyword, new rules actor Counter { var value = 0 func increment() { value += 1 } } await counter.increment() // infects callers // @escaping: separate annotation func on(handler: @escaping () -> Void) { } // TaskGroup: verbose structured concurrency await withTaskGroup(of: Config.self) { group in for key in keys { group.addTask { await lookup(key) } } } // 'in' keyword: 4 different meanings in Swift
// Actor = class with proxy policy d Counter +M(Actor) value: I f increment(c: Counter+R+M) t.value = t.value + 1 counter.increment() // no await needed // @escaping = +R on closure f on(handler: F()+R) { } // TaskGroup = .x() with 'a' cfgs = a keys.x(key => a lookup(key)) // 'in' keyword: zero uses in U
| Property | U | Swift + GCD |
|---|---|---|
| Coloring | solved | present (Swift 5.5+) |
| Escaping closures | +R modifier | @escaping annotation |
| Actor model | proxy policy on class | actor keyword + 3 annotations |
| Concurrent iteration | .x(k => a f(k)) | withTaskGroup { group in ... } |
| Keyword reuse | zero | in: 4 different meanings |
| GC | none | weak/unowned GC cycles |
Ownership & Memory: U vs Rust and Zig
U vs Rust — Modifier Algebra vs Borrow Checker
Rust's borrow checker statically proves no aliased mutation exists. U routes all mutation through a proxy with a declared policy. The outcomes are similar — memory safety, race freedom — but the mechanisms and ergonomics differ significantly.
// Shared mutable: Arc> use std::sync::{Arc, Mutex}; let state = Arc::new(Mutex::new(Config::new())); // Clone Arc for every thread that needs it let state2 = Arc::clone(&state); thread::spawn(move || { let mut s = state2.lock().unwrap(); s.update(delta); }); // Single &mut: one writer at a time // No MVCC, no CRDT built in // Async adds coloring (async fn type) // Copy elision: optimizer heuristic
// Shared mutable: +R +M with policy state: Config+R+M = Config() +M(MVCC) // MVCC: readers never block snap = state.c() // instant snapshot state.update(delta) // serialized write // CRDT: commutative — any order votes: GCounter+R+M = GCounter() +M(CRDT) votes.inc(nodeId) // concurrent safe // No async coloring // .c() elision: compiler-guaranteed
-R annotation encodes the same fact: the programmer states it, the compiler reads it. No analysis needed.Arc<Mutex<T>> encodes: heap (Arc), shared (Arc), mutable (Mutex). U writes: T +R +M +M(Mutex). Same semantics, three modifiers from the standard algebra. Change Mutex to MVCC for non-blocking reads. Change to CRDT for commutative writes. Rust has no equivalent mechanism — each requires a different library type.| Property | U | Rust |
|---|---|---|
| Memory safety | modifier algebra (annotation) | borrow checker (analysis) |
| Aliased mutation | permitted via proxy policy | forbidden (&mut exclusive) |
| Multiple writers | MVCC, CRDT policies | impossible in safe Rust |
| Shared mutable | T +R +M +M(X) | Arc<Mutex<T>> |
| Null safety | -N default (type error) | Option<T> (unwrapping) |
| Async coloring | solved | present (async fn type) |
| Caller stability | zero recompile when callee adds async | rewrite all callers |
| Copy elision | compiler-guaranteed (genesis) | optimizer heuristic (RVO) |
| GPU domain | +V modifier, first-class | unsafe (wgpu, cuda-rs) |
| Annotation burden | 3 modifiers + domains | lifetimes, Pin, Arc/Rc/RefCell |
U vs Zig — Modifier as Allocator, Fiber as Frame
Zig makes allocation explicit via allocator parameters: every allocating function takes an Allocator argument. U encodes the same information in the modifier: -R = stack (no allocator needed), +R = heap (runtime allocator). Same visibility, different mechanism.
// Every allocating function takes allocator // Adding allocation deep in chain forces // adding allocator param to every caller fn process(ally: Allocator, data: []T) ![]T { const result = try ally.alloc(T, data.len); defer ally.free(result); // ... } // Async: stackless frame-based // coloring present (async fn) // No +A equivalent — no lazy await
// Allocation in the type, not the signature f process(data: [T]): [T]+R // +R on return = heap allocated // callers see T +R — no param change r => transform(data) // Async: coloring solved // +A = lazy pending type // T +A forward decl: caller stable
Allocator parameter to every intermediate function — a form of the coloring problem for allocators. U's +R modifier is on the value's type, not the function's parameter list. Callers see a different return type (T +R) but need no new parameter.| Property | U | Zig |
|---|---|---|
| Allocation strategy | +R/-R modifier on value | explicit allocator parameter |
| Null safety | -N default (type error) | explicit ?T optional |
| Async coloring | solved | present |
| Pending type | T +A | none |
| Error handling | e propagates up fiber | try at every call site |
| Copy semantics | .c() explicit, genesis elision | manual, explicit |
| GPU | +V modifier | none |
| Injection safety | type error (templates) | none |
U vs Swift — Explicit Conventions vs Structural Encoding
Swift is the closest language to U's goals: memory safety without GC, null safety, value/reference distinction, and a modern concurrency model. The differences reveal a consistent pattern: Swift uses convention and annotation; U uses structure and type.
@escaping vs +R
Swift requires @escaping on closures that outlive their calling scope — they're heap-allocated and may be called after the function returns. U encodes this as +R on the closure type.
// Must mark @escaping manually // Forgetting it is a compile error // No other type information conveyed func onEvent(handler: @escaping () -> Void) { listeners.append(handler) // heap allocation here } // Non-escaping: stack-allocated, cannot outlive call func transform(fn: (Int) -> Int) -> Int { return fn(42) // fn is -escaping by default }
// +R: heap-allocated, may outlive call // The same modifier system as everything else f onEvent(handler: F()+R) listeners.append(handler) // heap: +R tells you // -R: stack-allocated, default f transform(fn: F(I):I): I r => fn(42) // -R default: compiler knows
Swift's in Keyword — One Word, Four Jobs
Swift reuses in in four distinct syntactic contexts. U has zero context-dependent keyword reuse.
| Swift context | Swift syntax | U equivalent |
|---|---|---|
| Closure body separator | { (x: Int) in x + 1 } | x => x + 1 |
| For-in loop | for item in items { ... } | items.x(item => ...) |
| Collection iteration | for (i, v) in items.enumerated() | items.x((item, idx) => ...) |
| Range loop | for i in 0..<10 { ... } | (0..10).x(i => ...) |
Swift Actors vs U Proxy Policies
// New keyword, new type, new rules actor Counter { var value = 0 func increment() { value += 1 } // Callers MUST use await — coloring! } await counter.increment() // nonisolated = not actor-protected // @MainActor = global actor // @Sendable = can cross actor boundary // Three new annotations to learn
// No new keyword — just a class with policy d Counter +M(Actor) value: I f increment(self: Counter+R+M) t.value = t.value + 1 // Caller: no 'a' needed — fiber handles it counter.increment() // Same +R +M pattern as MVCC, CRDT, Mutex // One concept, four policies, zero new keywords
Swift async/await — Same Coloring Problem
// Swift: async infects callers — coloring present // func fetchData() async throws -> Data { ... } // let data = try await fetchData() // caller must be async // — every function in the chain must be marked async // U: no coloring — any function can call any function a fetchData(): S+N // only fetchData is marked 'a' f main() // NOT marked 'a' — no annotation needed data = a fetchData() // 'a' is at the call site, not on main() // Swift: withTaskGroup for concurrent iteration (verbose) // await withTaskGroup(of: Data.self) { group in // for url in urls { group.addTask { await fetch(url) } } // } // U: .x() with +A return — automatic, zero ceremony results = a urls.x(url => fetch(url)) // done
Full Comparison Table — U vs Swift, Rust, Go, JS, Zig, C++
| Property | U | Swift | Rust | Go | JS | Zig |
|---|---|---|---|---|---|---|
| Memory | modifier algebra | ARC+GC | borrow checker | GC | GC | manual |
| Null safety | -N default (type err) | Optional<T> | Option<T> | nil panic | undefined | ?T explicit |
| Data races | impossible (single thread) | actor isolation | type error | race detector | impossible | no races |
| Async coloring | solved — fibers | present | present | solved | present | present |
| Pending type | T +A (built-in) | none | Future<T> | none | Promise<T> | none |
| Auto backpressure | yes — type-driven | no | no | no | no | no |
| Escaping closures | +R modifier | @escaping | lifetime | GC | GC | manual |
| Actor model | proxy policy | actor keyword | library | goroutine+chan | none | none |
| Concurrent iter | .x() + backpressure | TaskGroup | Stream::buffered | goroutine+wg | Promise.all | manual |
| Injection safety | type error | none | library | partial | none | none |
| i18n correctness | compile-time | runtime | runtime | runtime | runtime | runtime |
| Keyword reuse | zero (1 meaning each) | in: 4 meanings | minimal | minimal | this: context | minimal |
| GPU domain | +V modifier | Metal only | unsafe wgpu | none | WebGPU | none |
| GC pauses | none (ARC) | weak/unowned GC | none | GC | GC | none |
| Keyword count | 10 (1 letter each) | ~80+ | ~50+ | ~25 | ~60+ | ~30 |
U vs Rust, Go, Zig, JavaScript
U occupies a previously unoccupied intersection: Go's concurrency ergonomics, Rust's safety, C's performance, and compile-time injection and i18n safety no existing language provides.
| Property | U | Rust | Go | Zig | JavaScript |
|---|---|---|---|---|---|
| Memory safety | modifier algebra | borrow checker | GC | manual+comptime | GC |
| Null safety | -N default (type error) | Option<T> | nil panics | explicit optional | undefined/null |
| Data races | impossible (single fiber thread) | type error | race detector | no races | impossible (single thread) |
| Async coloring | solved — fibers | present | solved — goroutines | present | present |
| Async frame size | minimal (+A oracle) | minimal (stackless) | full stack | minimal | heap closure |
| Multiple writers | yes (MVCC, CRDT) | no — single &mut | mutex only | mutex only | yes (single thread) |
| Injection safety | type error (templates) | library only | partial | none | none |
| i18n correctness | compile-time (msg``) | runtime | runtime | runtime | runtime |
| GC pauses | none (ARC) | none | GC pauses | none | GC pauses |
| ARC atomics | none (single thread) | Arc: always atomic | N/A (GC) | N/A (manual) | N/A (GC) |
| All copies explicit | yes — .c() only | yes — .clone() | implicit | mostly | implicit |
| GPU first-class | +V modifier | unsafe (wgpu) | none | none | WebGPU only |
| Maps | Bag type built-in | HashMap only | map[string]any | manual | native objects |
| Keyword count | 10 (all 1 letter) | ~50+ | ~25 | ~30 | ~50+ |
vs Rust — Same Goals, Different Philosophy
Pin/Unpin, Rc/Arc/RefCell proliferation, sharp &T/&mut T distinction. Rust async has the coloring problem. Stackless coroutines are lean but you cannot yield from nested calls without propagating async upward.+R +M objects use proxy-mediated writes, meaning multiple concurrent writers are possible via MVCC or CRDT — impossible in safe Rust. The single-threaded fiber scheduler eliminates most synchronization entirely. +A minimizes fiber frames without losing stackful ergonomics. No lifetime annotations. No Pin.vs Go — Better Concurrency, Better Safety
+A to tell the runtime "only save these two values." Go also has nil pointers (runtime panics, not type errors), GC pauses, and no injection safety at the language level.+A. Null safety is a type error, not a runtime panic. No GC — ARC with O(1) cycle detection. Templates make injection impossible.vs Zig — Same Performance Goals, More Ergonomics
?T optionals, async has the coloring problem, and there is no template safety or i18n.+R/-R modifier encodes allocation strategy; U's answer to Zig's allocator parameters: the allocation strategy is encoded in the type. U adds null safety, injection safety, and fiber concurrency that Zig doesn't have.vs JavaScript — Same Ergonomics, Radically Different Guarantees
await, the entire call stack must unwind back to the event loop. Every local variable surviving the suspension is serialized into a heap-allocated Promise closure. This is why async infects callers — each frame must opt in to this serialization. Two separate queues: macrotasks (setTimeout, I/O — one per loop tick) and microtasks (Promise.then — all drained before the next macrotask). Microtasks can starve I/O callbacks if they keep adding more microtasks. Generators are stackless and can only yield at the top level — not from nested calls.Formal Guarantees
Every safety claim in U is backed by a proved theorem in the formal calculus λ_U.
| # | Theorem | What it proves |
|---|---|---|
| 1 | Modifier-Optimization Correspondence | Each annotation is a sound compiler transformation license: -R→stack alloc, -M→no sync, -N→no null check, +A→exact fiber frame |
| 2 | ARC-Freedom | Well-typed -R programs contain zero heap allocations or ARC operations |
| 3 | Race-Freedom | Well-typed programs have no data races |
| 4 | Proxy Safety | Every +R +M mutation passes through a proxy satisfying its declared policy |
| 5 | Type Soundness | Well-typed programs do not get stuck (Progress + Preservation) |
| 6 | Red-Blue Freedom | All functions may call all functions without async annotation change |
| 7 | Fiber Frame Minimization | Suspension frame contains exactly the +A-annotated live values — no more |
| 8 | Signature Completeness | Function signatures are machine-verified contracts for all three modifier dimensions |
| 9 | Template Safety | All {expr} in html/sql/msg are escaped at compile time — injection is a type error |
| 10 | Localization Completeness | Missing locale keys and placeholder mismatches are compile-time type errors |
| 11 | Stack-Frame Confinement | -R values passed to -R functions cannot be retained beyond the call |
| 12 | Compilation Correctness | Compilation to C/WASM preserves semantics and places -R on stack, +R on heap |
| 13 | Domain Oracle | +V/+C/+A domain decisions are exact reads of type annotations — no analysis needed |
| 14 | .x() Safety | All .x() iterations are bounded, non-invalidating, and bounds-safe |
| 15 | Conditional Completeness | &, |, ?? are expressively complete for all conditional patterns |
| 16 | Unsafe Convention Soundness | Programs with no ! suffixes have no out-of-bounds, divide-by-zero, or unchecked overflow |
Everything Together — Composability & the Pit of Success
U's type system is not a collection of independent safety features bolted together. Promises, events, exceptions, ownership, and iteration are all expressions of the same underlying model. The pit of success means the natural thing to write is also the correct thing. These scenarios show why.
Scenario 1 — Fetch, fanout, collect, handle
The classic parallel fetch. In JavaScript this requires Promise.all(), .catch(), and careful attention to which errors propagate where. In U the types enforce the structure.
d Article { title: S, body: S, author: S } a f loadDashboard(ids: [I]) // Error policy declared upfront — happy path reads clean below e.x(MyLib.networkPolicies) // typed array: [log, notify, retry] e.x((err: NotFoundError) => showEmpty()) // Start N concurrent fetches — map returns [Article +A] pending: [Article+A] = ids.map((id) => a fetchArticle(id)) // Await all — input order preserved, time = max not sum articles: [Article] = pending.all() // Any rejected fetchArticle → NetworkError → e.x() fires above // No .catch(), no try/catch, no Promise.all().catch() dance render(articles)
Scenario 2 — Race with fallback
Try the cache first; if it times out, fall back to the network. The winner takes it. The loser is ignored. .any() returns T +N +A — nullable because nothing might win.
a f loadConfig(): Config e.x((err: NetworkError) => r => Config.defaults()) cache: Config+N+A = a fetchFromCache() remote: Config+N+A = a fetchFromNetwork() winner: Config+N+A = [cache, remote].any() r => winner ?? Config.defaults()
Scenario 3 — Event stream with typed dispatch
A UI component subscribes to events, each handler typed. Error handling is a separate concern registered before the event logic. RAII closes the subscription when the component is destroyed.
d ClickEvent { x: I, y: I, button: I } d ResizeEvent { width: I, height: I } d Canvas+R(RAII) clicks: ClickEvent+A+R resizes: ResizeEvent+A+R f drop(canvas: Canvas+R) // fires when last ref drops canvas.clicks.unsubscribe() // cleanup automatic canvas: Canvas+R = Canvas.create() // Error policy for canvas event handlers e.x((err: RenderError) => logAndSkip(err)) canvas.clicks.x((evt) => paint(evt.x, evt.y)) canvas.clicks.x((evt) => logInteraction(evt)) canvas.resizes.x((evt) => relayout(evt.width, evt.height)) // No unsubscribe logic — RAII handles it when canvas scope exits
Scenario 4 — Shared state with concurrent workers
Multiple fibers read a config that can be hot-reloaded. MVCC means readers never block. The policy is declared once on the binding; callers need no locking code.
config: AppConfig+R+M(MVCC) = AppConfig.load() // N concurrent workers — all reading config simultaneously pending: [Result+A] = jobs.map((job) => a runJob(job, config)) results: [Result] = pending.all() // Hot-reload fires while workers are running config.reload() // MVCC: new version; in-flight workers see old version // No mutex, no lock, no blocking. Policy handles it.
Why this is the pit of success
Default is safe
Zero annotations = stack-allocated, immutable, non-null, synchronous. The safest possible program requires no effort. Complexity is opt-in via modifiers.
One mechanism, many contexts
.x() handles events, errors, iteration, and policy registration. .all() and .any() handle promise collections. T +N is nullable everywhere. No special cases.
Error handling is a preamble
e.x(policies) before the happy path. Policies are typed arrays — reusable across 100 call sites. The happy path reads as if errors don't exist, because the compiler verified they're covered.
Type-indexed dispatch
Events, errors, and promises all dispatch by type. No string names. No untyped catch-all. The compiler knows exactly what types flow through every channel at every call site.
Policy declared once
RAII, MVCC, Actor, ARC — declared at the binding site. Every consumer gets the right behavior automatically. No per-call locking code, no per-call cleanup code.
Full stack preserved
Stackful fibers. Exceptions carry the complete trace from main through every intermediate caller. Unlike JavaScript where await destroys call context.
On LLMs and the Need for New Languages
A reasonable objection: large language models trained across millions of codebases already know the right patterns. They'll suggest MVCC over a raw mutex, typed errors over untyped exceptions, non-null defaults. Why build a new language when a model can just tell you the correct approach?
The answer is structural. An LLM can recommend MVCC — it cannot prevent you from forgetting to declare the write policy on the next binding. Static checking costs microseconds. Re-inferring a codebase's full dependency graph, policy structure, and modifier discipline from source text — the way current AI coding tools do on every query — costs significant compute and produces educated guesses that can be wrong. A type system encodes verification once; every tool reads it for free thereafter, without re-spending the inference cost.
The deeper point is that the pit of success is a coordination property. It requires that the easy path and the correct path coincide for every developer on every greenfield codebase — not just those who happen to ask the model at the right moment with the right prompt. Language-level enforcement creates a common grammar of correctness that scales uniformly across teams and organizations. Haphazard LLM suggestions across a thousand codebases, each framed differently, produce a thousand dialects. A shared type system produces one.
There's a related argument about tooling. When a codebase declares its structure in types — ownership, mutability, nullability, async boundaries, write policies — tools can understand it instantly from the annotations. When it doesn't, tools must infer the structure from source text on every query, re-reading files, rebuilding call graphs, reasoning about implicit relationships. The cost of that inference scales with codebase size and repeats indefinitely. The cost of reading a type annotation is constant and paid once.
Grokers — Pre-computed knowledge graphs for codebases. Where Cursor and Claude Code re-infer the dependency graph on every query, Grokers indexes it once and makes it queryable in milliseconds. The structural argument made concrete: declared structure is cheaper than inferred structure.
Past the Single-Developer Loop — AI coding when changes need to coordinate across teams. Where Claude Code and Cursor collapse "discussing what to change" and "actually changing it" into one loop, this splits the layers: codebase indexed as a queryable graph, changes routed through governance before any file is written. Structure enforced at the workflow level, not by convention.
Safebox — Sealed compute environments where data sovereignty is a property, not a promise. The keys to read your data are mathematically bound to the box itself. The same principle as U's type system: correctness enforced by architecture, not by asking nicely.