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.
Supplemental Material
- Danel Ahman. 2017. Handling fibred algebraic effects. Proc. ACM Program. Lang., 2, POPL (2017), Article 7, https://doi.org/10.1145/3158095 Google Scholar
Digital Library
- Danel Ahman and Matija Pretnar. 2021. Asynchronous effects. Proc. ACM Program. Lang., 5, POPL (2021), 1–28. https://doi.org/10.1145/3434305 Google Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
- Andrej Bauer. 2018. What is algebraic about algebraic effects and handlers? arXiv preprint, arxiv:1807.05923v2Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- Ziga Luksic and Matija Pretnar. 2020. Local algebraic effect theories. J. Funct. Program., 30 (2020), e13. https://doi.org/10.1017/S0956796819000212 Google Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Frank Pfenning. 2009. Lecture notes on harmony. https://www.cs.cmu.edu/~fp/courses/15317-f09/lectures/03-harmony.pdfGoogle Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Nikita Zyuzin and Aleksandar Nanevski. 2021. Contextual modal types for algebraic effects and handlers. arxiv:2103.02976. arxiv:2103.02976Google Scholar
Index Terms
Contextual modal types for algebraic effects and handlers
Recommendations
Effects as capabilities: effect handlers and lightweight effect polymorphism
Effect handlers have recently gained popularity amongst programming language researchers. Existing type- and effect systems for effect handlers are often complicated and potentially hinder a wide-spread adoption.
We present the language Effekt with ...
Algebraic effects and effect handlers for idioms and arrows
WGP '14: Proceedings of the 10th ACM SIGPLAN workshop on Generic programmingPlotkin and Power's algebraic effects combined with Plotkin and Pretnar's effect handlers provide a foundation for modular programming with effects. We present a generalisation of algebraic effects and effect handlers to support other kinds of effectful ...
Handlers for Non-Monadic Computations
IFL '17: Proceedings of the 29th Symposium on the Implementation and Application of Functional Programming LanguagesAlgebraic effects and handlers are a convenient method for structuring monadic effects with primitive effectful operations and separating the syntax from the interpretation of these operations. However, the scope of conventional handlers are somewhat ...






Comments