Type System & Abilities
Hindley–Milner inference with level-based generalization, scoped-label structural rows, variants, zero-cost distinct wrappers, coherent abilities, and Rose-style Row.map.
Primitives & exact 64-bit Int
Exp's primitive types are Unit, Never, Bool,
Int, Float (IEEE-754 binary64 with canonical NaN at observation
points), String (UTF-8, scalar-indexed), and Bytes.
Int is strictly 64-bit signed with trapping overflow (use
+%, -%, *% for explicit wrapping arithmetic). On the
JavaScript backend, static range analysis selects fast JS number paths whenever
safe and automatically uses range-checked BigInt otherwise — preventing silent
53-bit precision corruption.
Structural records, rows & defaults
Records are structural with scoped-label row polymorphism ({ name: a | r }).
The compiler sorts record fields into a canonical alphabetical order across modules and
backends, guaranteeing identical monomorphic hidden classes in V8 and JSC.
Named record types act as structural aliases that may declare default values. Any
Option<T> field defaults to None automatically, and when a
function's last parameter is a declared record type, it behaves naturally as named arguments.
Variants, nominal records & distinct types
- Algebraic variants: constructors belong to their declaring type
(
Shape.Circle). Bare constructor names resolve by uniqueness, expected type, then current file; ambiguous bare names produceE0032. On JS, variants lower to compact integer tags ($tag: 0, 1, ...) with consistent object shapes. - Nominal records: a single-constructor variant with named fields (like
Point(x: Float, y: Float)) supports field access (p.x), spread updates ({ ...p, x: 9.0 }), and field reassignment (p.x = 9.0) while keeping nominal identity for abilities. -
distincttypes:type UserId = distinct Intcreates a zero-cost nominal wrapper erased completely at runtime — zero object allocation in JS or C99. Construct withUserId(5)and unwrap viaid.value()or pattern matching.
Coherent single-parameter abilities
A type body containing only method signatures declares a single-parameter,
globally coherent ability (orphan rule E0056, no overlap E0057, no
higher-kinded complexity). Show, Eq, and Ord are
derived structurally for all data types and can be overridden on nominal variants.
type UserId = distinct Int
type RequestOptions
timeoutMs: Int = 5000
retries: Int = 2
bearerToken: Option<String>
end
type Printable
fn format(self) -> String
end
type Metric
Metric(name: String, value: Float)
end
fn Metric.format(m)
"{m.name}={m.value:.2}"
end
fn renderAll(xs)
xs.map(x => x.format()).join(", ")
end
fn buildOpts() -> RequestOptions
-- Missing fields fill declared defaults; Option fields default to None
{ retries: 4 }
end
fn main()
id = UserId(42)
opts = buildOpts()
items = [Metric("p99_ms", 1.60), Metric("rt_bytes", 0.0)]
print("user={id.value()} timeout={opts.timeoutMs} retries={opts.retries}")
print(renderAll(items))
endRow-generic programming (Row.map / Row.fold)
Row.map(rec, x => ...) and Row.fold(rec, init, (acc, x) => ...)
operate generically across record fields at each field's concrete type using decidable
first-order Rose-style row typing. This same mechanism powers record-shaped
Async.all({ user: => ..., posts: => ... }) and schema-free typed
Json.decode.
export fn doubleCounts(rec: { pure: Int, effects: Int, async: Int }) -> { pure: Int, effects: Int, async: Int }
-- Rose-style Row.map transforms every field while preserving exact field names
Row.map(rec, n => n * 2)
end
fn main()
counts = { pure: 37, effects: 20, async: 15 }
doubled = doubleCounts(counts)
print("pure={doubled.pure} effects={doubled.effects} async={doubled.async}")
endFour-step method resolution
Any dot-call x.f(a) resolves deterministically in four steps:
- Callable record field
fonx. - Method
fn T.f(self, ...)declared onx's nominal typeT. - Ability method
fimplemented forx's type. - Function
fin lexical scope (uniform call syntax).