skip to main content
10.1145/2503778.2503791acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article

Extensible effects: an alternative to monad transformers

Published:23 September 2013Publication History

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.

References

  1. A. Bauer and M. Pretnar. Programming with algebraic effects and handlers. arXiv:1203.1539 {cs.PL}, 2012.Google ScholarGoogle Scholar
  2. E. C. Brady. Programming and reasoning with algebraic effects and dependent types. In ICFP {11}, page To Appear. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  4. D. Espinosa. Modular denotational semantics. Unpublished manuscript, 1993.Google ScholarGoogle Scholar
  5. D. Espinosa. Building interpreters by transforming stratified monads. Unpublished manuscript, 1994.Google ScholarGoogle Scholar
  6. D. A. Espinosa. Semantic Lego. PhD thesis, Columbia University, New York, NY, USA, 1995. UMI Order No. GAX95-33546. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. A. Filinski. Representing monads. Incitetpopl1994, pages 446--457. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. A. Filinski. Representing layered monads. In POPL '99, pages 175--188, New York, NY, USA, 1999. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. R. Hinze. Deriving backtracking monad transformers. In ICFP '00, pages 186--197. ACM Press, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. ICFP. ICFP '13, 2013. ACM Press.Google ScholarGoogle Scholar
  12. M. Jaskelioff and E. Moggi. Monad transformers as monoid transformers. Theor. Comp. Science, 411 (51/52): 4441--4466, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. O. Kammar, S. Lindley, and N. Oury. Handlers in action. In ICFP {11}, page To Appear. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. O. Kiselyov, C.-c. Shan, and A. Sabry. Delimited dynamic binding. In ICFP '06, pages 26--37. ACM Press, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. 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 ScholarGoogle Scholar
  18. S. Liang, P. Hudak, and M. Jones. Monad transformers and modular interpreters. In POPL '95, pages 333--343. ACM Press, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. C. Lüth and N. Ghani. Composing monads using coproducts. In ICFP '02, pages 133--144. ACM Press, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. S. Marlow. An extensible dynamically-typed hierarchy of exceptions. In Proc. 2006 Haskell Workshop, pages 96--106. ACM Press, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. C. McBride. The Frank manual. https://personal.cis.strath.ac.uk/conor.mcbride/pub/Frank/, 2012.Google ScholarGoogle Scholar
  22. E. Moggi. Computational lambda-calculus and monads. In LICS, pages 14--23, Piscataway, NJ, USA, 1989. IEEE Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. E. Moggi. An abstract view of programming languages. Technical Report ECS-LFCS-90--113, Edinburgh Univ., 1989.Google ScholarGoogle Scholar
  24. B. O'Sullivan, J. Goerzen, and D. Stewart. Real world Haskell -- code you can believe in. O'Reilly, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. G. Plotkin and M. Pretnar. Handlers of algebraic effects. In ESOP '09, pages 80--94, Berlin, Heidelberg, 2009. Springer-Verlag. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. POPL. POPL '94, 1994. ACM Press.Google ScholarGoogle Scholar
  27. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  28. M. Shields and E. Meijer. Type-indexed rows. In POPL '01, pages 261--275, London, United Kingdom, Jan. 17--19, 2001. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. G. L. Steele, Jr. How to compose monads. Technical report, Thinking Machines Corporation, Cambridge, Massachusetts, July 1993.Google ScholarGoogle Scholar
  30. G. L. Steele, Jr. Building interpreters by composing monads. In POPL {26}, pages 472--492. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. N. Swamy, N. Guts, D. Leijen, and M. Hicks. Lightweight monadic programming in ML. In ICFP'11, pages 15--27, Sept. 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. W. Swierstra. Data types à la carte. J. Funct. Program., 18 (4): 423--436, July 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. S. Visscher. Control.effects, 2012. URL http://github.com/sjoerdvisscher/effects.Google ScholarGoogle Scholar
  34. P. Wadler. The essence of functional programming. In POPL '92, pages 1--14, New York, NY, USA, 1992. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Extensible effects: an alternative to monad transformers

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in
        • Published in

          cover image ACM Conferences
          Haskell '13: Proceedings of the 2013 ACM SIGPLAN symposium on Haskell
          September 2013
          158 pages
          ISBN:9781450323833
          DOI:10.1145/2503778

          Copyright © 2013 ACM

          Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 23 September 2013

          Permissions

          Request permissions about this article.

          Request Permissions

          Check for updates

          Qualifiers

          • research-article

          Acceptance Rates

          Haskell '13 Paper Acceptance Rate13of33submissions,39%Overall Acceptance Rate57of143submissions,40%

          Upcoming Conference

          ICFP '24

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader