States and exceptions considered as dual effects

States and exceptions considered as dual effects
Notice: This research summary and analysis were automatically generated using AI technology. For absolute accuracy, please refer to the [Original Paper Viewer] below or the Original ArXiv Source.

In this paper we consider the two major computational effects of states and exceptions, from the point of view of diagrammatic logics. We get a surprising result: there exists a symmetry between these two effects, based on the well-known categorical duality between products and coproducts. More precisely, the lookup and update operations for states are respectively dual to the throw and catch operations for exceptions. This symmetry is deeply hidden in the programming languages; in order to unveil it, we start from the monoidal equational logic and we add progressively the logical features which are necessary for dealing with either effect. This approach gives rise to a new point of view on states and exceptions, which bypasses the problems due to the non-algebraicity of handling exceptions.


💡 Research Summary

The paper investigates the two fundamental computational effects—mutable state and exceptions—from a categorical perspective, revealing a deep symmetry between them that stems from the classic product–coproduct duality. Starting from Moggi’s monadic semantics, the authors model state as a monad T A = (A × S) S and exceptions as T A = A + E, but they note that the monadic treatment of exception handling (the “handle” operation) is not algebraic, which makes formal reasoning difficult.

In the first technical section the authors give a concrete denotational semantics for state. A set of states St is equipped with, for each location i, a lookup function lᵢ : St → Valᵢ and an update function uᵢ : Valᵢ × St → St. They list seven elementary equations (annihilation, interaction, commutation) that capture the algebraic behaviour of these operations. The product × underlies the state structure, and the equations are shown to be observationally equivalent to the usual co‑inductive definition of updates.

The second technical section mirrors the first for exceptions. A set Exc of exceptions and a set of constructors i with parameter types Parᵢ are introduced. The key “throw” function tᵢ : Parᵢ → Exc turns a non‑exceptional value into an exception; the raise operation raiseᵢ,Y = inr ∘ tᵢ injects the exception into the sum Y + Exc. Propagation of exceptions is defined as the identity on Exc, and handling is modelled as a chain of catch clauses, each of which matches an exception constructor and applies a handler gᵢ. The authors give an explicit functional description of the try‑catch construct that works both as a function X → Y + Exc and as a total function X + Exc → Y + Exc.

To relate the two effects, the authors adopt the framework of diagrammatic logics. They start from a minimal monadic equational logic and build three related logics: (1) an explicit logic that contains the concrete sets St and Exc, (2) an apparent logic that hides these sets and presents only the operations, and (3) a decorated logic that annotates each syntactic term with a “decoration” indicating whether it reads, writes, throws, or catches. Morphisms between these logics preserve the decorations, allowing a systematic translation from concrete semantics to abstract syntax and back.

The crucial observation is that the lookup lᵢ and update uᵢ operations correspond categorically to the coproduct injections inl and inr, while the throw tᵢ and catch operations correspond to the product projections. Thus the product–coproduct duality yields a direct duality between state and exception primitives. This duality is first proved at the semantic level (Proposition 1.6) and then lifted to the syntactic level (Theorem 5.1), showing that the same categorical symmetry underlies both the denotational models and the programming language constructs.

A significant technical contribution is the handling of the non‑algebraic nature of exception handling. By encapsulating the “catch” operation inside conditionals in the decorated logic, the authors turn it into an algebraic operation, thereby fitting it into the same equational framework as state updates. This resolves the difficulty identified by Plotkin & Power (2003) regarding the algebraicity of exception handling.

The paper concludes with an appendix that proves the basic properties of the decorated logic for both effects, confirming that the equations listed for state and the propagation/handling equations for exceptions are sound in the decorated setting. Overall, the work provides a unified categorical account of state and exceptions, demonstrating that they are not merely distinct side‑effects but two facets of a single dual structure. This perspective opens the way to more systematic reasoning about programs that combine both effects and suggests that other computational effects might also be organized via similar categorical dualities.


Comments & Academic Discussion

Loading comments...

Leave a Comment