skip to main content
research-article
Open Access

Contextual modal types for algebraic effects and handlers

Published:19 August 2021Publication History
Skip Abstract Section

Abstract

Programming languages with algebraic effects often track the computations’ effects using type-and-effect systems. In this paper, we propose to view an algebraic effect theory of a computation as a variable context; consequently, we propose to track algebraic effects of a computation with contextual modal types. We develop ECMTT, a novel calculus which tracks algebraic effects by a contextualized variant of the modal □ (necessity) operator, that it inherits from Contextual Modal Type Theory (CMTT).

Whereas type-and-effect systems add effect annotations on top of a prior programming language, the effect annotations in ECMTT are inherent to the language, as they are managed by programming constructs corresponding to the logical introduction and elimination forms for the □ modality. Thus, the type-and-effect system of ECMTT is actually just a type system.

Our design obtains the properties of local soundness and completeness, and determines the operational semantics solely by β-reduction, as customary in other logic-based calculi. In this view, effect handlers arise naturally as a witness that one context (i.e., algebraic theory) can be reached from another, generalizing explicit substitutions from CMTT.

To the best of our knowledge, ECMTT is the first system to relate algebraic effects to modal types. We also see it as a step towards providing a correspondence in the style of Curry and Howard that may transfer a number of results from the fields of modal logic and modal type theory to that of algebraic effects.

Skip Supplemental Material Section

Supplemental Material

Auxiliary Presentation Video

This is a presentation for our paper at ICFP 2021, accepted into the research track. In our work, we explore the connection between algebraic effects in contextual modal types. From the abstract: Programming languages with algebraic effects often track the computations’ effects using type-and-effect systems. In this paper, we propose to view an algebraic effect theory of a computation as a variable context; consequently, we propose to track algebraic effects of a computation with contextual modal types. We develop ECMTT, a novel calculus which tracks algebraic effects by a contextualized variant of the modal □ (necessity) operator, that it inherits from Contextual Modal Type Theory (CMTT).

3473580.mp4

Presentation Videos

References

  1. Danel Ahman. 2017. Handling fibred algebraic effects. Proc. ACM Program. Lang., 2, POPL (2017), Article 7, https://doi.org/10.1145/3158095 Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Danel Ahman and Matija Pretnar. 2021. Asynchronous effects. Proc. ACM Program. Lang., 5, POPL (2021), 1–28. https://doi.org/10.1145/3434305 Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Natasha Alechina, Michael Mendler, Valeria de Paiva, and Eike Ritter. 2001. Categorical and Kripke semantics for Constructive S4 modal logic. In International Workshop on Computer Science Logic, (CSL). 292–307. https://doi.org/10.1007/3-540-44802-0_21 Google ScholarGoogle ScholarCross RefCross Ref
  4. Miëtek Bak. 2017. Introspective Kripke models and normalisation by evaluation for the λ ^□ -calculus. In Workshop on Intuitionistic Modal Logic and Applications (IMLA). https://github.com/mietek/imla2017/blob/master/doc/imla2017.pdfGoogle ScholarGoogle Scholar
  5. Andrej Bauer. 2018. What is algebraic about algebraic effects and handlers? arXiv preprint, arxiv:1807.05923v2Google ScholarGoogle Scholar
  6. Andrej Bauer and Matija Pretnar. 2014. An effect system for algebraic effects and handlers. Log. Methods Comput. Sci., 10, 4 (2014), https://doi.org/10.2168/LMCS-10(4:9)2014 Google ScholarGoogle ScholarCross RefCross Ref
  7. Andrej Bauer and Matija Pretnar. 2015. Programming with algebraic effects and handlers. Journal of Logical and Algebraic Methods in Programming, 84, 1 (2015), 108–123. https://doi.org/10.1016/j.jlamp.2014.02.001 Google ScholarGoogle ScholarCross RefCross Ref
  8. P. N. Benton, G. M. Bierman, and V.C.V de Paiva. 1998. Computational types from a logical perspective. Journal of Functional Programming, 8, 2 (1998), 177–193. https://doi.org/10.1017/S0956796898002998 Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Gavin M. Bierman and Valeria de Paiva. 2000. On an Intuitionistic Modal Logic. Studia Logica, 65, 3 (2000), 383–416. https://doi.org/10.1023/A:1005291931660 Google ScholarGoogle ScholarCross RefCross Ref
  10. Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2019. Abstracting algebraic effects. Proc. ACM Program. Lang., 3, POPL (2019), 6. https://doi.org/10.1145/3290319 Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2020. Binders by day, labels by night: effect instances via lexically scoped handlers. Proc. ACM Program. Lang., 4, POPL (2020), 48:1–48:29. https://doi.org/10.1145/3371116 Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Patrick Blackburn, Maarten de Rijke, and Yde Venema. 2001. Modal Logic (Cambridge Tracts in Theoretical Computer Science, Vol. 53). Cambridge University Press. isbn:978-1-10705088-4 https://doi.org/10.1017/CBO9781107050884 Google ScholarGoogle Scholar
  13. Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. 2020. Effects as capabilities: effect handlers and lightweight effect polymorphism. Proc. ACM Program. Lang., 4, OOPSLA (2020), 1–30. https://doi.org/10.1145/3428194 Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Carl Bruggeman, Oscar Waddell, and R. Kent Dybvig. 1996. Representing control in the presence of one-shot continuations. In Conference on Programming Language Design and Implementation (PLDI). 99–107. https://doi.org/10.1145/231379.231395 Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Andrew Cave and Brigitte Pientka. 2013. First-class substitutions in contextual type theory. In International Workshop on Logical Frameworks & Meta-languages: Theory & Practice (LFMTP). 15–24. https://doi.org/10.1145/2503887.2503889 Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Lukas Convent, Sam Lindley, Conor McBride, and Craig McLaughlin. 2020. Doo bee doo bee doo. J. Funct. Program., 30 (2020), e9. https://doi.org/10.1017/S0956796820000039 Google ScholarGoogle ScholarCross RefCross Ref
  17. Rowan Davies and Frank Pfenning. 2001. A modal analysis of staged computation. J. ACM, 48, 3 (2001), 555–604. https://doi.org/10.1145/382780.382785 Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Murdoch James Gabbay and Aleksandar Nanevski. 2013. Denotation of contextual modal type theory (CMTT): Syntax and meta-programming. J. Appl. Log., 11, 1 (2013), 1–29. https://doi.org/10.1016/j.jal.2012.07.002 Google ScholarGoogle ScholarCross RefCross Ref
  19. Marco Gaboardi, Shin-ya Katsumata, Dominic Orchard, Flavien Breuvart, and Tarmo Uustalu. 2016. Combining effects and coeffects via grading. Proc. ACM Program. Lang., 51, ICFP (2016), 476–489. issn:0362-1340 https://doi.org/10.1145/3022670.2951939 Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Daniel Gratzer, Jonathan Sterling, and Lars Birkedal. 2019. Implementing a modal dependent type theory. Proc. ACM Program. Lang., 3, ICFP (2019), 107:1–107:29. https://doi.org/10.1145/3341711 Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Daniel Hillerström and Sam Lindley. 2016. Liberating effects with rows and handlers. In Workshop on Type-Driven Development ([email protected]). 15–27. https://doi.org/10.1145/2976022.2976033 Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Daniel Hillerström and Sam Lindley. 2018. Shallow effect handlers. In Asian Symposium on Programming Languages and Systems (APLAS). 415–435. https://doi.org/10.1007/978-3-030-02768-1_22 Google ScholarGoogle ScholarCross RefCross Ref
  23. Daniel Hillerström, Sam Lindley, and Robert Atkey. 2020. Effect handlers via generalised continuations. Journal of Functional Programming, 30 (2020), https://doi.org/10.1017/S0956796820000040 Google ScholarGoogle Scholar
  24. Danko Ilik. 2013. Continuation-passing style models complete for intuitionistic logic. Annals of Pure and Applied Logic, 164, 6 (2013), 651–662. issn:0168-0072 https://doi.org/10.1016/j.apal.2012.05.003 Google ScholarGoogle ScholarCross RefCross Ref
  25. Ohad Kammar, Sam Lindley, and Nicolas Oury. 2013. Handlers in action. SIGPLAN Not., 48, 9 (2013), 145–158. issn:0362-1340 https://doi.org/10.1145/2544174.2500590 Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Georgios Karachalias, Matija Pretnar, Amr Hany Saleh, Stien Vanderhallen, and Tom Schrijvers. 2020. Explicit effect subtyping. J. Funct. Program., 30 (2020), e15. https://doi.org/10.1017/S0956796820000131 Google ScholarGoogle ScholarCross RefCross Ref
  27. Daan Leijen. 2014. Koka: programming with row polymorphic effect types. In Workshop on Mathematically Structured Functional Programming ([email protected]). 100–126. https://doi.org/10.4204/EPTCS.153.8 Google ScholarGoogle ScholarCross RefCross Ref
  28. Daan Leijen. 2017. Type directed compilation of row-typed algebraic effects. In Symposium on Principles of Programming Languages (POPL). 486–499. https://doi.org/10.1145/3093333.3009872 Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Ziga Luksic and Matija Pretnar. 2020. Local algebraic effect theories. J. Funct. Program., 30 (2020), e13. https://doi.org/10.1017/S0956796819000212 Google ScholarGoogle ScholarCross RefCross Ref
  30. Aleksandar Nanevski. 2003. From dynamic binding to state via modal possibility. In Symposium on Principles and Practice of Declarative Programming (PPDP). 207–218. https://doi.org/10.1145/888251.888271 Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Aleksandar Nanevski. 2003. A modal calculus for effect handling. School of Computer Science, Carnegie Mellon University. http://reports-archive.adm.cs.cmu.edu/anon/2003/CMU-CS-03-149.pdfGoogle ScholarGoogle Scholar
  32. Aleksandar Nanevski. 2004. Functional programming with names and necessity. Ph.D. Dissertation. School of Computer Science, Carnegie Mellon University. http://reports-archive.adm.cs.cmu.edu/anon/2004/CMU-CS-04-151.pdfGoogle ScholarGoogle ScholarDigital LibraryDigital Library
  33. Aleksandar Nanevski and Frank Pfenning. 2005. Staged computation with names and necessity. Journal of Functional Programming, 15, 6 (2005), 837–891. https://doi.org/10.1017/S095679680500568X Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Aleksandar Nanevski, Frank Pfenning, and Brigitte Pientka. 2008. Contextual modal type theory. ACM Transactions on Computational Logic, 9, 3 (2008), 23. https://doi.org/10.1145/1352582.1352591 Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Dominic Orchard, Vilem-Benjamin Liepelt, and Harley Eades III. 2019. Quantitative program reasoning with graded modal types. Proc. ACM Program. Lang., 3, ICFP (2019), Article 110, 30 pages. https://doi.org/10.1145/3341714 Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Frank Pfenning. 2009. Lecture notes on harmony. https://www.cs.cmu.edu/~fp/courses/15317-f09/lectures/03-harmony.pdfGoogle ScholarGoogle Scholar
  37. Frank Pfenning and Rowan Davies. 2001. A judgmental reconstruction of modal logic. Mathematical Structures in Computer Science, 11, 4 (2001), 511–540. https://doi.org/10.1017/S0960129501003322 Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Brigitte Pientka. 2008. A type-theoretic foundation for programming with higher-order abstract syntax and first-class substitutions. In Symposium on Principles of Programming Languages (POPL). 371–382. https://doi.org/10.1145/1328438.1328483 Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Brigitte Pientka. 2010. Beluga: programming with dependent types, contextual data, and contexts. In International Symposium on Functional and Logic Programming (FLOPS). 1–12. https://doi.org/10.1007/978-3-642-12251-4_1 Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Brigitte Pientka and Frank Pfenning. 2003. Optimizing higher-order pattern unification. In International Conference on Automated Deduction (CADE). 473–487. https://doi.org/10.1007/978-3-540-45085-6_40 Google ScholarGoogle ScholarCross RefCross Ref
  41. Maciej Piróg, Tom Schrijvers, Nicolas Wu, and Mauro Jaskelioff. 2018. Syntax and semantics for operations with scopes. In Symposium on Logic in Computer Science (LICS). 809–818. isbn:9781450355834 https://doi.org/10.1145/3209108.3209166 Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Andrew M. Pitts. 2003. Nominal logic, a first order theory of names and binding. Information and Computation, 186, 2 (2003), 165–193. issn:0890-5401 https://doi.org/10.1016/S0890-5401(03)00138-X Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Gordon Plotkin and John Power. 2002. Notions of computation determine monads. In International Conference on Foundations of Software Science and Computation Structures (FoSSaCS). 342–356. https://doi.org/10.1007/3-540-45931-6_24 Google ScholarGoogle ScholarCross RefCross Ref
  44. Gordon Plotkin and John Power. 2003. Algebraic operations and generic effects. Applied Categorical Structures, 11, 1 (2003), 69–94. https://doi.org/10.1023/A:1023064908962 Google ScholarGoogle ScholarCross RefCross Ref
  45. Gordon D. Plotkin and John Power. 2001. Adequacy for algebraic effects. In International Conference on Foundations of Software Science and Computation Structures (FoSSaCS). 1–24. isbn:3540418644 https://doi.org/10.1007/11548133_3 Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. Casper Bach Poulsen, Cas van der Rest, and Tom Schrijvers. 2021. Staged effects and handlers for modular languages with abstraction. In Workshop on Partial Evaluation and Program Manipulation (PEPM). http://casperbp.net/store/staged-effects-and-handlers.pdfGoogle ScholarGoogle Scholar
  47. Matija Pretnar. 2015. An introduction to algebraic effects and handlers (invited paper). In Conference on the Mathematical Foundations of Programming Semantics (MFPS). 19–35. https://doi.org/10.1016/j.entcs.2015.12.003 Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. Matija Pretnar and Gordon D Plotkin. 2013. Handling algebraic effects. Logical Methods in Computer Science, 9 (2013), https://doi.org/10.2168/LMCS-9(4:23)2013 Google ScholarGoogle ScholarCross RefCross Ref
  49. Philipp Schuster, Jonathan Immanuel Brachthäuser, and Klaus Ostermann. 2020. Compiling effect handlers in capability-passing style. Proc. ACM Program. Lang., 4, ICFP (2020), 93:1–93:28. https://doi.org/10.1145/3408975 Google ScholarGoogle ScholarDigital LibraryDigital Library
  50. Alex K. Simpson. 1994. The proof theory and semantics of intuitionistic modal logic. Ph.D. Dissertation. University of Edinburgh. http://hdl.handle.net/1842/407Google ScholarGoogle Scholar
  51. KC Sivaramakrishnan, Stephen Dolan, Leo White, Tom Kelly, Sadiq Jaffer, and Anil Madhavapeddy. 2021. Retrofitting effect handlers onto OCaml. In Conference on Programming Language Design and Implementation (PLDI). https://doi.org/10.1145/3453483.3454039 Google ScholarGoogle ScholarDigital LibraryDigital Library
  52. Antonis Stampoulis and Zhong Shao. 2010. VeriML: typed computation of logical terms inside a language with effects. In International Conference on Functional Programming (ICFP). 333–344. https://doi.org/10.1145/1863543.1863591 Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. Antonios Michael Stampoulis. 2013. VeriML: A dependently-typed, user-extensible and language-centric approach to proof assistants. Ph.D. Dissertation. Yale University. http://flint.cs.yale.edu/flint/publications/ams-thesis.pdfGoogle ScholarGoogle Scholar
  54. Guannan Wei, Oliver Bracevac, Shangyin Tan, and Tiark Rompf. 2020. Compiling symbolic execution with staging and algebraic effects. Proc. ACM Program. Lang., 4, OOPSLA (2020), https://doi.org/10.1145/3428232 Google ScholarGoogle ScholarDigital LibraryDigital Library
  55. Philip Wickline, Peter Lee, Frank Pfenning, and Rowan Davies. 1998. Modal types as staging specifications for run-time code generation. Comput. Surveys, 30, 3es (1998), https://doi.org/10.1145/289121.289129 Google ScholarGoogle ScholarDigital LibraryDigital Library
  56. Nicolas Wu, Tom Schrijvers, and Ralf Hinze. 2014. Effect handlers in scope. In Symposium on Haskell. 1–12. https://doi.org/10.1145/2633357.2633358 Google ScholarGoogle ScholarDigital LibraryDigital Library
  57. Ningning Xie, Jonathan Immanuel Brachthäuser, Daniel Hillerström, Philipp Schuster, and Daan Leijen. 2020. Effect handlers, evidently. 4, ICFP (2020), Article 99, https://doi.org/10.1145/3408981 Google ScholarGoogle ScholarDigital LibraryDigital Library
  58. Yizhou Zhang and Andrew C Myers. 2019. Abstraction-safe effect handlers via tunneling. Proc. ACM Program. Lang., 3, POPL (2019), 1–29. https://doi.org/10.1145/3290318 Google ScholarGoogle ScholarDigital LibraryDigital Library
  59. Nikita Zyuzin and Aleksandar Nanevski. 2021. Contextual modal types for algebraic effects and handlers. arxiv:2103.02976. arxiv:2103.02976Google ScholarGoogle Scholar

Index Terms

  1. Contextual modal types for algebraic effects 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

          Full Access

          • Published in

            cover image Proceedings of the ACM on Programming Languages
            Proceedings of the ACM on Programming Languages  Volume 5, Issue ICFP
            August 2021
            1011 pages
            EISSN:2475-1421
            DOI:10.1145/3482883
            Issue’s Table of Contents

            Copyright © 2021 Owner/Author

            Publisher

            Association for Computing Machinery

            New York, NY, United States

            Publication History

            • Published: 19 August 2021
            Published in pacmpl Volume 5, Issue ICFP

            Permissions

            Request permissions about this article.

            Request Permissions

            Check for updates

            Qualifiers

            • research-article

          PDF Format

          View or Download as a PDF file.

          PDF

          eReader

          View online with eReader.

          eReader
          About Cookies On This Site

          We use cookies to ensure that we give you the best experience on our website.

          Learn more

          Got it!