From Monads to Effects and Back


The combination of monads and effects leads to a clean and easy to reason programming paradigm. Monadic programming is easy to reason, but can be cumbersome, as it requires explicit lifting and binding. In this paper, we combine monads and effects within a single programming paradigm: we use monads to define the semantics of effect types, and then, use the effects to program with those monads. In particular, we implemented an extension to the effect type system of Koka [20] with user defined effects. We use a type-directed translation to automatically lift such effectful programs into monadic programs, by inserting bindand unit operations. As such, these user-defined effects are not just introducing a new effect type, but also enable full monadic abstraction and let us “take control of the semi-colon” in a typed and structured manner. We give examples of various abstractions like ambiguous computations and parsers. All examples have been implemented in the Koka language and we describe various implementation issues and optimization mechanisms.

DOI: 10.1007/978-3-319-28228-2_11

Extracted Key Phrases

4 Figures and Tables

Cite this paper

@inproceedings{Vazou2016FromMT, title={From Monads to Effects and Back}, author={Niki Vazou and Daan Leijen}, booktitle={PADL}, year={2016} }