Effects and type classes¶
Effects enter QVR in two places. A chart parser may type expressions with effects, such as a
continuation for a quantifier or a set of alternatives for an indefinite, and lift its rules to
these types by the operations of a functor, an applicative functor, or a monad, as in
effect-driven interpretation (Bumford and Charlow, forthcoming; Charlow, 2025). The Quivers Indexed Effect
Core (QIEC) checks every computation of a module against an effect row and runs it with
effect handlers (Plotkin and Pretnar, 2009) (§8). The
library's Python packages quivers.monadic and quivers.arrows provide the
type classes behind the first (Wadler and Blott, 1989).
An algebraic effect separates a request from its interpretation (Plotkin and Power, 2003): a computation requests a random value, and a handler answers by drawing one, by replaying a given value, or by trying every value. The computation then continues with the answer, so one program can be run under different strategies. A type class lists the operations a type provides, and its laws say which rearrangements of those operations preserve meaning.
1. Setting¶
The definitions of Setting and notation apply. A parser whose categories carry effect types fixes:
- a finite set \(\mathcal C = \llbracket \mathrm{Cat} \rrbracket\) of categorial types, built by
FreeResiduated(generators, depth, ops)(Schemas §4); - a finite list of declared effects \(T_1, \dots, T_n\), each an instance of one or more of the type
classes
Functor,Applicative,Monad,Alternative,MonadPlus,Traversable,ArrowApply, andArrowLoop.
A chart entry has a categorial type and a stack of effects applied to it, of length at most \(k\),
the effect_depth of chart_fold. Write
for the set of such pairs, where \(\mathrm{Stack}_{\le k}\) is the set of lists of at most \(k\) effects. Each chart cell at a span \((i, j)\) holds weights indexed by \(\widehat{\mathcal C}\).
2. Type classes¶
The type class guide describes the classes in use. A functor maps a function over a value in a context. An applicative functor combines several values in contexts by a fixed shape of computation (McBride and Paterson, 2008). A monad also lets the next computation depend on the value just produced (Wadler, 1992). For probability distributions, this is the difference between combining independent draws and choosing the next distribution after seeing a draw.
Each class in quivers.monadic.typeclasses is an abstract Python
class. Beside each, quivers.monadic.theories has a theory
(TypeclassTheory) that declares the operations and laws the class introduces and the classes it
extends. The class's theory is the colimit of a diagram with
one node per class it extends, directly or not, and one theory inclusion per extension, computed by
panproto through the theory engine. A class shares its ancestors' symbols
because the inclusions relate them, never because names coincide, and the colimit's provenance names
the class that declared each law. ThMonadPlus, for instance, is ThMonad and ThAlternative glued
along ThApplicative. The laws are equations in one universe sort, stated with the combinators of
ThCombinators (application app, id, curried composition dot, and the section applyto), so
that a law with a bound variable is stated first-order:
| Theory | Extends | Operations | Laws |
|---|---|---|---|
ThCombinators |
app, id, dot, applyto |
their defining equations | |
ThFunctor |
ThCombinators |
fmap |
identity, composition |
ThApplicative |
ThFunctor |
pure, apply |
identity, homomorphism, interchange, composition, fmap coherence |
ThMonad |
ThApplicative |
bind, join, unit, kleisli |
left unit, right unit, associativity |
ThAlternative |
ThApplicative |
empty, alt |
identity, associativity |
ThMonadPlus |
ThMonad, ThAlternative |
left zero | |
ThMonadTrans |
ThCombinators |
lift |
lift of pure, lift of bind |
ThFoldable |
ThCombinators |
foldr |
|
ThTraversable |
ThFunctor, ThFoldable |
traverse |
identity, fmap coherence |
The naturality and composition laws of Traversable quantify over applicative transformations and
composite applicatives, which a one-sorted signature cannot range over, and are not stated.
An instance of a class is a Python object that implements its methods, with its carrier a finite set
and its operations morphisms of Morphisms. The library does not check the laws when
an instance is registered. quivers.monadic.laws has functions that test
the functor and monad laws of an instance at given objects.
3. Lifted rules¶
For each declared effect \(T\) and each rule of the parser, the function
class_directed_lifts produces lifted rule schemata according to
the classes \(T\) belongs to. In QVR's slash notation, with the result first
(Schemas §3.1):
| Class of \(T\) | Schema | Shape |
|---|---|---|
Applicative |
pure_T |
\(X \to T(X)\) |
Applicative |
apply_T |
\(T(X / Y) \otimes T(Y) \to T(X)\) |
Monad |
bind_T |
\(T(X) \otimes (T(Y) / X) \to T(Y)\) |
Alternative |
alt_T |
\(T(X) \otimes T(X) \to T(X)\) |
for all categorial types \(X\) and \(Y\). pure_T and apply_T are the unit and the lifted application
of an applicative functor, the lifting of function application that effect-driven interpretation uses
(McBride and Paterson, 2008; Bumford and Charlow, forthcoming). bind_T is monadic bind, whose second premise
\(T(Y) / X\) is the categorial type of a function from \(X\) to \(T(Y)\). It is the bind of \(T\), not a
morphism of the Kleisli category of \(T\). A MonadPlus instance gets the lifts of Monad and of
Alternative. A bare Functor, ArrowApply, and ArrowLoop add no schemata. The base
schema contributes the generated names, while the four displayed shapes remain fixed.
The applicative composition law permits rebracketing applications that compose the same pure functions and keep the original order of the effectful arguments (McBride and Paterson, 2008). For instance, two state updates that append the digits \(1\) and \(2\) to a register give \(12\) in one order and \(21\) in the other. Exchanging those arguments requires a separate commutation law.
4. Firing rules¶
A chart parser over \(\mathcal C\) with declared effects \(T_1, \dots, T_n\) has cells
vectors of weights indexed by categories with effect types. Write \(\mathrm{Chart}[i, j] \ni (\alpha ; \bar T)\) when the cell at span \((i, j)\) has an entry at the type \(\alpha \in \mathcal C\) under the effect stack \(\bar T\), write \(\bar S \cdot \bar T\) for the concatenation of stacks and \(\epsilon\) for the empty stack, and let \(\sigma\) range over substitutions of categorial types for the variables of a schema. Cells are filled by three kinds of firing, each an inference rule of a weighted deduction:
In \(\textsc{Base}\) and \(\textsc{Lift}_T\) the substitution \(\sigma\) is determined by matching the types
of the two cells against \(\pi_1\) and \(\pi_2\). \(\textsc{Lift}_T\) is the firing of the lifted schemata of
§3, and since every monad is an applicative functor it covers monadic effects. \(\textsc{Swap}_{T, U}\)
fires the schema swap_TU : T(U(X)) -> U(T(X)) that
make_swap_schema builds from a registered
distributive law \(\lambda\), a natural transformation
that exchanges the two monads compatibly with both (Beck, 1969). The chart sums the weights
of all derivations built from these firings under the conditions of
Weighted deduction §7.
Structural chart construction can derive an unprefixed conclusion while recording its
indexed prefixed child in the proof. The checked pre_fold action installs the named QIEC
handler during interpretation of the selected rule. In the ordered binary form, the fold
interprets the left premise once and passes its value and the original indexed right proof
to the action. The action installs the handler with that value and interprets the right
proof once in its scope.
In the phased lexical example, this scope retains the original lexical draw and the order of the state requests. The placement of a handler at the selected proof node is related to the right-adjoint ejection that Bumford and Charlow describe in §5.3.2 of the author preprint (Bumford and Charlow, forthcoming). Interpretation reference
5. When lifting preserves the base grammar¶
Let \(r\) be a rule and \(T\) an effect instance of the classes \(\mathfrak C_1, \dots, \mathfrak C_k\). If the instance satisfies the laws of these classes and the chart's semiring and convergence conditions hold (Weighted deduction §5), then the weight the chart assigns to an entry whose category has an effect type is the sum, over its derivations, of the composites of base rules with the operations of \(T\) that the derivation uses. The order of chart updates may vary under the strategy independence hypotheses, including preservation of the weighted derivations and the order of multiplication within them. Weighted deduction §7
- For an applicative \(T\), a lifted firing composes the base rule with
applyof \(T\). Successive lifts agree under rebracketing when they denote the same pure composite on the same ordered effectful arguments (McBride and Paterson, 2008). - For a monad \(T\), a bind firing is Kleisli composition with the base rule, and the associativity law \(\mathrm{join} \circ \mathrm{fmap}(\mathrm{join}) = \mathrm{join} \circ \mathrm{join}\) makes iterated binds equal to the iterated Kleisli composite.
- For an alternative \(T\),
altcombines two analyses of one span, and its identity and associativity laws make the combination independent of grouping.
This is a statement about the denotation the chart computes, given lawful instances. It is not adequacy in the sense of programming language semantics, which relates an operational semantics to a denotational one (Plotkin, 1977).
6. Free monads and handlers¶
A free computation records its requests before deciding how to answer them: a leaf holds a finished value, and an operation node holds a request and a continuation for each possible answer (Swierstra, 2008). A handler interprets the tree by replacing each request with its own behavior, a fold over the tree (Plotkin and Pretnar, 2009).
For an effect signature \(\Sigma = \{\mathrm{op}_1 : P_1 \to R_1, \dots, \mathrm{op}_m : P_m \to R_m\}\) with finite parameter sets \(P_i\) and finite answer sets \(R_i\), the free monad on \(\Sigma\) sends a set \(A\) to the trees with leaves in \(A\) whose operation nodes \(\mathrm{op}_i(p, \kappa)\) have a parameter \(p \in P_i\) and a continuation \(\kappa : R_i \to\) trees, so a node branches \(|R_i|\) ways:
with \(\mathrm{Tree}_{\Sigma, n}(A)\) the trees of depth at most \(n\). The class
FreeMonad represents only the trees of depth at most its parameter
depth (default \(3\)), as one finite set. That set is not closed under bind, which can make a tree
deeper, so the representation covers the binds whose results stay within the bound.
A handler of \(\Sigma\) into a monad \(S\) gives a return clause \(A \to S(A)\) and, for each operation, a
clause that answers a request using the interpreted continuation. It makes \(S(A)\) a model of the
operations of \(\Sigma\), and running the handler, Handler.run, is the unique homomorphism from the free
model \(\mathrm{Free}_\Sigma(A)\) to it, the fold over the tree (Plotkin and Pretnar, 2009).
7. Arrows and monads¶
An arrow generalizes the composition of
functions (Hughes, 2000). Arrows with an application operation (ArrowApply) correspond to monads:
the Kleisli arrows of a monad form an ArrowApply, and an ArrowApply defines a monad whose values of
type \(A\) are its arrows from the unit to \(A\) (Hughes, 2000). The functions kleisli and
arrow_monad of quivers.monadic.bridges implement the two directions.
ArrowLoop is the class of arrows with a feedback operation loop. For the Kleisli arrows of a monad,
loop requires the monad to support value recursion, the class MonadFix [@erkok2000recursive;
@paterson2001arrows], so an ArrowLoop instance for Kleisli arrows exists only for such monads.
When the list of declared effects is empty, only \(\textsc{Base}\) fires, and the parser is the categorial grammar parser of Weighted deduction §6 with the rules it is given. The effects add firings and change no weight that the empty list would compute, so the parser with effect types is a conservative extension of the plain one.
8. QIEC rows and handlers¶
Two state cells counter and total, both holding integers, have the same interface and different
identities: handling a request to counter must leave a request to total alone. An effect instance
is one named occurrence of an effect interface, and its handler intercepts only its own requests
(Bauer and Pretnar, 2015; Biernacki et al., 2020). An effect row lists the instances a computation may
use (Leijen, 2014; Hillerström and Lindley, 2016). The typing rules
track which requests remain after handling and how many times each continuation may be resumed.
When a handler answers a request, its continuation is the rest of the computation. A handler for draws resumes once with a random value, and a handler for enumeration resumes once for each alternative. A deep handler is reinstalled around the resumed computation, while requests made by the handler's own clause go to the handlers outside it (Kammar et al., 2013). So the order in which handlers nest, and the instance a request names, both change the result.
Every computation of a module, including each elaborated program, is checked under QIEC. An applied
interface \(E[\bar a]\) describes a family of operations, and an instance \(i : E[\bar a]\) gives the identity
that appears in a row, so counter and total are separate entries. A row has the form
\(\{i_1, \ldots, i_n \mid \rho\ \mathsf{lacks}\ j_1, \ldots, j_m\}\): the tail \(\rho\) is a row variable, so
that functions may be polymorphic in the rest of the row
(row polymorphism), and the lacks list records the
instances the rest of the row may not contain, which extending a row and eliminating a handler need.
8.1 Implementation¶
The reference machine, the library's interpreter for QIEC, implements deep handlers bound to instances. Resuming a captured continuation reinstalls the handler that matched, and an effect performed in a clause body goes to the outer handlers. A request matches a handler by its instance, its applied interface, and its operation, so another instance of the same interface is never intercepted. The machine checks at run time that a clause resumes no more often than its declared resumption grade allows, and a continuation resumed more than once extends the address of its trace with a branch.
When a completed authored grade-zero clause abandons a continuation its handler owned, the machine drops the captured handler contexts, from innermost to outermost. That traversal follows a suspended authored clause's own capture when its resumption is unspent, has no unrestricted seed, and has never been shared by a multi-shot fork. A forked frame still refers to the same resumption. Dropping one copy can leave another copy able to resume it. When one authored multi-shot clause returns normally outside a host delimiter, it can also drop a directly captured, unspent clause shared solely among its own seed and shots. Its postlude has finished by then. A distinct fork owner or a borrowed host continuation leaves this shared cleanup unresolved.
These rules cover the interfaces of state, abort, random choice, scoring, nondeterministic choice, and
weighted accumulation. A handler's clauses are written in QVR, or held only in the running Python process
and given by a provider. A foreign handler may instead declare what it computes, such as a semiring sum
or a settlement, and the runtime builds its clauses from that declaration and the laws of the semiring it
names, never from the handler's name
(Weighted deduction §11). Pyro, NumPyro, PyMC, Edward2, Turing, Gen, WebPPL, and Church run the same typed
computations through implementations of the QIEC runtime for each target, which dispatch by the stable
identifiers of instances and operations, so the two state cells above stay separate. Tests compare these
implementations with the reference machine at fixed parameter values. The static targets read a
computation with its handlers discharged. Stan expresses a computation with an
empty closed row, no static parameters, and a scalar result as a user-defined function, including
conditionals, calls, and recursion, and BUGS and JAGS refuse a call they cannot inline. For the other
forms the static targets report a qiec:capability:* diagnostic. The QIEC developer note gives the
details.
The effect handlers of quivers.effects are handlers of this calculus, in the
style of inference by effect handlers for probabilistic programs (Ścibior et al., 2018; Nguyen et al., 2023). A
MonadicProgram runs on the reference machine as the computation
program_kernel builds from it: each step computed in Python is a
request to the Compute interface of the prelude on the values bound so far, each draw is a request
Random.sample to the program's random instance, and each density is a request Score.add to its score
instance, made by the handler that answered the draw. A handler on the with stack is installed as a
handler of one of these instances, and the run nests the handlers in a fixed order, from the outside in:
the score accumulator, the score transformers, the scoring draw and the observations, the handlers of
random in the order of the stack, the parameter store with the param handlers over it, and the steps.
Two consequences follow. An inner handler of random sees a request before any outer one and receives the
outer answer back through its continuation, so a trace inside a clamp records the clamped value. And the
handler that answers a draw emits its density outward, so every score transformer sees every site, and a
trace reads the density of each site from what reaches the accumulator, under the static identity and
dynamic address that every derived request carries.
8.2 Static discharge¶
Write \(\mathcal{E}\) for an evaluation context that contains no handler of \(i\) with a clause for \(\mathsf{op}\), and let \(h\) be an authored handler with parameters \(\bar p\), return clause \(\mathsf{return}\ x \Rightarrow c_{\mathsf{ret}}\), and clauses \(\mathsf{op}(\bar x) \Rightarrow c_{\mathsf{op}}\). The reference machine computes by the two rules of deep handlers (Plotkin and Pretnar, 2009; Kammar et al., 2013) with parameters (Leijen, 2017):
Discharge applies these rules to the open body of a computation before it runs. It carries four equations besides:
- \(\mathsf{let}\ x \leftarrow \mathsf{return}\ w\ \mathsf{in}\ c = c[w/x]\), the left identity law of sequencing, applied when \(w\) is a variable, a literal, or a tuple or constructor application of these, and otherwise left as a binding, so that a computed value is shared;
- \(\mathcal{E}[\mathsf{if}\ b\ \mathsf{then}\ c\ \mathsf{else}\ d] = \mathsf{if}\ b\ \mathsf{then}\ \mathcal{E}[c]\ \mathsf{else}\ \mathcal{E}[d]\), with which a conditional commutes with its context;
- when both branches return to one context, with values \(w_1, w_2\) and handler parameters \(\bar v_1, \bar v_2\), the conditional instead binds \(\mathsf{if}\ b\ \mathsf{then}\ (w_1, \bar v_1)\ \mathsf{else}\ (w_2, \bar v_2)\) ahead of that context, which is then stated once;
- \(\mathsf{handle}\ i\ \mathsf{with}\ h(\bar v)\ \mathsf{in}\ \mathcal{E}[c] = \mathsf{let}\ y \leftarrow c\ \mathsf{in}\ \mathsf{handle}\ i\ \mathsf{with}\ h(\bar v)\ \mathsf{in}\ \mathcal{E}[\mathsf{return}\ y]\) for a request or a call \(c\) that does not reach \(h\), such as a request to an instance the computation does not handle.
A call whose row names a handled instance is replaced by the body of its callee. A case on a constructor
application is its branch, and any other case is treated as a conditional.
Proposition. Let \(\Gamma \vdash c : A \mathbin{!} \epsilon\) and let the checked discharge fragment eliminate the selected handler, yielding \(\Gamma \vdash c' : A \mathbin{!} \epsilon'\) with \(\epsilon' \subseteq \epsilon\). Fix a closing substitution, one numerical interpretation, and matching replies to the outward requests. On successful finite executions the two terms give the same result and the same ordered outward requests, including their full original addresses. The kernel checks the residual body row at the rewritten declaration. Discharge keeps a reached value evaluation when the totality of that evaluation cannot be proved. For instance, a projection of an eagerly evaluated tuple still checks an unused square-root field before selecting another field. An aborted continuation is outside the reached path.
Projecting each trace onto the outward requests gives the same observation. The full reference trace also records the internal requests to the eliminated handler. A finite ranked computation can use tabulation for its answer and reference execution for its addressed trace. The corresponding evidence binds both observations to the same source and arguments.
Proof sketch. Each step of discharge is one of the machine's rules or one of the equations, closed under
evaluation contexts. The machine's rules preserve types by the
subject reduction argument for deep handlers
(Plotkin and Pretnar, 2009; Kammar et al., 2013), and the parameters do not change it, since a resume carries
values of their declared types. A row can only shrink, as a clause that does not resume drops the requests
of its continuation. The first equation holds in every monad. The
second and third hold since a closed condition is true or false, and in each case both sides reduce to
one term: an authored clause and the
parameters of its handler are pure data, so the context \(\mathcal{E}\) may be entered with either branch's
values. The fourth holds since a handler that a request does not reach keeps its place in the continuation
that the request captures, so resuming that continuation with \(y\) runs the same handler around
\(\mathcal{E}[\mathsf{return}\ y]\). An if whose condition is a variable is kept, so no step depends on an
assumption about a value. \(\square\)
A lowered named computation keeps its original calling type. If the rewritten body has a smaller closed row, the declaration carries that body row explicitly. The module checker infers the body type again and requires the same result type and exact body row. Each remaining row entry must have the original instance identity and applied effect. Thus callers retain the same nominal type, and the target can check the rewritten body against the effects it actually needs. For instance, a zero-grade clause may drop the only draw and score in a continuation, leaving a pure body whose callable signature still names both effects.
Address preservation. A residual request has an address \((o,d,s)\) consisting of its static site identifier \(o\), its ordered dynamic frames \(d\), and its resumption path \(s\). For the admitted discharge fragment, the corresponding residual requests of \(c\) and \(c'\) have equal addresses when the two runs receive the same checked answers to those requests. This statement concerns execution by the QIEC reference machine.
The address invariant relates the allocation counters, live frame order, and resumption paths at the corresponding steps. Each entered call or local instance advances its original counter once, including an inlined scope that makes no observable request. Discharge retains an immutable address value for that scope. Capture removes the live frames of the captured continuation while the operation clause runs. Each resumption reinstates the corresponding frames in order, reusing their allocations, and appends the ordinal for an unrestricted shot. A handler whose return can make an observable request allocates a return activation ordinal at installation. A resumption reuses that activation. A capture through a return or local instance includes its allocated value in the clause address, in the same order as lexical call sites. Discharged code resolves the deferred clause address from those original values. A retained call extends the live path for the duration of its body. If that call carries a discharged shot or clause path, the discharger requires a closed residual effect row and rules out an outer multi-shot clause that could interleave its own shot with the restored path. Scope exit restores the preceding paths. These steps preserve \((o,d,s)\) at each residual request and give the same address sequence by induction along the execution. The reference machine handles cases where an external unrestricted clause can reenter a live resumption after another shot has changed its counter.
The use check is an observation of a reached clause. A linear clause that returns normally must invoke its resumption exactly once. A nested abort can skip that invocation, so the symbolic interpreter retains reference execution when a path can complete with the wrong count. A multi-shot capture can also copy an active affine or linear clause whose token has yet to be invoked. The copies share the reference machine’s count. The discharger retains that check instead of treating each copy as an independent token.
An active unrestricted token also has a shared shot counter. If a
copied token can be invoked again in a computation with surviving
effects, the discharger retains the reference counter and its request
addresses. A copied postlude that never invokes the token can still
discharge. The reference machine also checks a provider’s copy
permission for a directly typed Sampleable[A] value. When a
multi-shot capture may need that value in its owned scope, symbolic
discharge leaves the permission check in the reference computation.
Values beyond the delimiting handler are outside that capture.
Discharge terminates. A callee is entered only when it is not being entered already, so a body unrolls to a finite tree of returns, requests, and conditionals. A deep handler is the fold of §6 over that tree: it replaces each request by its clause, with the folded subtrees in place of the resumptions, and the fold of a finite tree by finite clauses is finite. The result grows by a factor of \(m\) at each request whose clause resumes \(m\) times, and a conditional whose branches differ in \(k\) values is stated \(k\) times. When every clause resumes at most once, and the branches of each conditional return to one context and differ in one value, it is linear in the number of requests and the sizes of their clauses. A computation that passes 2048 statements, or 65536 steps of the rules, is left as it is.
For a closed recursive computation, one handler for a named instance can be specialized without unrolling its calls. Suppose the handler is total and authored, its state is a fixed product \(P\), and the final result type is \(B\). Each clause either uses one tail resumption on every path or has grade zero. Ordinary prefixes and the return clause are pure. The specialization checks a monomorphic first-order graph with no residual effects, and retains the source's evaluation order for values and branches.
For an intermediate result type \(A\), the specialized computation takes a state and returns an element of \((A\times P)+B\). A normal return \(a\) at state \(p\) produces the left injection of \((a,p)\). A grade-one request evaluates its reply and new state in the current state, then uses both in the selected continuation. A grade-zero request evaluates its clause once and produces the right injection of its answer. A bind case splits on this result. The left branch invokes the next computation with the returned value and state. The right branch propagates the answer. At installation the handler's return action handles the left injection, and the right injection yields the final answer directly.
For each finite execution, induction on the execution establishes the state at each reached request and the selected result at each call boundary. Induction through pending binds gives the same skipped work on abort and the same ordered computation on normal return. Companion calls retain the original call identities for the QIEC address machine. No generated constructor or case allocates an address. The specialization erases handled requests, while requests reached after installation keep the same full addresses. Within an open region where branch choices stay fixed and the reached scalar primitives are differentiable, the source and staged computations apply the same local functions in order and thus have the same derivative.
Each reachable recursive callee has one companion per installation. For a fixed handler, construction uses space linear in the checked control graph and the declared result types. More generally, clause code copied at a request site costs its authored size. The construction budget counts emitted computation terms and added data declarations. The number of tags and case selections in a finite run is bounded by its reached terms and the number of call boundaries crossed on abort. For fixed state width, this adds linear work in the reached source control. Runtime fuel still bounds each run independently.
The shared state discharge represents the ordered state fields in one closed nominal record. Each generated projection reads its checked ordinal from that constructor. The pure helper applies the same transition before the next continuation, with no new dynamic frame. An unchanged state forwards the existing record. A grade-zero transition returns the abort answer and discards the continuation.
For \(n\) shared request sites, state width \(k\), \(r\) generated field reads, \(u\) written update operands, and \(b\) separately inlined ordinary branches, the added logical code size is \(O(n+k+r+u+kb)\). This counts each distinct shared definition once. Source origin paths and the byte width of names and types have separate encoding costs, and evaluating a changed record still requires evaluating its written fields.
8.3 Checking handler equations¶
An equation relates checked computations with the same input and result types. For the finite fragment, inputs range over Unit, Bool and their finite products. A continuation with argument carrier \(X\) and result carrier \(Y\) ranges over all \(|Y|^{|X|}\) total tables. The checker compares both results on every assignment before deciding equality. It returns a concrete assignment when the results differ. Reaching a work or execution limit leaves the equation undecided.
For supported scalar polynomial computations the checker compares exact rational coefficients. It checks definedness in the original source before normalizing a discharged computation, using the reached operands and original branch structure to derive its domain. For partial rational computations the checker also records all evaluated denominator guards. Equal normalized guard products certify the same domain. On that domain, the checker compares the polynomial obtained by cross-multiplying the two rational expressions and can exhibit a distinguishing assignment away from the guard zeros. The checker reports when it cannot establish that the domains agree. Effects API
Two independent tail-state handlers commute on returned values under an explicit product-state hypothesis. For a request at instance \(i\), write the clause as a pure transition \(S_i\times P\to S_i\times R\) followed by one tail resumption, with an identity return clause. Assume the two instances are distinct, the transitions read and update only their own state, and the handled computation has a finite tree of requests to those instances. Interpret the tree with paired state \((s_1,s_2)\). At a request to either instance, both installation orders perform the same transition on its component, leave the other component as it was, and continue with the same reply. Induction on the tree proves equality of the returned value. The finite interchange checker compares two named source trees on all admitted inputs. A separate example changes the returned value by exchanging a state handler with multi-shot choice. There, the first shot can update a store shared with the second, while separate captured stores retain their initial state. Finite handler interchange
The pure context operations use the cartesian adjunction
\(E\times(-)\dashv(E\to-)\) on the admitted ordinary values. Currying sends
\(f:E\times A\to B\) to \(a\mapsto(e\mapsto f(e,a))\), and uncurrying
applies this function at a pair \((e,a)\). The two substitutions cancel
pointwise, and composing in \(A\) or \(B\) commutes with the substitutions.
This gives the unit and counit equations for pure environments. Copying
an environment value uses the diagonal on \(E\) after the value has been
computed. A computation that reaches a Random request on each
resumption has the corresponding separate addresses and draws. Scoped proof execution
8.4 Superposition and trace completion¶
Let a finite choice \(z\) have weights \(w_z\), and let the associated kernels
on a common output space be \(\mu_z\). Superposition is the measure
\(\mu=\sum_z w_z\mu_z\). If the kernels have densities \(f_z\) relative to a
common reference measure, scoring a single draw at \(x\) uses
\(\log\sum_z w_z f_z(x)\) and records one Random address. An authored
clause that resumes twice gives each reached request its own
resumption ordinal. When those resumptions draw from independent
normals with fixed supplied locations, replay scores the product of
the two densities at their two addresses. This product is a density
on pairs. The clause's return map, such as a weighted arithmetic mean,
then determines the returned value.
A product-space completion extends a selected branch with an auxiliary kernel at each inactive site. For one auxiliary value \(y\), the extended mass is \(q_z f_z(x)g_z(y\mid x)\). Integration over \(y\) yields \(q_z f_z(x)\) when \(g_z(\cdot\mid x)\) has unit mass at every admitted \(x\). This equality is about the projection onto the original branch and its active value. A completed replay records the auxiliary addresses as well. The native worked example uses an explicit, normalized auxiliary kernel and checks this marginalization and its derivative. Superposition example
For a fixed addressed row replay, projection to one row commutes with each pure elementwise value operation. A declared nominal operation checks against a closed ordinary computation on those same values, so the commutation follows by induction on the operation body. The checked physical trace and scalar source traces agree on the order and identity of their observed requests. Each original Bernoulli request reads the Boolean from its own row tape, and each reached score adds its log factor on that row.
On a regular branch and with fixed tape answers, the chain rule gives the same directional action for each projected scalar output and request observation. The implementation compares actual binary64 results against independent source runs, keeping Bernoulli log probabilities, additive factor logs, and declared operation answers as distinct channels. It records each original address with its row coordinate. Row replay reference
8.5 Scalar derivatives and estimator hypotheses¶
For a checked scalar source execution, fix a point and a direction. If all reached comparisons are stable near that point and every reached primitive is differentiable there, the execution follows a finite sequence of primitive calls. The chain rule differentiates that sequence. A discarded continuation contributes no primitive calls. A clause that resumes several times passes each result to the enclosing computation, whose derivative combines those results by its own partial derivatives. The implemented exact scalar interpreters admit the listed rational primitives under their definedness conditions. They refuse an input-dependent comparison at equality when the chosen branch lacks a regularity certificate. A portable rational derivative declaration names its primal and actions. The checked interpreter verifies those actions throughout the primal rational domain before running them. Scalar reference and checked rules
The nominal forward handler compares the ground primals of its two operands. On a reached strict inequality, their difference is continuous on the preceding branch. The sign is constant on an open neighborhood of the input. Intersecting those neighborhoods for the finite executed path leaves an open neighborhood on which the selected expression applies. The handler's dual coefficients give the appropriate derivatives of that expression. A reached equality under a nominal strict comparison refuses. In the checked source interpreter, a comparison of identical checked arithmetic expressions in the same environment is locally constant wherever the expressions are defined. The interpreter evaluates both operands and checks their domains before applying this rule. Untaken branches impose no domain condition. Nominal forward differentiation
The same handler divides only at a nonzero ground divisor. Write the numerator and divisor as \(x_0+x_1\epsilon\) and \(y_0+y_1\epsilon\), with \(\epsilon^2=0\) and coefficients in the parent algebra. The quotient equation determines \(q_0=x_0/y_0\) and \(q_1=(x_1-q_0 y_1)/y_0\). Applying the equations at every layer gives all the ground coefficients and uses the same ground divisor at each step. Each reached nonzero condition also holds on an open neighborhood where the preceding rational expressions are defined. An unused quotient retains its domain check through discharge. Nominal forward differentiation
For analytic primitives, the boundary argument extends to almost-everywhere differentiability on the covered open domains. Fix a finite branch path and a connected region on which the preceding choices are stable and all reached expressions are analytic. The difference tested by the next guard is analytic there. An identically zero difference gives a constant ordinary guard. A nominal strict comparison refuses that equality. For a difference that is not identically zero, its zero set has measure zero. To see this, take a product box in the region and fix a last-coordinate slice on which the difference is nonzero somewhere. The analytic function on that slice has a null zero set by induction on dimension. Outside those exceptional first coordinates, the one-variable section is nonzero as an analytic function and has discrete zeros. Fubini's theorem gives the claim on the box. Countably many such boxes and finite branches preserve the null bound on the admitted domains.
For a finite adaptive computation, let \(h\) range over its complete addressed histories. Write \(m_h(\theta)\) for the product of the reached conditional probabilities, and \(L_h(\theta)\) for the returned scalar cost on that history. When the histories and the reached comparisons are locally stable, the directional derivative is
Enumeration evaluates this sum. A strictly positive Bernoulli site may use its score because \(D m_h=m_h D\log m_h\), and \(D\log m_h\) is the sum of the local log-probability derivatives over the reached sites. Writing a Bernoulli kernel as \((1-p)\delta_0+p\delta_1\) gives its weak action \((Dp)(\delta_1-\delta_0)\). Applying either identity at one node and inducting on the remaining finite tree gives the mean of the mixed estimator. This argument counts each reached score once and applies to linear combinations of outcomes. Finite site estimators
The scalar Normal fragment writes each draw as \(\mu+\sigma\epsilon\), with independent standard-normal seeds, positive noise-independent scales, and noise-independent comparisons. Along the admitted paths, the returned cost and its tangent are polynomials in the Gaussian seeds with locally regular rational coefficients. On a sufficiently small closed parameter neighborhood, the denominators on those paths are bounded away from zero. It follows that the absolute tangent is bounded by a polynomial in the absolute seed coordinates with finite Gaussian expectation. The dominated convergence argument permits differentiation under the Gaussian integral. Finite branching can condition this argument on each discrete history when its conditional probabilities are independent of the Gaussian noise. Mixed site estimators
8.6 Observed, intervened, and resampled finite laws¶
For a positive observed mass \(Z=\sum_h m_h L_h\), the derivative of \(\log Z\) is the posterior expectation of the complete-history log score \(D\log(m_h L_h)\). This follows by dividing the differentiated sum by \(Z\). With an addressed proposal mass \(q_h\), exact importance sampling returns an unbiased estimate of \(Z\) when \(q_h>0\) on every history with \(m_h L_h>0\). With the proposal held fixed, its raw estimate has derivative with expectation \(DZ\). A positive random estimate \(\widehat Z\) has \(\mathbb E[\log\widehat Z]\leq\log Z\) by Jensen's inequality, with equality only if it is constant almost surely. Finite marginalization and importance
Conditioning on an addressed draw restricts the original history sum and normalizes the restricted mass. Intervention fixes the draw and replaces that site's conditional probability by one in the history product. The conditional kernels and observation factors at its reachable descendants still contribute. The distinction changes both the value and its directional derivative in a confounded model. Finite observation and intervention
For conditionally independent multinomial resampling at \(k\) offspring slots, an ordered ancestry \(a=(a_1,\ldots,a_k)\) has conditional probability \(P(a)=\prod_i \pi_{a_i}\). Its score is \(D\log P(a)= \sum_i D\log\pi_{a_i}\) on the positive support. Distinct ancestors may have the same particle value, so the ancestry is a tuple of positions. The finite derivative evaluates both the score term and the derivative of the downstream cost at each ancestry. The finite Metropolis entry propagates the supplied initial law through the requested number of transitions and differentiates each matrix update. Its stopping count specifies the derivative being computed. Resampling and finite-step Metropolis derivatives
8.7 Finite selection¶
Consider an exact scalar entry that only writes loss and requests binary decisions. A leaf supplies its return and the sum of its loss writes. At a choice, the false and true subtrees supply their selected losses after any later choices. Adding the loss before the choice to both alternatives preserves their order. Thus backward induction on the finite tree implements the loss continuation at every choice and selects one return and one writer trace. For finitely many strict comparisons between locally continuous alternatives, the selected path is constant in a neighborhood of the input. Its return and loss derivatives then follow from the chain rule. At ties the optional false-first convention specifies a path tangent. Choice continuations and finite continuation selection.
For \(L\) complete alternatives, the explored tree has \(2L-1\) replay starts. With at most \(F\) source steps per replay and maximum choice depth \(D\), execution after source validation takes \(O(L(F+D))\) work in the bounded rational arithmetic model. Its replay tables store \(O(LD)\) choice-prefix entries measured in Boolean coordinates, and a single evaluator has at most \(O(F)\) live frames and addressed requests. The size of a rational coefficient affects arithmetic cost. Exact forward differentiation keeps one tangent per scalar and uses the same replay schedule. The path cap refuses before adding an alternative that exceeds it.
8.8 Limits of sampled and logarithmic representations¶
Suppose an estimator has access to an unknown probability \(p\) through at most \(n\) independent Bernoulli draws and may use independent auxiliary randomness. Assume its return has finite absolute expectation. Preallocate \(n\) draws and ignore the unused suffix if the estimator stops early. For each binary draw sequence \(b\), let \(a_b\) be the estimator's conditional mean over the auxiliary randomness, and let \(|b|\) count the ones. On \(0<p<1\) the expected estimate is the polynomial
For a Bernoulli draw the logarithm of its expectation is \(\log p\). Its derivative of order \(n+1\) is \((-1)^n n!/p^{n+1}\), which is nonzero throughout \((0,1)\). Thus a bounded-draw estimator with sampling-only access to the law cannot be unbiased for the logarithm of an expectation on an open interval of Bernoulli probabilities. A checked finite plan that enumerates a known law can compute the logarithm from the resulting positive mass.
A pointwise logarithmic weight also loses linear tangent information at zero. For \(w_a(t)=at\) with \(a>0\) and \(t\geq 0\), the stored logarithmic weight at \(t=0\) is \(-\infty\) for every \(a\), while the right derivative in linear coordinates is \(a\). Recovering this derivative requires information beyond the stored point value. The signed logarithmic dual carrier retains the tangent in its own lane even when the primal weight is zero.
For a fixed word with an acyclic productive Markov graph, the checked expected path cost and its right action use the raw binary64 weights, affine weight directions, and fixed initial, arc, and final costs. As these coordinates are dyadic, the algorithm can represent mass, cost-weighted mass, and their tangents as exact rationals. For incoming mass \(m\) and cost-weighted mass \(C\), an edge of weight \(w\) and cost \(c\) contributes \(wm\) and \(w(C+cm)\). The algorithm accumulates these contributions in topological order and differentiates their quotient at positive total mass. It rounds the resulting coordinates once to binary64 and refuses overflow or rounding a nonzero result to zero. Work is linear in the vertices and edges of the observed graph and in the size of the input weight and cost tables under unit-cost arithmetic. Rational numerators and denominators have separate bit costs. General reverse-mode rounding bounds for logarithmic elimination remain open. In the admitted finite path law, an initially zero accepting-path probability that grows to first order along the chosen ray contributes a Shannon entropy term of order \(-t\log t\), which precludes a finite right derivative.
8.9 Limits of finite elimination and stochastic environments¶
Unrestricted finite-factor elimination includes counting the satisfying assignments of a Boolean formula in conjunctive normal form. Take one Boolean variable per source variable. For each clause, take the factor with value one on its satisfying assignments and zero elsewhere. Multiply the factors using natural-number multiplication and sum over all variables. The product is the indicator of simultaneous clause satisfaction, so the returned scalar is the original count. For clauses of bounded size the tables have bounded size, and their number grows linearly with the formula. Any polynomial bound uniform over these graphs would thus give a polynomial algorithm for counting those assignments. The checked width bound depends on the elimination order.
For finite stochastic matrices, the ordinary environment functor \(E\times(-)\) has no right adjoint when \(|E|\geq 2\). Suppose it did, and fix the output object \(B=\{0,1\}\). At the one-point input, the adjunction would give a bijection from the product of \(|E|\) Bernoulli probability intervals to the probability simplex on the proposed right-adjoint object at \(B\). Naturality in the input would make this bijection affine. Take two one-point kernels as the columns of a two-point kernel, then precompose with a stochastic matrix that selects the columns with any prescribed probabilities. Both sides form the same convex combination through the bijection. The product of \(|E|\) intervals has dimension \(|E|\) and \(2^{|E|}\) extreme points. A simplex of dimension \(|E|\) has \(|E|+1\) extreme points. An affine bijection preserves both properties, which is impossible for \(|E|\geq 2\). The section's environment operations thus use the cartesian adjunction on values.
8.10 Limits of uniform checking and conditioning¶
In a language that can simulate arbitrary deterministic computations, treating such a simulation as a probability-one execution reduces the halting problem to almost-sure termination. The same simulation followed by a unit return is equivalent to a total fixed chain precisely when the simulation halts, if the observation is success and returned value and the simulation has no outward requests.
The problem of deciding whether a closed simple handler of type \(F\,0\) respects a given effect theory is \(\Pi_2\)-complete even for simple signatures, by Theorem 6.2 of Plotkin and Pretnar (Plotkin and Pretnar, 2013). The finite and arithmetic checkers in §8.3 have separate decision procedures with explicit domains.
Richardson’s Theorem One proves that the existence of an input with \(A(x)<0\) is undecidable for a class of exact one-variable expressions generated by rational constants, \(\pi\), \(\log 2\), sine, exponentiation \(\exp\), addition, subtraction, multiplication, and composition (Richardson, 1968). Extend the class with a second real variable and absolute value, and form
If \(A\) is everywhere nonnegative, \(H\) is identically zero. If \(A(x_0)<0\), the left and right partial derivatives in \(y\) at \((x_0,0)\) have opposite nonzero values. Thus a decision procedure for everywhere smoothness in the extended language would decide the original negativity problem.
On sets, the finite powerset monad, including the empty set, and the finitely supported probability-distribution monad admit no Beck distributive law in either direction, by Example 3.9 of Zwart and Marsden (Zwart and Marsden, 2022).
Ackerman, Freer, and Roy’s Theorem 7.6 constructs a computable joint law with no almost-everywhere computable conditional version in their representation. Their Corollary 8.5 rules out uniform conditioning even for the class of joint laws admitting everywhere-continuous conditional versions (Ackerman et al., 2019). For an explicit finite table and a positive normalizer, the checked conditional calculation in §8.6 uses finite summation and division.
8.11 Evidence passing¶
A clause \(\mathsf{op}(\bar x) \Rightarrow c_{\mathsf{op}}\) of a handler \(h\) with parameters \(\bar p\) is tail-resumptive when \(c_{\mathsf{op}}\) has grade \(1\), performs no request, and every path through it ends in \(\mathsf{resume}(u)\) with the parameters unchanged; write \(\hat c_{\mathsf{op}}\) for \(c_{\mathsf{op}}\) with each such \(\mathsf{resume}(u)\) replaced by \(\mathsf{return}\ u\). A handler is tail-resumptive when all its clauses are and its return clause makes no request (Xie et al., 2020; Xie and Leijen, 2021).
Proposition. Let \(h\) be tail-resumptive, and let \(\mathcal{E}\) contain no handler of \(i\) with a clause for \(\mathsf{op}\). Then
Proof sketch. By the second rule of §8.2 the left side reduces to \(c_{\mathsf{op}}[\bar v/\bar p, \bar w/\bar x]\) with the resumption bound to \(\mathsf{handle}\ i\ \mathsf{with}\ h(\bar v)\ \mathsf{in}\ \mathcal{E}[\mathsf{return}\ -]\). The clause performs no request, so it reduces to a value \(u\) by pure steps that do not depend on where it runs, and it then resumes exactly once in tail position with \(\bar v\), which yields \(\mathsf{handle}\ i\ \mathsf{with}\ h(\bar v)\ \mathsf{in}\ \mathcal{E}[\mathsf{return}\ u]\). The right side reaches the same term by the same pure steps inside \(\mathcal{E}\). \(\square\)
Applying the proposition at every request the handler answers, including the requests in the bodies of called computations, gives a computation with no request to \(i\); the installation then reduces to binding \(\bar p\) and applying the return clause. A called computation is specialized to the handler: its copy takes \(\bar v\) as extra arguments, so the rewriting needs no unrolling and terminates on recursive and data-dependent control. No continuation is captured. The inlined code allocates no call address, as a clause activation allocates none, and its calls advance the call counter as the clause's own calls do, so the outward requests of the installing computation keep their addresses. A specialized copy is entered under its own name, so the rewriting specializes only computations that make no outward request.
8.12 Lexically scoped instances and tunneling¶
Let \(g\) be a computation whose row has a tail \(\rho\) not declared to lack \(i\), and let \(g\) install a handler of \(i\) around a call or application \(c\) whose row reaches \(i\) only through \(\rho\). Under the rules of §8.2 that handler would answer a request \(c\) makes when a caller instantiates \(\rho\) with \(i\), so \(g\) would intercept a request it was not given. QIEC adds a term \(\mathsf{mask}\ i\ \mathsf{in}\ c\), under which a request to \(i\) skips the innermost handler of \(i\) installed outside the mask (Biernacki et al., 2020; Zhang and Myers, 2019):
is stuck at \(h\) and passes the request to the next handler of \(i\) outside, where \(\mathcal{E}'\) contains no mask of \(i\). Elaboration wraps \(c\) in one mask of \(i\) per handler of \(i\) that \(g\) installs around it. A mask's row records the explicit requests of its body under a derived identity \(i^{\uparrow}\), which the handler it skips does not discharge and which that handler's installation renames back to \(i\); a request through the tail stays in the tail.
Proposition (abstraction safety). Let \(g\) be well typed with masks inserted as above, and let two callers instantiate \(\rho\) with rows that differ only in requests to \(i\). Then no handler that \(g\) installs answers a request that reaches \(g\) through \(\rho\).
Proof sketch. A request reaching \(g\) through \(\rho\) is made inside some call or application \(c\) whose row reaches \(i\) only through \(\rho\). Every handler of \(i\) that \(g\) installs around \(c\) is matched by one mask of \(i\) around \(c\) inside it, and each mask skips exactly one handler, so the search from the request passes all of them. \(\square\)
The kernel rejects a body in which a handler of \(i\) surrounds such a \(c\) without a matching mask, and a call whose row names \(i\) explicitly and also reaches it through a tail that does not lack \(i\), where the two requests cannot be separated. Evidence passing pops one evidence frame per mask, so a mask over a tail-resumptive handler compiles away.
8.13 Local theories¶
An equation \(c_1 = c_2\) over an instance \(i\) declared without handlers is a local theory of \(i\) (Lukšič and Pretnar, 2020): it is a premise of the code that performs on \(i\), and every handler installed for \(i\) in the program must satisfy it. Each installed handler is checked by the method of §8.3. A counterexample refutes the handler at compile time; an equation outside the decidable fragment, or a check that exhausts its budget, is recorded as assumed for that handler. Handler correctness is undecidable in general (Plotkin and Pretnar, 2013), so an assumed law is a claim and not a result of the checker.
8.14 Control-flow linearity¶
A clause of grade \(1\) or \(\mathsf{aff}\) holds a one-shot resumption from the request it answers until it resumes. If, in that interval, it makes a request that a clause of grade \(\omega\) (or an interval with upper bound at least two) answers, each shot of that clause runs the rest of the one-shot clause, and every copy holds the same resumption (Tang et al., 2024). The kernel refuses a module in which two shots on one path of a multi-shot clause can each reach the one-shot clause's resumption.
The check follows the one-shot clause from each such request once per value the multi-shot clause resumes with. Values are evaluated where their operands are known constants; a branch whose condition is decided is followed alone, and an undecided branch is followed both ways. A request the continuation makes is followed into the clause that answers it, when that clause is known from the handlers installed around the one-shot handler (lexically or around the call that reaches it): a clause of grade \(0\) abandons the continuation, and any other clause continues it once per value it resumes with. A request whose answering clause is not known continues with an unknown value.
Proposition (soundness). If the kernel accepts a module, no run of it resumes a one-shot resumption more than once through a multi-shot handler.
Proof sketch. A one-shot resumption is resumed twice only if two copies of the rest of its clause reach the resumption, and copies arise only from the shots of a multi-shot clause answering a request made before the resumption. The analysis over-approximates the set of paths from that request: it follows every branch it cannot decide, treats every unknown value as possibly resuming, and drops a path only at a clause of grade \(0\), which never resumes, or at a branch decided by constants the run computes identically. So if two shots can reach the resumption in a run, the analysis counts both. \(\square\)
The check is incomplete: a value the analysis cannot evaluate may in fact send one shot away from the resumption, and such a module is refused.
8.15 Hefty elaboration¶
A higher-order operation takes computations as arguments, as local takes a function that changes
an environment and a computation to run under the changed one. If such an operation were handled
algebraically, its clause would run those computations where the handler is installed, outside the
handlers between the request and the handler. Following Bach Poulsen and van der Rest
(Bach Poulsen and van der Rest, 2023), a higher-order operation is instead elaborated before anything is handled: an
elaborator is an authored handler whose clauses each compute the result of one operation, may
perform the effects they introduce and apply the function arguments, and end by resuming once with
the result. Elaboration replaces every request \(\mathsf{perform}\ i.\mathsf{op}(\bar w)\) by the
clause's code with \(\bar w\) for its parameters and \(\mathsf{return}\) for its final
\(\mathsf{resume}\), at the request; in every row, \(i\) is replaced by the row the elaborator
introduces. The kernel types a request to an elaborated instance by that row, so handlers that a
computation installs for the introduced effects check before elaboration.
Elaborations are modular: each instance has its own elaborator, an elaborator's code may request another elaborated instance, whose request is elaborated in turn, and elaborations that introduce each other without end are refused. An elaborated instance is not handled.
8.16 Open proof obligations¶
The following claims remain open for the implemented system.
- Mechanized type soundness of the full indexed kernel and combination of free models with the recursive powerdomain.
- Composition of estimators for programs of unbounded depth, batching with data-dependent loops, and domination conditions for arbitrary registered families.
- First-class resumptions stored in values, scoped operations forwarded without elaboration, and differentiation of transdimensional kernels or of superpositions with different site sets.
- General rounding bounds for reverse logarithmic elimination and optimal interval ordering for noncommutative answers.
- Agreement between an external system’s derivative and the derivative claimed for the checked QIEC computation.
Cited sources¶
Dylan Bumford and Simon Charlow. Effect-Driven Interpretation: Functors for Natural Language Composition. Elements in Semantics. Cambridge University Press, forthcoming. ISBN 9781009285377. Forthcoming; publisher lists expected 2026 publication. Author preprint: arXiv:2504.00316. URL: https://www.cambridge.org/core/elements/abs/effectdriven-interpretation/56671E539160AAA1DACF8555B82A2FE4.
Simon Charlow. Static and dynamic exceptional scope. Journal of Semantics, 42(4):353–398, 2025. URL: https://academic.oup.com/jos/issue/42/4, doi:10.1093/jos/ffad012.
Gordon Plotkin and Matija Pretnar. Handlers of Algebraic Effects. In Programming Languages and Systems, volume 5502 of Lecture Notes in Computer Science, 80–94. Springer, 2009. URL: https://link.springer.com/chapter/10.1007/978-3-642-00590-9_7, doi:10.1007/978-3-642-00590-9_7.
Philip Wadler and Stephen Blott. How to Make Ad-Hoc Polymorphism Less Ad Hoc. In Proceedings of the 16th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL), 60–76. 1989. doi:10.1145/75277.75283.
Gordon Plotkin and John Power. Algebraic Operations and Generic Effects. Applied Categorical Structures, 11:69–94, 2003. URL: https://link.springer.com/article/10.1023/A:1023064908962, doi:10.1023/A:1023064908962.
Conor McBride and Ross Paterson. Applicative programming with effects. Journal of Functional Programming, 18(1):1–13, 2008. URL: https://www.cambridge.org/core/journals/journal-of-functional-programming/article/applicative-programming-with-effects/C80616ACD5687ABDC86D2B341E83D298, doi:10.1017/S0956796807006326.
Philip Wadler. The Essence of Functional Programming. In Proceedings of the 19th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 1–14. ACM, 1992. URL: https://doi.org/10.1145/143165.143169, doi:10.1145/143165.143169.
Jon Beck. Distributive Laws. In Seminar on Triples and Categorical Homology Theory, Lecture Notes in Mathematics, pages 119–140. Springer, 1969. doi:10.1007/BFb0083084.
G. D. Plotkin. LCF Considered as a Programming Language. Theoretical Computer Science, 5(3):223–255, 1977. doi:10.1016/0304-3975(77)90044-5.
Wouter Swierstra. Data Types à la Carte. Journal of Functional Programming, 18(4):423–436, 2008. doi:10.1017/S0956796808006758.
John Hughes. Generalising Monads to Arrows. Science of Computer Programming, 37(1–3):67–111, 2000. URL: https://www.sciencedirect.com/science/article/pii/S0167642399000234, doi:10.1016/S0167-6423(99)00023-4.
Andrej Bauer and Matija Pretnar. Programming with Algebraic Effects and Handlers. Journal of Logical and Algebraic Methods in Programming, 84(1):108–123, 2015. URL: https://www.sciencedirect.com/science/article/pii/S2352220814000194, doi:10.1016/j.jlamp.2014.02.001.
Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. Binders by Day, Labels by Night: Effect Instances via Lexically Scoped Handlers. Proceedings of the ACM on Programming Languages, 4(POPL):1–29, 2020. doi:10.1145/3371116.
Daan Leijen. Koka: Programming with Row Polymorphic Effect Types. In Proceedings of the 5th Workshop on Mathematically Structured Functional Programming (MSFP), volume 153 of Electronic Proceedings in Theoretical Computer Science, 100–126. 2014. doi:10.4204/EPTCS.153.8.
Daniel Hillerström and Sam Lindley. Liberating Effects with Rows and Handlers. In Proceedings of the 1st International Workshop on Type-Driven Development (TyDe), 15–27. 2016. doi:10.1145/2976022.2976033.
Ohad Kammar, Sam Lindley, and Nicolas Oury. Handlers in Action. In Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming (ICFP), 145–158. 2013. doi:10.1145/2500365.2500590.
Adam Ścibior, Ohad Kammar, and Zoubin Ghahramani. Functional Programming for Modular Bayesian Inference. Proceedings of the ACM on Programming Languages, 2(ICFP):83:1–83:29, 2018. URL: https://doi.org/10.1145/3236778, doi:10.1145/3236778.
Minh Nguyen, Roly Perera, Meng Wang, and Steven Ramsay. Effect Handlers for Programmable Inference. In Proceedings of the 16th ACM SIGPLAN International Haskell Symposium. ACM, 2023. URL: https://doi.org/10.1145/3609026.3609729, doi:10.1145/3609026.3609729.
Daan Leijen. Type Directed Compilation of Row-Typed Algebraic Effects. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL), 486–499. 2017. doi:10.1145/3009837.3009872.
Gordon D. Plotkin and Matija Pretnar. Handling Algebraic Effects. Logical Methods in Computer Science, 9(4):23:1–23:36, 2013. doi:10.2168/LMCS-9(4:23)2013.
Daniel Richardson. Some Undecidable Problems Involving Elementary Functions of a Real Variable. The Journal of Symbolic Logic, 33(4):514–520, 1968. doi:10.2307/2271358.
Maaike Zwart and Dan Marsden. No-Go Theorems for Distributive Laws. Logical Methods in Computer Science, 18(1):13:1–13:61, 2022. doi:10.46298/lmcs-18(1:13)2022.
Nathanael L. Ackerman, Cameron E. Freer, and Daniel M. Roy. On the Computability of Conditional Probability. Journal of the ACM, 66(3):23:1–23:40, 2019. doi:10.1145/3321699.
Ningning Xie, Jonathan Immanuel Brachthäuser, Daniel Hillerström, Philipp Schuster, and Daan Leijen. Effect Handlers, Evidently. Proceedings of the ACM on Programming Languages, 2020. doi:10.1145/3408981.
Ningning Xie and Daan Leijen. Generalized Evidence Passing for Effect Handlers: Efficient Compilation of Effect Handlers to C. Proceedings of the ACM on Programming Languages, 2021. doi:10.1145/3473576.
Yizhou Zhang and Andrew C. Myers. Abstraction-Safe Effect Handlers via Tunneling. Proceedings of the ACM on Programming Languages, 2019. doi:10.1145/3290318.
Žiga Lukšič and Matija Pretnar. Local Algebraic Effect Theories. Journal of Functional Programming, 2020. doi:10.1017/S0956796819000212.
Wenhao Tang, Daniel Hillerström, Sam Lindley, and J. Garrett Morris. Soundly Handling Linearity. Proceedings of the ACM on Programming Languages, 2024. doi:10.1145/3632896.
Casper Bach Poulsen and Cas van der Rest. Hefty Algebras: Modular Elaboration of Higher-Order Algebraic Effects. Proceedings of the ACM on Programming Languages, 2023. doi:10.1145/3571255.