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

Liberating effects with rows and handlers

Published:18 September 2016Publication History

ABSTRACT

Algebraic effects and effect handlers provide a modular abstraction for effectful programming. They support user-defined effects, as in Haskell, in conjunction with direct-style effectful programming, as in ML. They also present a structured interface to programming with delimited continuations.

In order to be modular, it is necessary for an effect type system to support extensible effects. Row polymorphism is a natural abstraction for modelling extensibility at the level of types. In this paper we argue that the abstraction required to implement extensible effects and their handlers is exactly row polymorphism.

We use the Links functional web programming language as a platform to substantiate this claim. Links is a natural starting point as it uses row polymorphism for polymorphic variants, records, and its built-in effect types. It also has infrastructure for manipulating continuations. Through a small extension to Links we smoothly add support for effect handlers, making essential use of rows in the frontend and first-class continuations in the backend.

We demonstrate the usability of our implementation by modelling the mathematical game of Nim as an abstract computation. We interpret this abstract computation in a variety of ways, illustrating how rows and handlers support modularity and smooth composition of effectful computations.

We present a core calculus of row-polymorphic effects and handlers based on a variant of A-normal form used in the intermediate representation of Links. We give an operational semantics for the calculus and a novel generalisation of the CEK machine that implements the operational semantics, and prove that the two coincide.

References

  1. R. Atkey. Parameterised notions of computation. Journal of Functional Programming, 19(3-4):335–376, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. A. Bauer and M. Pretnar. An effect system for algebraic effects and handlers. Logical Methods in Computer Science, 10(4), 2014.Google ScholarGoogle Scholar
  3. A. Bauer and M. Pretnar. Programming with algebraic effects and handlers. Journal of Logical and Algebraic Methods in Programming, 84(1):108–123, 2015.Google ScholarGoogle ScholarCross RefCross Ref
  4. M. Blume, U. A. Acar, and W. Chae. Exception handlers as extensible cases. In G. Ramalingam, editor, Programming Languages and Systems, 6th Asian Symposium, APLAS 2008, Bangalore, India, December 9-11, 2008. Proceedings, volume 5356 of Lecture Notes in Computer Science, pages 273–289. Springer, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. C. L. Bouton. Nim, a game with a complete mathematical theory. The Annals of Mathematics, 3(1/4):35–39, 1901.Google ScholarGoogle ScholarCross RefCross Ref
  6. E. Brady. Programming and reasoning with algebraic effects and dependent types. In Morrisett and Uustalu {27}, pages 133–144. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. C. Bruggeman, O. Waddell, and R. K. Dybvig. Representing control in the presence of one-shot continuations. In C. N. Fischer, editor, Proceedings of the ACM SIGPLAN’96 Conference on Programming Language Design and Implementation (PLDI), Philadephia, Pennsylvania, May 21-24, 1996, pages 99–107. ACM, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. E. Cooper, S. Lindley, P. Wadler, and J. Yallop. Links: Web programming without tiers. In F. S. de Boer, M. M. Bonsangue, S. Graf, and W. P. de Roever, editors, Formal Methods for Components and Objects, 5th International Symposium, FMCO 2006, Amsterdam, The Netherlands, November 7-10, 2006, Revised Lectures, volume 4709 of Lecture Notes in Computer Science, pages 266–296. Springer, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. S. Dolan, L. White, K. Sivaramakrishnan, J. Yallop, and A. Madhavapeddy. Effective concurrency through algebraic effects. OCaml Workshop, September 2015.Google ScholarGoogle Scholar
  10. M. Felleisen and D. P. Friedman. Control operators, the SECDmachine, and the λ-calculus. In The Proceedings of the Conference on Formal Description of Programming Concepts III, Ebberup, Denmark, pages 193–217. Elsevier, 1987.Google ScholarGoogle Scholar
  11. C. Flanagan, A. Sabry, B. F. Duba, and M. Felleisen. The essence of compiling with continuations. In Proceedings of the ACM SIGPLAN 1993 Conference on Programming Language Design and Implementation, PLDI ’93, pages 237–247, New York, NY, USA, 1993. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. D. Hillerström. Handlers for algebraic effects in Links. Master’s thesis, The University of Edinburgh, Scotland, 2015.Google ScholarGoogle Scholar
  13. D. Hillerström, S. Lindley, and K. Sivaramakrishnan. Compiling Links effect handlers to the OCaml backend. ML Workshop, 2016.Google ScholarGoogle Scholar
  14. S. Holmes. Compiling Links server-side code. Bachelor thesis, The University of Edinburgh, 2009.Google ScholarGoogle Scholar
  15. O. Kammar, S. Lindley, and N. Oury. Handlers in action. In Morrisett and Uustalu {27}, pages 145–158. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. O. Kiselyov and H. Ishii. Freer monads, more extensible effects. In B. Lippmeier, editor, Proceedings of the 8th ACM SIGPLAN Symposium on Haskell, Haskell 2015, Vancouver, BC, Canada, September 3-4, 2015, pages 94–105. ACM, 2015. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. O. Kiselyov, A. Sabry, and C. Swords. Extensible effects: an alternative to monad transformers. In C. Shan, editor, Proceedings of the 2013 ACM SIGPLAN Symposium on Haskell, Boston, MA, USA, September 23-24, 2013, pages 59–70. ACM, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. D. Leijen. Koka: Programming with row polymorphic effect types. In P. Levy and N. Krishnaswami, editors, Proceedings 5th Workshop on Mathematically Structured Functional Programming, MSFP, Grenoble, France, April 2014, volume 153 of EPTCS, pages 100–126, 2014.Google ScholarGoogle Scholar
  19. X. Leroy and F. Pessaux. Type-based analysis of uncaught exceptions. ACM Transactions on Programming Languages and Systems, 22(2): 340–377, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. P. B. Levy, J. Power, and H. Thielecke. Modelling environments in call-by-value programming languages. Information and Computation, 185(2):182–210, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. S. Liang, P. Hudak, and M. P. Jones. Monad transformers and modular interpreters. In R. K. Cytron and P. Lee, editors, Conference Record of POPL’95: 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, San Francisco, California, USA, January 23-25, 1995, pages 333–343. ACM Press, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. S. Lindley and J. Cheney. Row-based effect types for database integration. In B. C. Pierce, editor, Proceedings of TLDI 2012: The Seventh ACM SIGPLAN Workshop on Types in Languages Design and Implementation, Philadelphia, PA, USA, Saturday, January 28, 2012, pages 91–102. ACM, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. S. Lindley, C. McBride, and C. McLaughlin. Do be do be do.Google ScholarGoogle Scholar
  24. C. McBride. Shonky, 2016. https://github.com/pigworker/ shonky.Google ScholarGoogle Scholar
  25. J. G. Morris. Variations on variants. In B. Lippmeier, editor, Proceedings of the 8th ACM SIGPLAN Symposium on Haskell, Haskell 2015, Vancouver, BC, Canada, 2015, pages 71–81. ACM, 2015. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. J. G. Morris and M. P. Jones. Instance chains: type class programming without overlapping instances. In P. Hudak and S. Weirich, editors, Proceeding of the 15th ACM SIGPLAN International Conference on Functional Programming, ICFP 2010, Baltimore, Maryland, USA, September 27-29, 2010, pages 375–386. ACM, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. G. Morrisett and T. Uustalu, editors. ACM SIGPLAN International Conference on Functional Programming, ICFP’13, Boston, MA, USA - September 25 - 27, 2013, 2013. ACM. Google ScholarGoogle ScholarCross RefCross Ref
  28. D. A. Orchard and T. Petricek. Embedding effect systems in Haskell. In W. Swierstra, editor, Proceedings of the 2014 ACM SIGPLAN symposium on Haskell, Gothenburg, Sweden, September 4-5, 2014, pages 13–24. ACM, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. G. D. Plotkin and J. Power. Adequacy for algebraic effects. In F. Honsell and M. Miculan, editors, Foundations of Software Science and Computation Structures, 4th International Conference, FOSSACS Genova, Italy, April 2-6, 2001, Proceedings, volume 2030 of Lecture Notes in Computer Science, pages 1–24. Springer, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. G. D. Plotkin and M. Pretnar. Handling algebraic effects. Logical Methods in Computer Science, 9(4), 2013.Google ScholarGoogle Scholar
  31. M. Pretnar. Inferring algebraic effects. Logical Methods in Computer Science, 10(3), 2014.Google ScholarGoogle Scholar
  32. M. Pretnar. An introduction to algebraic effects and handlers. invited tutorial paper. Electronic Notes in Theoretical Computer Science, 319: 19–35, 2015. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. D. Rémy. Theoretical aspects of object-oriented programming. chapter Type Inference for Records in Natural Extension of ML, pages 67– 95. MIT Press, Cambridge, MA, USA, 1994.Google ScholarGoogle Scholar
  34. W. Swierstra. Data types à la carte. Journal of Functional Programming, 18(4):423–436, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. N. Wu and T. Schrijvers. Fusion for free - efficient algebraic effect handlers. In R. Hinze and J. Voigtländer, editors, Mathematics of Program Construction - 12th International Conference, MPC 2015, Königswinter, Germany, 2015. Proceedings, volume 9129 of Lecture Notes in Computer Science, pages 302–322. Springer, 2015.Google ScholarGoogle Scholar
  36. N. Wu, T. Schrijvers, and R. Hinze. Effect handlers in scope. In Proceedings of the 2014 ACM SIGPLAN Symposium on Haskell, Haskell ’14, pages 1–12, New York, NY, USA, 2014. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. B. A. Yorgey, S. Weirich, J. Cretin, S. L. P. Jones, D. Vytiniotis, and J. P. Magalh˜aes. Giving Haskell a promotion. In B. C. Pierce, editor, Proceedings of TLDI 2012: The Seventh ACM SIGPLAN Workshop on Types in Languages Design and Implementation, Philadelphia, PA, USA, Saturday, January 28, 2012, pages 53–66. ACM, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Liberating effects with rows and handlers

      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
        TyDe 2016: Proceedings of the 1st International Workshop on Type-Driven Development
        September 2016
        71 pages
        ISBN:9781450344357
        DOI:10.1145/2976022

        Copyright © 2016 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: 18 September 2016

        Permissions

        Request permissions about this article.

        Request Permissions

        Check for updates

        Qualifiers

        • research-article

        Upcoming Conference

        ICFP '24

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader