◄ WORLD V · SONNY 5DART 254 · a helldive at the net

THE EFFECT SYSTEM the type says not just what it returns, but what it disturbs

A plain type says what a function returns. An effect system also tracks what it does — reads state, writes memory, throws, performs I/O — as a set of effects in the type: read : () → Int ! {State}. Effects compose by union; a function with the empty effect set is pure. This lets the compiler know which code can be reordered, memoized, or run in parallel (pure code) and which cannot. From Gifford & Lucassen, effect systems are how a type system reasons about the messy, imperative half of a program.

THE TECHNIQUE effects as a set; compose by union; empty set = pure

Effects as a bitmask (Read=1, Write=2, IO=4). The demo composes two effectful calls by union and shows the combined effect: live demo


HISTORY & CREDIT Gifford & Lucassen, 1986

“A function's type is its signature.” — its signature hides its side effects, and those are exactly what stop you reordering or parallelizing it. An effect system drags the hidden half into the type, where the compiler can reason about it. cited

1986–88 · David Gifford & John Lucassen — integrating functional + imperative via effect systems; polymorphic effects.
1990s · Talpin & Jouvelot — type-and-effect inference.
now · Koka, Eff, algebraic effect handlers; Rust's unsafe/async are effect-flavored.

Purity is the empty effect set — the license to reorder, memoize, and parallelize freely. An effect system is the compiler learning which code it is allowed to move. Gifford-Lucassen 1986

RECOMMEND FOR I-13 composed effect set, computed

On the canonical compiler, composing a Read(1) and a Write(2) unions to effect set 3; two pure calls stay 0:

$ i13 run t_effect.i13 # union effect sets effects_rw = 3 -- Read | Write pure = 0 -- the empty effect set
Recommend: i13 is pure by construction — the empty effect set, everywhere. It has no mutable heap, no I/O, no exceptions; its arrays are value-semantic and its functions are total transforms of f64. So every i13 function's effect would be {} — the very property an effect system works to prove, i13 has by having nothing to track. The flip side: because there are no effects, there is nothing to gain from typing them, and i13's ledger can stay silent on the imperative world it never enters.