What Monads Can and Cannot Do with a Few Extra Pages
Møgelberg, Zwart
The delay monad provides a way to introduce general recursion in type theory. To write programs that use a wide range of computational effects directly in type theory, we need to combine the delay monad with the monads of these effects. Here we present a first systematic study of such combinations.
We study both the coinductive delay monad and its guarded recursive cousin, giving concrete examples of combining these with well-known computational effects. We also provide general theorems stating which algebraic effects distribute over the delay monad, and which do not. Lastly, we salvage some of the impossible cases by considering distributive laws up to weak bisimilarity.
academic
What Monads Can and Cannot Do with a Few Extra Pages
The delay monad provides a method for introducing general recursion in type theory. To write programs directly in type theory that use a wide range of computational effects, we need to combine the delay monad with monads for these effects. This paper presents the first systematic study of such combinations. The article investigates both the coinductive delay monad and its guarded recursive variant, providing concrete examples of combining these monads with well-known computational effects. Additionally, it provides general theorems characterizing which algebraic effects distribute over the delay monad and which do not. Finally, some impossible cases are rescued by considering distributive laws under weak bisimulation.
Problem to be Solved: Martin-Löf type theory requires all programs to terminate to preserve the correctness of logical interpretation, yet practical programming requires general recursion. The delay monad addresses this through encapsulating recursion, but lacks a theory for systematically combining the delay monad with other computational effects.
Problem Significance: Modern functional programming languages must handle multiple computational effects (exceptions, state, nondeterminism, etc.). Direct programming and reasoning about these effects in type theory requires a mathematical theory describing the interaction between the delay monad and other monads.
Limitations of Existing Approaches:
Lack of systematic study of combining the delay monad with other monads
Related results from domain theory are too complex for type-theoretic settings
Certain combinations (e.g., finite powerset monad) are known to be infeasible, but lack general theory
No principled method to determine which combinations are possible
Research Motivation: Establish a complete mathematical theory of combining the delay monad with other computational effects, providing theoretical foundations for advanced functional programming in type theory.
Systematic Study Framework: First systematic investigation of combining the delay monad with other monads, covering both coinductive and guarded recursive variants.
Concrete Combination Examples: Demonstrates concrete ways to combine the delay monad with standard computational effects (exceptions, reader, global state, continuations, choice).
General Theorems on Distributive Laws:
Proves that sequential distribution works for algebraic monads with balanced equations
Proves that monads with commutative idempotent operations admit no distributive law
Establishes correspondence between equation types and existence of distributive laws
Weak Bisimulation Theory: By working in the category of sets, proves that distributive laws can be constructed for algebraic monads without discarding equations under weak bisimulation.
Formal Verification: Partially formalizes results in Agda, providing verifiable implementations.
Study the existence of distributive laws TD → DT, where T is an arbitrary monad and D is the delay monad. A distributive law distributes the operations of T over computational steps, giving the composite DT a monad structure.
Guarded Recursive Encoding: Uses multi-clock guarded recursion to encode coinductive types as ∀κ.D^κX, avoiding continuity requirements.
Distributive Law Equivalence: Establishes a bijection between distributive laws and monad liftings in the Eilenberg-Moore category (Theorem 2.12).
Equation-Driven Analysis: Predicts existence of distributive laws through equation types of algebraic theories, providing a systematic analytical framework.
Weak Bisimulation Category: Works in the category of sets to handle quotient structures, overcoming technical difficulties of directly quotienting the delay monad.
This paper cites 69 important references spanning multiple domains including type theory, category theory, and computational effects, particularly foundational works such as Beck (1969)'s distributive law theory, Capretta (2005)'s delay monad, and Nakano (2000)'s guarded recursion.