---
title: Categorical Models of Effect Handlers
url: https://www.emergentmind.com/topics/categorical-models-of-effect-handlers
type: topic
---

# Categorical Models of Effect Handlers

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 $\mathit{op} \in \text{Op}$, each with a parameter type $A$ and arity type $B$, typically in $\text{Set}$ or a suitable category. An equational theory $T$ over Σ consists of equations between Σ-terms, e.g., commutativity of $\mathit{choose}$ for nondeterminism or read/write equations for state. The pair $(\Sigma,T)$ presents the algebraic theory of a computational effect [1312.1399], [1203.1539].

A Σ-algebra (a model of $(\Sigma,T)$) is a set $M$ equipped with operations
\[
\op_M : A \times M^B \to M
\]
for each $\mathit{op}:A \to B$, satisfying the equations of $T$. The category of Σ-algebras, $\mathsf{Mod}(\Sigma,T)$, and corresponding forgetful functor $U: \mathsf{Mod}(\Sigma,T) \to \text{Set}$, admit a left adjoint $F:\text{Set} \to \mathsf{Mod}(\Sigma,T)$. The induced monad $T := U \circ F$ on $\text{Set}$ consists of
\[
\eta_X : X \to T X,\qquad \mu_X : T^2 X \to T X
\]
satisfying the monad laws. Here, $T X$ is the set of Σ-terms (i.e., computations) over $X$, modulo the equations of $T$ [1312.1399], [1203.1539].

## 2. Effect Handlers as Algebra Homomorphisms

A (closed) effect handler with result type $R$ is a Σ-algebra structure on $R$, i.e., for every operation $\mathit{op}:A \to B$, a map
\[
\op_R : A \times R^B \to R
\]
that solves the theory $T$. For any $X$, any map $f:X \to R$ extends uniquely to a Σ-homomorphism
\[
\sharp f : F X \to R
\]
making the following triangle commute:
\[
\begin{diagram}
X & \rTo^{\eta_X} & T X \\
& \rdTo_{f} & \dDotsto_{\sharp f} \\
& & R
\end{diagram}
\]
In computational terms, $\eta_X$ is a pure computation, and $\sharp f$ interprets the handling construct: for a computation in $T X$ and a handler $R$, $\sharp f$ evaluates the computation under the handler, returning a value in $R$ [1312.1399], [1203.1539].

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 [1203.1539].

## 3. Soundness, Completeness, and the Equational Theory

For a programming language with algebraic effects and handlers, categorical models are formulated as strong monads $(T, \eta, \mu, \mathsf{str})$ on a cartesian category $\mathcal{C}$, equipped with algebraic operation interpretations and a family of handler maps
\[
\mathbf{handle}_{\Sigma, \Sigma', X}: \mathcal{H}(\Sigma, X) \times T_\Sigma X \to X
\]
where $\mathcal{H}(\Sigma, X)$ is the product of all handler-clause objects on $X$.

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 $M = N$ 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 $M=N$ is derivable in the theory [2602.03275].

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 [2602.03275].

## 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 $S$ [2212.07015]. In this setting:
- An $S$-graded signature $\Sigma$ has operations
  \[
  \sigma : P \to A; f \in \Sigma
  \]
  with parameters, arities, and grades $f: c \to b$.
- Terms, operations, equations, and models are organized according to $S$.
- The free $S$-graded monad $T^\TT$ is a lax functor $S^{op} \to [\Set, \Set]$.
- 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) [2212.07015].

### Scoped (Functorial Algebra) Models

Effects with non-algebraic properties, such as delimited scopes, are modeled using pairs of functors $\Sigma, \Gamma : \mathcal{C}\to\mathcal{C}$ for algebraic and scoped operations, respectively [2201.10287]. The resulting category of functorial algebras, built from the "grammar functor" $G K = \text{Id} + \Sigma K + \Gamma(K\circ K)$, provides a categorical environment for both algebraic and scoped handlers. This model admits an adjunction $L \dashv R$ and comes with fusion laws for composing handlers, guaranteeing the modularity and compositionality of handler application [2201.10287].

### 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 [2602.03275]. 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 $\mathit{raise}_e:1\to 0$ for each $e$, leading to handlers as case analysis.
- **State**: Operations like $\mathit{get}: L \to \mathbb{N}$, $\mathit{set}:L\times\mathbb{N}\to 1$; handlers encode state passing.
- **I/O**: Operations $\mathit{read}:1\to \text{Char}$, $\mathit{write}:\text{Char}\to 1$; 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 [1312.1399].

The modular structure is made explicit in categories of functorial algebras and in the fusion laws of handler application [2201.10287]. 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 [2602.03275]. 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 [2212.07015]. Functorial algebra models admit concise semantics for scope-delimiting effects, with equivalence results ensuring parity in expressive power with indexed and EM algebra models [2201.10287].

Categorical theorems such as the existence and uniqueness of handlers, their compositionality, and the duality of effect construction and deconstruction, are central structural results [1312.1399]. 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              | [1312.1399] [1203.1539] |
| Category-graded monad           | Lax functors $S^{op} \to [\Set,\Set]$        | [2212.07015]            |
| Functorial/scoped algebra       | Grammar endofunctor $G$ and adjunction $L\dashv R$ | [2201.10287]            |
| CPS semantics                   | Polymorphic continuation objects $D_\Sigma X$ | [2602.03275]            |

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.

Source: https://www.emergentmind.com/topics/categorical-models-of-effect-handlers