Modal Effect Types
Wenhao Tang, Leo White, Stephen Dolan, Daniel Hillerström, Sam Lindley, Anton Lorenzen
TL;DR
This work introduces Modal Effect Types (Met), a robust framework for effectful programming that eliminates the need for explicit effect polymorphism by tracking ambient effect contexts as modalities. Built on multimodal type theory, Met distinguishes absolute $[E]$ and relative $<L|D>$ modalities to manage how effect contexts change across computations, handlers, and masking. The paper defines a core calculus Met, proves type soundness and effect safety, and shows how to encode traditional row-based effect polymorphism within Met and its surface language Metl. Extensions to data types, polymorphism, and richer handlers demonstrate practical scalability, and a detailed comparison with Koka and Effekt highlights the practical advantages of modal effect types for modular, first-class effects. The work lays groundwork for future language integrations (e.g., OCaml) and offers a principled approach to robustly managing effects without pervasive annotation overhead.
Abstract
Effect handlers are a powerful abstraction for defining, customising, and composing computational effects. Statically ensuring that all effect operations are handled requires some form of effect system, but using a traditional effect system would require adding extensive effect annotations to the millions of lines of existing code in these languages. Recent proposals seek to address this problem by removing the need for explicit effect polymorphism. However, they typically rely on fragile syntactic mechanisms or on introducing a separate notion of second-class function. We introduce a novel approach based on modal effect types.
