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.
- A. Bauer and M. Pretnar. Programming with algebraic effects and handlers. arXiv:1203.1539 {cs.PL}, 2012.Google Scholar
- E. C. Brady. Programming and reasoning with algebraic effects and dependent types. In ICFP {11}, page To Appear. Google ScholarDigital Library
- R. Cartwright and M. Felleisen. Extensible denotational language specifications. In M. Hagiya and J. C. Mitchell, editors, Theor. Aspects of Comp. Soft., number 789 in LNCS, pages 244--272. Springer, 1994. Google ScholarDigital Library
- D. Espinosa. Modular denotational semantics. Unpublished manuscript, 1993.Google Scholar
- D. Espinosa. Building interpreters by transforming stratified monads. Unpublished manuscript, 1994.Google Scholar
- D. A. Espinosa. Semantic Lego. PhD thesis, Columbia University, New York, NY, USA, 1995. UMI Order No. GAX95-33546. Google ScholarDigital Library
- A. Filinski. Representing monads. Incitetpopl1994, pages 446--457. Google ScholarDigital Library
- A. Filinski. Representing layered monads. In POPL '99, pages 175--188, New York, NY, USA, 1999. ACM. Google ScholarDigital Library
- R. Hinze. Deriving backtracking monad transformers. In ICFP '00, pages 186--197. ACM Press, 2000. Google ScholarDigital Library
- J. Hughes. The design of a pretty-printing library. In First Intl. Spring School on Adv. Functional Programming Techniques, pages 53--96, London, UK, UK, 1995. Springer-Verlag. Google ScholarDigital Library
- ICFP. ICFP '13, 2013. ACM Press.Google Scholar
- M. Jaskelioff and E. Moggi. Monad transformers as monoid transformers. Theor. Comp. Science, 411 (51/52): 4441--4466, 2010. Google ScholarDigital Library
- O. Kammar, S. Lindley, and N. Oury. Handlers in action. In ICFP {11}, page To Appear. Google ScholarDigital Library
- D. King and P. Wadler. Combining monads. In J. Launchbury and P. Sansom, editors, Functional Programming, Glasgow 1992, Workshops in Computing, pages 134--143. Springer London, 1993. Google ScholarDigital Library
- O. Kiselyov, R. Lämmel, and K. Schupke. Strongly typed heterogeneous collections. In Proc. 2004 workshop on Haskell, pages 96--107, New York, NY, USA, 2004. ACM. Google ScholarDigital Library
- O. Kiselyov, C.-c. Shan, and A. Sabry. Delimited dynamic binding. In ICFP '06, pages 26--37. ACM Press, 2006. Google ScholarDigital Library
- D. Leijen. Koka: A language with row-polymorphic effect inference. In 1st Workshop on Higher-Order Programming with Effects (HOPE 2012). ACM, September 2012.Google Scholar
- S. Liang, P. Hudak, and M. Jones. Monad transformers and modular interpreters. In POPL '95, pages 333--343. ACM Press, 1995. Google ScholarDigital Library
- C. Lüth and N. Ghani. Composing monads using coproducts. In ICFP '02, pages 133--144. ACM Press, 2002. Google ScholarDigital Library
- S. Marlow. An extensible dynamically-typed hierarchy of exceptions. In Proc. 2006 Haskell Workshop, pages 96--106. ACM Press, 2006. Google ScholarDigital Library
- C. McBride. The Frank manual. https://personal.cis.strath.ac.uk/conor.mcbride/pub/Frank/, 2012.Google Scholar
- E. Moggi. Computational lambda-calculus and monads. In LICS, pages 14--23, Piscataway, NJ, USA, 1989. IEEE Press. Google ScholarDigital Library
- E. Moggi. An abstract view of programming languages. Technical Report ECS-LFCS-90--113, Edinburgh Univ., 1989.Google Scholar
- B. O'Sullivan, J. Goerzen, and D. Stewart. Real world Haskell -- code you can believe in. O'Reilly, 2008. Google ScholarDigital Library
- G. Plotkin and M. Pretnar. Handlers of algebraic effects. In ESOP '09, pages 80--94, Berlin, Heidelberg, 2009. Springer-Verlag. Google ScholarDigital Library
- POPL. POPL '94, 1994. ACM Press.Google Scholar
- T. Schrijvers and B. C. Oliveira. Monads, zippers and views: virtualizing the monad stack. In ICFP '11, pages 32--44, New York, NY, USA, 2011. ACM. Google ScholarDigital Library
- M. Shields and E. Meijer. Type-indexed rows. In POPL '01, pages 261--275, London, United Kingdom, Jan. 17--19, 2001. ACM Press. Google ScholarDigital Library
- G. L. Steele, Jr. How to compose monads. Technical report, Thinking Machines Corporation, Cambridge, Massachusetts, July 1993.Google Scholar
- G. L. Steele, Jr. Building interpreters by composing monads. In POPL {26}, pages 472--492. Google ScholarDigital Library
- N. Swamy, N. Guts, D. Leijen, and M. Hicks. Lightweight monadic programming in ML. In ICFP'11, pages 15--27, Sept. 2011. Google ScholarDigital Library
- W. Swierstra. Data types à la carte. J. Funct. Program., 18 (4): 423--436, July 2008. Google ScholarDigital Library
- S. Visscher. Control.effects, 2012. URL http://github.com/sjoerdvisscher/effects.Google Scholar
- P. Wadler. The essence of functional programming. In POPL '92, pages 1--14, New York, NY, USA, 1992. ACM. Google ScholarDigital Library
Index Terms
- Extensible effects: an alternative to monad transformers
Recommendations
Freer monads, more extensible effects
Haskell '15: Proceedings of the 2015 ACM SIGPLAN Symposium on HaskellWe present a rational reconstruction of extensible effects, the recently proposed alternative to monad transformers, as the confluence of efforts to make effectful computations compose. Free monads and then extensible effects emerge from the ...
Extensible effects: an alternative to monad transformers
Haskell '13We 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 (...
Freer monads, more extensible effects
Haskell '15We present a rational reconstruction of extensible effects, the recently proposed alternative to monad transformers, as the confluence of efforts to make effectful computations compose. Free monads and then extensible effects emerge from the ...
Comments