Extensible Effects: An Alternative to Monad Transformers
📜 Abstract
We design and implement a library that solves the long-standing problem of combining effects without imposing restrictions on their interactions (such as static ordering). Effects arise from interactions between a client and an effect handler (interpreter); interactions may vary throughout the program and dynamically adapt to execution conditions. Existing code that relies on monad transformers may be used with our library with minor changes, gaining efficiency over long monad stacks. In addition, our library has greater expressiveness, allowing for practical idioms that are inefficient, cumbersome, or outright impossible with monad transformers. Our alternative to a monad transformer stack is a single monad, for the coroutine-like communication of a client with its handler. Its type reflects possible requests, i.e., possible effects of a computation. To support arbitrary effects and their combinations, requests are values of an extensible union type, which allows adding and, notably, subtracting summands. Extending and, upon handling, shrinking of the union of possible requests is reflected in its type, yielding a type-and-effect system for Haskell. The library is lightweight, generalizing the extensible exception handling to other effects and accurately tracking them in types.
✨ Summary
Main contribution
The paper presents extensible effects, a Haskell library intended as an alternative to statically ordered monad-transformer stacks. Effectful computations use a single Eff r monad, where r records the currently possible effects. Effects are represented as requests sent from clients to handlers; handlers interpret requests they understand and relay other requests upstream. This replaces a centralized authority with composable, user-defined handlers. (okmij.org)
The central type-level mechanism is an open union of effect requests. The union can be extended when computations introduce effects and reduced when handlers remove them. Consequently, the type system can reject computations with unhandled effects. The implementation uses type-indexed unions and Typeable-based dispatch, with constant-time injection and projection relative to the number of effects in the union. (okmij.org)
The authors show that the framework can express standard Reader, State, exception, nondeterminism, tracing, and lifted-monad effects in an MTL-like style. More significantly, it supports effect interactions that require different handler orders in different parts of a program. The paper demonstrates this with exception recovery combined with nondeterminism and with dynamic binding interleaved with coroutines—cases that are cumbersome or impossible to express using one statically fixed monad-transformer ordering. (okmij.org)
Subsequent influence
A direct follow-up, “Freer Monads, More Extensible Effects” by Kiselyov and Ishii, reconstructs the approach from free-monad representations, removes the Functor constraint through freer monads, and develops a more efficient implementation. (okmij.org) The later work on Parameterized Extensible Effects and Session Types explicitly builds on the add/subtract effect-set idea and connects extensible type-state effects with session types. (doi.org)
The paper is also directly cited or acknowledged as foundational work by subsequent Haskell effect libraries and implementations, including freer-effects, polysemy, and eff. These projects apply or extend the paper’s general approach of typed, composable effect descriptions and handlers. (github.com) The reviewed sources provide evidence of substantial influence on subsequent research and Haskell-library development, but do not establish a specific industrial deployment attributable directly to this paper.