Reference. Structured Handling of Scoped Effects
Algebraic effects offer a versatile framework that covers a wide variety of effects. However, the family of operations that delimit scopes are not algebraic and are usually modelled as handlers, thus preventing them from being used freely in conjunction with algebraic operations. Although proposals for scoped operations exist, they are either ad-hoc and unprincipled, or too inconvenient for practical programming. This paper provides the best of both worlds: a theoretically-founded model of scoped effects that is convenient for implementation and reasoning. Our new model is based on an adjunction between a locally finitely presentable category and a category of functorial algebras . Using comparison functors between adjunctions, we show that our new model, an existing indexed model, and a third approach that simulates scoped operations in terms of algebraic ones have equal expressivity for handling scoped operations. We consider our new model to be the sweet spot between ease of implementation and structuredness. Additionally, our approach automatically induces fusion laws of handlers of scoped effects, which are useful for reasoning and optimisation.
Cite
Cited by (6)
Modular models of monoids with operations by lifting functors along fibrations yang-2026-modular
Inspired by Plotkin and Power’s algebraic treatment of computational effects and the principle of notions of computations as monoids, we propose a categorical framework for equational theories and models of monoids equipped with operations. This framework generalises Plotkin and Power’s algebraic treatment of effectful operations taking or returning values as input or output to operations that may take or return computations as input or output. Additionally, to give semantic models of computational effects in a modular way, we introduce a formal theory of modular constructions of algebraic structures based on the framework of lifting functors along fibrations.
Handling Higher-Order Effectful Operations with Judgemental Monadic Laws yang-2026-handling
This paper studies the design of programming languages with handlers of higher-order effectful operations - effectful operations that may take in computations as arguments or return computations as output. We present and analyse a core calculus with higher-kinded impredicative polymorphism, handlers of higher-order effectful operations, and optionally general recursion. The distinctive design choice of this calculus is that handlers are carried by lawless raw monads, while the computation judgements still satisfy the monadic laws judgementally. We present the calculus with a logical framework and give denotational models of the calculus using realizability semantics. We prove closed-term canonicity and parametricity for the recursion-free fragment of the language using synthetic Tait computability and a novel form of the ⊤⊤-lifting technique.
Scoped Effects, Scoped Operations, and Parameterized Algebraic Theories matache-2025-scoped
Notions of computation can be modeled by monads. Algebraic effects offer a characterization of monads in terms of algebraic operations and equational axioms, where operations are basic programming features, such as reading or updating the state, and axioms specify observably equivalent expressions. However, many useful programming features depend on additional mechanisms such as delimited scopes or dynamically allocated resources. Such mechanisms can be supported via extensions to algebraic effects including scoped effects and parameterized algebraic theories . We present a fresh perspective on scoped effects by translation into a variation of parameterized algebraic theories. The translation enables a new approach to equational reasoning for scoped effects and gives rise to an alternative characterization of monads in terms of generators and equations involving both scoped and algebraic operations. We demonstrate the power of our approach by way of equational characterizations of several known models of scoped effects.
Algebraic Effects Meet Hoare Logic in Cubical Agda kidney-2024-algebraic
This paper presents a novel formalisation of algebraic effects with equations in Cubical Agda. Unlike previous work in the literature that employed setoids to deal with equations, the library presented here uses quotient types to faithfully encode the type of terms quotiented by laws. Apart from tools for equational reasoning, the library also provides an effect-generic Hoare logic for algebraic effects, which enables reasoning about effectful programs in terms of their pre- and post-conditions. A particularly novel aspect is that equational reasoning and Hoare-style reasoning are related by an elimination principle of Hoare logic.
Scoped Effects as Parameterized Algebraic Theories lindley-2024-scoped
Notions of computation can be modelled by monads. Algebraic effects offer a characterization of monads in terms of algebraic operations and equational axioms, where operations are basic programming features, such as reading or updating the state, and axioms specify observably equivalent expressions. However, many useful programming features depend on additional mechanisms such as delimited scopes or dynamically allocated resources. Such mechanisms can be supported via extensions to algebraic effects including scoped effects and parameterized algebraic theories . We present a fresh perspective on scoped effects by translation into a variation of parameterized algebraic theories. The translation enables a new approach to equational reasoning for scoped effects and gives rise to an alternative characterization of monads in terms of generators and equations involving both scoped and algebraic operations. We demonstrate the power of our fresh perspective by way of equational characterizations of several known models of scoped effects.
Modular Models of Monoids with Operations yang-2023-modular
Inspired by algebraic effects and the principle of notions of computations as monoids, we study a categorical framework for equational theories and models of monoids equipped with operations. The framework covers not only algebraic operations but also scoped and variable-binding operations. Appealingly, in this framework both theories and models can be modularly composed. Technically, a general monoid-theory correspondence is shown, saying that the category of theories of algebraic operations is equivalent to the category of monoids. Moreover, more complex forms of operations can be coreflected into algebraic operations, in a way that preserves initial algebras. On models, we introduce modular models of a theory, which can interpret abstract syntax in the presence of other operations. We show constructions of modular models (i) from monoid transformers, (ii) from free algebras, (iii) by composition, and (iv) in symmetric monoidal categories.
Cites 74 works (9 here)
With notes (9)
Reasoning about effect interaction by fusion yang-2021-reasoning
Effect handlers can be composed by applying them sequentially, each handling some operations and leaving other operations uninterpreted in the syntax tree. However, the semantics of composed handlers can be subtle—it is well known that different orders of composing handlers can lead to drastically different semantics. Determining the correct order of composition is a non-trivial task. To alleviate this problem, this paper presents a systematic way of deriving sufficient conditions on handlers for their composite to correctly handle combinations, such as the sum and the tensor, of the effect theories separately handled. These conditions are solely characterised by the clauses for relevant operations of the handlers, and are derived by fusing two handlers into one using a form of fold/build fusion and continuation-passing style transformation. As case studies, the technique is applied to commutative and distributive interaction of handlers to obtain a series of results about the interaction of common handlers: (a) equations respected by each handler are preserved after handler composition; (b) handling mutable state before any handler gives rise to a semantics in which state operations are commutative with any operations from the latter handler; (c) handling the writer effect and mutable state in either order gives rise to a correct handler of the commutative combination of these two theories.
On the expressive power of user-defined effects: Effect handlers, monadic reflection, delimited control forster-2019-on
We compare the expressive power of three programming abstractions for user-defined computational effects: Plotkin and Pretnar’s effect handlers, Filinski’s monadic reflection, and delimited control. This comparison allows a precise discussion about the relative expressiveness of each programming abstraction. It also demonstrates the sensitivity of the relative expressiveness of user-defined effects to seemingly orthogonal language features. We present three calculi, one per abstraction, extending Levy’s call-by-push-value. For each calculus, we present syntax, operational semantics, a natural type-and-effect system, and, for effect handlers and monadic reflection, a set-theoretic denotational semantics. We establish their basic metatheoretic properties: safety, termination, and, where applicable, soundness and adequacy. Using Felleisen’s notion of a macro translation, we show that these abstractions can macro express each other, and show which translations preserve typeability. We use the adequate finitary set-theoretic denotational semantics for the monadic calculus to show that effect handlers cannot be macro expressed while preserving typeability either by monadic reflection or by delimited control. Our argument fails with simple changes to the type system such as polymorphism and inductive types. We supplement our development with a mechanised Abella formalisation.
Do be do be do lindley-2017-do
Adjoint folds and unfolds—An extended study hinze-2013-adjoint
Handlers in action kammar-2013-handlers
Algebraic foundations for effect-dependent optimisations kammar-2012-algebraic
Call-By-Push-Value: A Functional/Imperative Synthesis levy-2003-callbypushvalue
Introduction to Higher-Order Categorical Logic lambek_scott_1986
Abstract syntax and variable binding fiore_etal_nd
We develop a theory of abstract syntax with variable binding. To every binding signature we associate a category of models consisting of variable sets endowed with compatible algebra and substitution structures. The syntax generated by the signature is the initial model. This gives a notion of initial algebra semantics encompassing the traditional one; besides compositionality, it automatically verifies the semantic substitution lemma.
External (65)
- Asynchronous effects (2021)
- Latent Effects for Reusable Language Components (2021)
- Algebras for weighted search (2021)
- Not by equations alone: Reasoning with extensible effects (2021)
- Staged effects and handlers for modular languages with abstraction (2021)
- Monad transformers and modular algebraic effects: what binds them together (2019)
- eff – screaming fast extensible effects for less (software) (2019)
- polysemy: Higher-order, low-boilerplate free monads (software) (2019)
- Shallow Effect Handlers (2018)
- Syntax and Semantics for Operations with Scopes (2018)
- fused-effects: A fast, flexible, fused effect system (software) (2018)
- Type directed compilation of row-typed algebraic effects (2017)
- Category Theory in Context (2017)
- Programming with algebraic effects and handlers (2015)
- Freer monads, more extensible effects (2015)
- Fusion for Free (2015)
- An Effect System for Algebraic Effects and Handlers (2014)
- Effect handlers in scope (2014)
- Handling Algebraic Effects (2013)
- Instances of Computational Effects: An Algebraic Perspective (2013)
- Tracing monadic computations and representing effects (2012)
- Theory and Practice of Fusion (2011)
- Second-Order Algebraic Theories (2010)
- On the construction of free algebras for equational systems (2009)
- Handlers of Algebraic Effects (2009)
- Algebras for combinatorial search (2009)
- Foundations for structured programming with GADTs (2008)
- A Logic for Algebraic Effects (2008)
- Free-algebra models for the π-calculus (2008)
- Data types à la carte (2008)
- Stream fusion: From lists to streams to nothing at all (2007)
- The Category Theoretic Understanding of Universal Algebra: Lawvere Theories and Monads (2007)
- Initial Algebra Semantics Is Enough! (2007)
- Combining effects: Sum and tensor (2006)
- Substitution in non-wellfounded syntax with variable binding (2004)
- Explicit substitutions and higher-order syntax (2003)
- Adjunction Models For Call-By-Push-Value With Stacks (2003)
- Algebraic Operations and Generic Effects (2003)
- Notions of Computation Determine Monads (2002)
- Variations on Algebra: Monadicity and Generalisations of Equational Therories (2002)
- Semantics of name and value passing (2001)
- Generalised folds for nested datatypes (1999)
- A poor man's concurrency monad (1999)
- Enriched Lawvere theories (1999)
- Prological features in a functional setting — axioms and implementations (1998)
- Categories for the Working Mathematician (2nd edn) (1998)
- Categorical fixed point calculus (1995)
- Monad transformers and modular interpreters (1995)
- Shortcut deforestation in calculational form (1995)
- Monads for functional programming (1995)
- Locally Presentable and Accessible Categories (1994)
- Building interpreters by composing monads (1994)
- Adjunctions whose counits are coequalizers, and presentations of finitary enriched monads (1993)
- Composing monads (Yale research report) (1993)
- Notions of computation and monads (1991)
- A functional theory of exceptions (1990)
- Deforestation: transforming programs to eliminate trees (1990)
- Comprehending monads (1990)
- Category theory for computing science (1990)
- An abstract view of programming languages (1989)
- Structures defined by finite limits in the enriched context, I (1982)
- Free algebras and automata realizations in the language of categories (1974)
- Coequalizers and free triples (1970)
- Letters to the editor: go to statement considered harmful (1968)
- 10.5281/zenodo.5914133