On Complete Categorical Semantics for Effect Handlers
Soundness and completeness with respect to equational theories for programming languages are fundamental properties in the study of categorical semantics. However, completeness results have not been established for programming languages with algebraic effects and handlers, which raises a question of whether the commonly used models in the literature, i.e., free model monads generated from algebraic theories, are the only valid semantic models for effect handlers. In this paper, we show that this is not the case. We identify the precise characterizations of categorical models of effect handlers that allow us to establish soundness and completeness results with respect to a certain equational theory for effect handling constructs. Notably, this allows us to capture not only free monad models but also the CPS semantics for effect handlers as models of the calculus.
💡 Research Summary
The paper addresses a fundamental gap in the categorical semantics of programming languages that support algebraic effects and effect handlers. While soundness (every syntactically provable equation holds semantically) is well‑studied, completeness (every semantically valid equation is provable) has never been established for effect‑handler calculi. Consequently, the community has implicitly assumed that the only adequate categorical models are free model monads generated from algebraic theories (or equivalently Lawvere theories). The authors challenge this assumption by showing that other well‑known models, notably continuation‑passing‑style (CPS) semantics, also satisfy the desired properties.
The central technical contribution is the introduction of a family of morphisms, written as
handle Σ, C : H(Σ; ⟦C⟧) × T_Σ⟦C⟧ → ⟦C⟧
where Σ is a signature of operations, C is a result type, T_Σ is a strong monad indexed by Σ, and H(Σ; ⟦C⟧) denotes the object interpreting handlers for Σ with result type C. This morphism abstracts the “handle‑with” construct and replaces the ad‑hoc use of free monads. The authors impose four natural conditions on handle Σ, C: (1) it respects the return clause (Handle‑Ret), (2) it commutes with let‑bindings (Handle‑Let), (3) it correctly dispatches operation calls to the corresponding handler clause (Handle‑Op), and (4) it preserves the monad unit and multiplication laws. Under these constraints, the interpretation of any program term respects the equational theory defined for effect handlers.
Two calculi are considered. The first, λê, is a simply‑typed deep‑handler calculus without any equational axioms attached to the signature. Its types are values A, computations A ! Σ, and handlers Σ ⇒ C. The second calculus extends λê by allowing a set E of equations on the operations of Σ, following the approach of Plotkin and Pretnar. For the latter, the handle Σ, C morphism is defined only for handlers that satisfy the equations in E, which requires a more delicate construction but yields the same soundness and completeness results.
The authors then demonstrate that both free monad models and CPS models are instances of their abstract framework. In the free monad case, H(Σ; ⟦C⟧) consists of raw handler clauses, and handle Σ, C reduces to the usual monadic bind combined with pattern matching on operation symbols. In the CPS case, the underlying monad is the continuation monad K_R X = (R → X); handlers become continuation‑transforming functions, and handle Σ, C corresponds to the standard CPS translation of effect handling. This shows that the previously “non‑canonical” CPS semantics satisfies the same completeness theorem, disproving the belief that only free monads are complete models.
Finally, the paper outlines future work on “brational” logical relations (∗‑lifting) for effect handlers. By providing a flexible notion of model, the authors anticipate that existing techniques for lifting logical relations along fibrations can be adapted to the effect‑handler setting, potentially yielding new reasoning principles for program equivalence.
In summary, the paper delivers the first sound and complete categorical semantics for a simply‑typed deep effect‑handler calculus, proves that the semantics subsumes both free‑monad and CPS models, and extends the results to calculi with equational axioms. This establishes a robust theoretical foundation for reasoning about effect handlers and opens avenues for advanced logical‑relation techniques.
Comments & Academic Discussion
Loading comments...
Leave a Comment