Categorical Models of Effect Handlers
- Categorical models of effect handlers are algebraic frameworks that express, combine, and analyze computational effects using monads and equational theories.
- They formalize effect handlers as algebra homomorphisms, ensuring soundness and completeness through universal categorical properties.
- Recent developments extend these models to graded and scoped effects while integrating CPS semantics to handle complex effectful computations.
A categorical model of effect handlers provides a precise, algebraic foundation for expressing, combining, and analyzing computational effects and their deconstruction via handlers in programming languages. Grounded in the theory of monads, algebraic theories, and categorical semantics, these models accurately capture a wide range of effects—such as exceptions, state, nondeterminism, and I/O—through equational presentations, and give effect handlers the status of algebra homomorphisms, with rigorous universal properties, soundness, and completeness theorems. Recent developments include deep analyses of completeness, enrichment to handle scoped and graded effects, and the precise categorical characterization of both the canonical free-model and continuation-passing-style (CPS) semantics.
1. Signatures, Equational Theories, and the Algebraic Monad
An algebraic effect is specified by a signature Σ, a set of operation symbols , each with a parameter type and arity type , typically in or a suitable category. An equational theory over Σ consists of equations between Σ-terms, e.g., commutativity of for nondeterminism or read/write equations for state. The pair presents the algebraic theory of a computational effect (Plotkin et al., 2013, Bauer et al., 2012).
A Σ-algebra (a model of ) is a set equipped with operations
$\op_M : A \times M^B \to M$
for each , satisfying the equations of . The category of Σ-algebras, , and corresponding forgetful functor , admit a left adjoint . The induced monad on consists of
satisfying the monad laws. Here, is the set of Σ-terms (i.e., computations) over , modulo the equations of (Plotkin et al., 2013, Bauer et al., 2012).
2. Effect Handlers as Algebra Homomorphisms
A (closed) effect handler with result type is a Σ-algebra structure on , i.e., for every operation , a map
$\op_R : A \times R^B \to R$
that solves the theory . For any , any map extends uniquely to a Σ-homomorphism
making the following triangle commute: $\begin{diagram} X & \rTo^{\eta_X} & T X \ & \rdTo_{f} & \dDotsto_{\sharp f} \ & & R \end{diagram}$ In computational terms, is a pure computation, and interprets the handling construct: for a computation in and a handler , evaluates the computation under the handler, returning a value in (Plotkin et al., 2013, Bauer et al., 2012).
Handlers thus mediate between the free model (the syntax of computations) and models (instructions for deconstructing computations). The handler is uniquely determined by its behavior on variables and by satisfying the algebra laws—semantically, it is a homomorphism from the free Σ-algebra to the handler algebra (Bauer et al., 2012).
3. Soundness, Completeness, and the Equational Theory
For a programming language with algebraic effects and handlers, categorical models are formulated as strong monads on a cartesian category , equipped with algebraic operation interpretations and a family of handler maps
where is the product of all handler-clause objects on .
The semantics must satisfy three core diagrams:
- handle-unit: Handling a pure computation yields the value.
- handle-mult: Handling the result of joining computations is the same as joining the handled results.
- handle-op: Handling an operation processes it using the corresponding handler clause.
These directly correspond to the following equational laws on terms:
- $\handlewithto{\return{V}}{H}{x}{N} = N[V/x]$
- $\handlewithto{\mathsf{let}\;x=L\;\mathsf{in}\;M}{H}{y}{N} = \handlewithto{L}{H}{x}{\handlewithto{M}{H}{y}{N}}$
- $\handlewithto{\mathit{op}(V)}{H}{x}{N} = M_\mathit{op}[V/x, \lambda v. N[v/x]/k]$
Soundness theorem: If is derivable in the equational theory, then their interpretations coincide in every categorical model of handlers.
Completeness theorem: If for all models, $\interpret{M} = \interpret{N}$, then is derivable in the theory (Kura, 3 Feb 2026).
These results demonstrate that the categorical structure, characterized by strong monads and handler maps satisfying the three diagrams, precisely captures the computation laws of effect handlers (Kura, 3 Feb 2026).
4. Variations: Graded, Scoped, and CPS Models
Category-Graded Algebraic Theories
Category-graded effect theories generalize algebraic signatures by indexing operations and equations over morphisms in a grading category (Sanada, 2022). In this setting:
- An -graded signature has operations
with parameters, arities, and grades .
- Terms, operations, equations, and models are organized according to .
- The free -graded monad $T^\TT$ is a lax functor .
- A handler is a lax natural transformation matching the grading structure, subject to algebra laws.
This captures effect systems where, for example, stateful protocols or effect dependencies follow categorical structure (e.g., session types) (Sanada, 2022).
Scoped (Functorial Algebra) Models
Effects with non-algebraic properties, such as delimited scopes, are modeled using pairs of functors for algebraic and scoped operations, respectively (Yang et al., 2022). The resulting category of functorial algebras, built from the "grammar functor" , provides a categorical environment for both algebraic and scoped handlers. This model admits an adjunction and comes with fusion laws for composing handlers, guaranteeing the modularity and compositionality of handler application (Yang et al., 2022).
Continuation-Passing-Style (CPS) Semantics
In addition to the canonical free-model monad semantics, categorical completeness theorems recognize the continuation-passing-style (CPS) model for effect handlers. In this model, computations are represented by types of the form
$D_\Sigma X = \forall \beta.\, (X \to \beta) \to \left(\prod_{\op \in \Sigma}(A_\op \times (B_\op \to \beta) \to \beta)\right) \to \beta$
with handling done by continuation-passing closure (Kura, 3 Feb 2026). This substantiates the expressiveness of CPS as a model of computational effects with handlers, not just free-model monads.
5. Examples and Modularity of Handlers
Concrete algebraic signatures model effects such as:
- Exceptions: Nullary operations for each , leading to handlers as case analysis.
- State: Operations like , ; handlers encode state passing.
- I/O: Operations , ; handlers structure side-effects such as logging.
Handlers for effect combinations are formed as coproducts (sum signatures), allowing effects to be combined and handled modularly. Handler composition corresponds to algebra homomorphism composition, supporting "stacking" of handlers (Plotkin et al., 2013).
The modular structure is made explicit in categories of functorial algebras and in the fusion laws of handler application (Yang et al., 2022). All handler constructions conform to the categorical universality property, ensuring uniform extensibility.
6. Contemporary Developments and Theoretical Scope
Recent work has formalized the full soundness and completeness of categorical models for handlers relative to syntactic calculi with algebraic effects and handlers (Kura, 3 Feb 2026). This result ensures that all models satisfying the core diagrams—including both classic free-model (Plotkin–Power) and CPS models—are valid for interpreting effectful programs with handlers.
Advancements in category-graded and scoped effect theories further generalize the expressivity of algebraic models. For example, CatEff’s grading by morphisms supports refined effect protocols and dependency tracking at the semantic level (Sanada, 2022). Functorial algebra models admit concise semantics for scope-delimiting effects, with equivalence results ensuring parity in expressive power with indexed and EM algebra models (Yang et al., 2022).
Categorical theorems such as the existence and uniqueness of handlers, their compositionality, and the duality of effect construction and deconstruction, are central structural results (Plotkin et al., 2013). The formalism accommodates variants—including those with stronger typing disciplines or modular effect systems—by varying the ambient category or the structure of the algebraic or graded theory.
7. Table: Summary of Categorical Models of Effect Handlers
| Model Type | Key Construction | Notable References |
|---|---|---|
| Free-model monad | Initial Σ-models via adjunction | (Plotkin et al., 2013, Bauer et al., 2012) |
| Category-graded monad | Lax functors | (Sanada, 2022) |
| Functorial/scoped algebra | Grammar endofunctor and adjunction | (Yang et al., 2022) |
| CPS semantics | Polymorphic continuation objects | (Kura, 3 Feb 2026) |
The landscape of categorical models for effect handlers includes monadic, graded, and continuation-based approaches. All are governed by universal properties and categorical laws ensuring soundness and completeness, and they support modular reasoning about computations with algebraic and scope-delimited effects.