Abstract
Reasoning about the use of external resources is an important aspect of many practical applications. Effect systems enable tracking such information in types, but at the cost of complicating signatures of common functions. Capabilities coupled with escape analysis offer safety and natural signatures, but are often overly coarse grained and restrictive. We present System C, which builds on and generalizes ideas from type-based escape analysis and demonstrates that capabilities and effects can be reconciled harmoniously. By assuming that all functions are second class, we can admit natural signatures for many common programs. By introducing a notion of boxed values, we can lift the restrictions of second-class values at the cost of needing to track degree-of-impurity information in types. The system we present is expressive enough to support effect handlers in full capacity. We practically evaluate System C in an implementation and prove its soundness.
Supplemental Material
Available for Download
This zip file contains the **appendix** of our paper: > Effects, Capabilities, and Boxes: From Scope-based Reasoning to Type-based Reasoning and Back. > Jonathan Immanuel Brachthäuser, Philipp Schuster, Edward Lee, Aleksander Boruch-Gruszecki. > OOPSLA 2022. For the full artifact with proofs and interactive demonstration, we direct the interested reader to <https://zenodo.org/record/6372830>.
- Danel Ahman and Matija Pretnar. 2021. Asynchronous Effects. Proc. ACM Program. Lang., 5, POPL (2021), Article 24, Jan., 28 pages. https://doi.org/10.1145/3434305 Google Scholar
Digital Library
- Brian Aydemir, Arthur Charguéraud, Benjamin C. Pierce, Randy Pollack, and Stephanie Weirich. 2008. Engineering Formal Metatheory. In Proceedings of the Symposium on Principles of Programming Languages. ACM, New York, NY, USA. 3–15. https://doi.org/10.1145/1328438.1328443 Google Scholar
Digital Library
- Henk P. Barendregt. 1992. Lambda Calculi with Types. In Handbook of Logic in Computer Science (vol. 2): Background: Computational Structures. Oxford University Press, New York, NY, USA. 117–309.Google Scholar
- Yves Bertot and Pierre Castéran. 2004. Interactive Theorem Proving and Program Development, Coq’Art:The Calculus of Inductive Constructions. Springer-Verlag.Google Scholar
- Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2019. Binders by Day, Labels by Night: Effect Instances via Lexically Scoped Handlers. Proc. ACM Program. Lang., 4, POPL (2019), Article 48, Dec., 29 pages. https://doi.org/10.1145/3371116 Google Scholar
Digital Library
- Jonathan Immanuel Brachthäuser and Philipp Schuster. 2017. Effekt: Extensible Algebraic Effects in Scala (Short Paper). In Proceedings of the International Symposium on Scala. ACM, New York, NY, USA. https://doi.org/10.1145/3136000.3136007 Google Scholar
Digital Library
- Jonathan Immanuel Brachthäuser, Philipp Schuster, Edward Lee, and Boruch-Gruszecki Aleksander. 2022. Effects, Capabilities, and Boxes: From Scope-Based Reasoning to Type-Based Reasoning and Back. University of Tübingen, Germany. https://se.informatik.uni-tuebingen.de/publications/brachthaeuser22effectsGoogle Scholar
- Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. 2018. Effect Handlers for the Masses. Proc. ACM Program. Lang., 2, OOPSLA (2018), Article 111, Oct., 27 pages. issn:2475-1421 https://doi.org/10.1145/3276481 Google Scholar
Digital Library
- 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), Article 126, Nov., https://doi.org/10.1145/3428194 Google Scholar
Digital Library
- Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. 2020. Effekt: Capability-Passing Style for Type- and Effect-safe, Extensible Effect Handlers in Scala. Journal of Functional Programming, https://doi.org/10.1017/S0956796820000027 Google Scholar
Cross Ref
- Jonathan Immanuel Brachthäuser and Daan Leijen. 2019. Programming with Implicit Values, Functions, and Control. Microsoft Research.Google Scholar
- Vikraman Choudhury and Neel Krishnaswami. 2020. Recovering Purity with Comonads and Capabilities. Proc. ACM Program. Lang., 4, ICFP (2020), Article 111, Aug., 28 pages. https://doi.org/10.1145/3408993 Google Scholar
Digital Library
- Michael Coblenz, Joshua Sunshine, Jonathan Aldrich, Brad Myers, Sam Weber, and Forrest Shull. 2016. Exploring language support for immutability. In 2016 IEEE/ACM 38th International Conference on Software Engineering (ICSE). 736–747.Google Scholar
Digital Library
- William R. Cook. 2009. On Understanding Data Abstraction, Revisited. In Proceedings of the Conference on Object-Oriented Programming, Systems, Languages and Applications. ACM, New York, NY, USA. 557–572.Google Scholar
- Karl Crary, David Walker, and Greg Morrisett. 1999. Typed Memory Management in a Calculus of Capabilities. In Proceedings of the 26th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’99). Association for Computing Machinery, New York, NY, USA. 262–275. isbn:1581130953 https://doi.org/10.1145/292540.292564 Google Scholar
Digital Library
- Jack B. Dennis and Earl C. Van Horn. 1966. Programming Semantics for Multiprogrammed Computations. Commun. ACM, 9, 3 (1966), March, 143–155. issn:0001-0782Google Scholar
Digital Library
- Stephen Dolan, Spiros Eliopoulos, Daniel Hillerström, Anil Madhavapeddy, KC Sivaramakrishnan, and Leo White. 2017. Effectively Tackling the Awkward Squad. In ML Workshop.Google Scholar
- R. Kent Dybvig, Simon L. Peyton Jones, and Amr Sabry. 2007. A monadic framework for delimited continuations. Journal of Functional Programming, 17, 6 (2007), 687–730.Google Scholar
Digital Library
- Matthias Felleisen. 1988. The Theory and Practice of First-class Prompts. In Proceedings of the Symposium on Principles of Programming Languages. ACM, New York, NY, USA. 180–190.Google Scholar
Digital Library
- Marco Gaboardi, Shin-ya Katsumata, Dominic Orchard, Flavien Breuvart, and Tarmo Uustalu. 2016. Combining Effects and Coeffects via Grading. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming (ICFP 2016). Association for Computing Machinery, New York, NY, USA. 476–489. isbn:9781450342193 https://doi.org/10.1145/2951913.2951939 Google Scholar
Digital Library
- Colin S. Gordon. 2020. Designing with Static Capabilities and Effects: Use, Mention, and Invariants (Pearl). In 34th European Conference on Object-Oriented Programming (ECOOP 2020), Robert Hirschfeld and Tobias Pape (Eds.) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 166). Schloss Dagstuhl–Leibniz-Zentrum für Informatik, Dagstuhl, Germany. 10:1–10:25. isbn:978-3-95977-154-2 issn:1868-8969 https://doi.org/10.4230/LIPIcs.ECOOP.2020.10 Google Scholar
Cross Ref
- Carl A. Gunter, Didier Rémy, and Jon G. Riecke. 1995. A Generalization of Exceptions and Control in ML-like Languages. In Proceedings of the Conference on Functional Programming Languages and Computer Architecture. ACM, New York, NY, USA. 12–23.Google Scholar
- John Hannan. 1998. A Type-based Escape Analysis for Functional Languages. Journal of Functional Programming, 8, 3 (1998), May, 239–273.Google Scholar
Digital Library
- Oleg Kiselyov, Chung-chieh Shan, and Amr Sabry. 2006. Delimited Dynamic Binding. In Proceedings of the International Conference on Functional Programming. ACM, New York, NY, USA. 26–37.Google Scholar
Digital Library
- Daan Leijen. 2005. Extensible records with scoped labels. In Proceedings of the Symposium on Trends in Functional Programming. 297–312.Google Scholar
- Daan Leijen. 2014. Koka: Programming with Row Polymorphic Effect Types. In Proceedings of the Workshop on Mathematically Structured Functional Programming.Google Scholar
Cross Ref
- Daan Leijen. 2017. Structured Asynchrony with Algebraic Effects. In Proceedings of the Workshop on Type-Driven Development. ACM, New York, NY, USA. 16–29.Google Scholar
Digital Library
- Daan Leijen. 2017. Type directed compilation of row-typed algebraic effects. In Proceedings of the Symposium on Principles of Programming Languages. ACM, New York, NY, USA. 486–499.Google Scholar
Digital Library
- Paul Blain Levy. 1999. Call-by-Push-Value: A Subsuming Paradigm. In Typed Lambda Calculi and Applications, Jean-Yves Girard (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg. 228–243. isbn:978-3-540-48959-7Google Scholar
- Paul Blain Levy, John Power, and Hayo Thielecke. 2003. Modelling environments in call-by-value programming languages. Information and Computation, 185, 2 (2003), 182–210.Google Scholar
Digital Library
- Sam Lindley. 2018. Encapsulating effects. Dagstuhl Reports, 8, 4 (2018).Google Scholar
- Sam Lindley, Conor McBride, and Craig McLaughlin. 2017. Do Be Do Be Do. In Proceedings of the Symposium on Principles of Programming Languages. ACM, New York, NY, USA. 500–514.Google Scholar
Digital Library
- J. M. Lucassen and D. K. Gifford. 1988. Polymorphic Effect Systems. In Proceedings of the Symposium on Principles of Programming Languages (POPL ’88). Association for Computing Machinery, New York, NY, USA. 47–57. isbn:0897912527 https://doi.org/10.1145/73560.73564 Google Scholar
Digital Library
- Darya Melicher, Yangqingwei Shi, Alex Potanin, and Jonathan Aldrich. 2017. A capability-based module system for authority control. In 31st European Conference on Object-Oriented Programming (ECOOP 2017).Google Scholar
- Mark Samuel Miller. 2006. Robust Composition: Towards a Unified Approach to Access Control and Concurrency Control. Ph. D. Dissertation. Johns Hopkins University. Baltimore, Maryland, USA. AAI3245526Google Scholar
- Aleksandar Nanevski, Frank Pfenning, and Brigitte Pientka. 2008. Contextual Modal Type Theory. ACM Trans. Comput. Logic, 9, 3 (2008), Article 23, June, 49 pages. issn:1529-3785 https://doi.org/10.1145/1352582.1352591 Google Scholar
Digital Library
- Flemming Nielson, Hanne Riis Nielson, and Chris Hankin. 1999. Type and effect systems. In Principles of Program Analysis. Springer, 283–363.Google Scholar
Digital Library
- Martin Odersky, Aleksander Boruch-Gruszecki, Jonathan Immanuel Brachthäuser, Edward Lee, and Ondřej Lhoták. 2021. Safer Exceptions for Scala. In Proceedings of the 12th ACM SIGPLAN International Symposium on Scala (SCALA 2021). Association for Computing Machinery, New York, NY, USA. 1–11. https://doi.org/10.1145/3486610.3486893 Google Scholar
Digital Library
- Leo Osvald, Grégory Essertel, Xilun Wu, Lilliam I González Alayón, and Tiark Rompf. 2016. Gentrification gone too far? affordable 2nd-class values for fun and (co-) effect. In Proceedings of the Conference on Object-Oriented Programming, Systems, Languages and Applications. New York, NY, USA. 234–251.Google Scholar
Digital Library
- Leo Osvald and Tiark Rompf. 2017. Rust-like Borrowing with 2nd-Class Values (Short Paper). In Proceedings of the 8th ACM SIGPLAN International Symposium on Scala (SCALA 2017). Association for Computing Machinery, New York, NY, USA. 13–17. isbn:9781450355292 https://doi.org/10.1145/3136000.3136010 Google Scholar
Digital Library
- Tomas Petricek, Dominic Orchard, and Alan Mycroft. 2014. Coeffects: A Calculus of Context-Dependent Computation. In Proceedings of the International Conference on Functional Programming. ACM, New York, NY, USA. 123–135. https://doi.org/10.1145/2628136.2628160 Google Scholar
Digital Library
- Gordon Plotkin and John Power. 2003. Algebraic operations and generic effects. Applied Categorical Structures, 11, 1 (2003), 69–94.Google Scholar
- Gordon Plotkin and Matija Pretnar. 2009. Handlers of algebraic effects. In European Symposium on Programming. 80–94.Google Scholar
Digital Library
- Gordon D. Plotkin and Matija Pretnar. 2013. Handling Algebraic Effects. Logical Methods in Computer Science, 9, 4 (2013).Google Scholar
- Matija Pretnar. 2015. An introduction to algebraic effects and handlers. invited tutorial paper. Electronic Notes in Theoretical Computer Science, 319 (2015), 19–35.Google Scholar
Digital Library
- John C. Reynolds. 1972. Definitional Interpreters for Higher-Order Programming Languages. In Proceedings of the ACM annual conference. ACM, New York, NY, USA. 717–740.Google Scholar
Digital Library
- Lukas Rytz, Martin Odersky, and Philipp Haller. 2012. Lightweight Polymorphic Effects. In Proceedings of the European Conference on Object-Oriented Programming, James Noble (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg. 258–282.Google Scholar
Digital Library
- Gabriel Scherer and Jan Hoffmann. 2013. Tracking Data-Flow with Open Closure Types. In Logic for Programming, Artificial Intelligence, and Reasoning, Ken McMillan, Aart Middeldorp, and Andrei Voronkov (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 710–726. isbn:978-3-642-45221-5Google Scholar
- Dorai Sitaram. 1993. Handling Control. In Proceedings of the Conference on Programming Language Design and Implementation. ACM, New York, NY, USA. 147–155.Google Scholar
- Mads Tofte and Jean-Pierre Talpin. 1997. Region-Based Memory Management. Inf. Comput., 132, 2 (1997), Feb., 109–176. issn:0890-5401 https://doi.org/10.1006/inco.1996.2613 Google Scholar
Digital Library
- Andrew K. Wright and Matthias Felleisen. 1994. A syntactic approach to type soundness. Inf. Comput., 115, 1 (1994), Nov., 38–94.Google Scholar
Digital Library
- Ningning Xie, Jonathan Immanuel Brachthäuser, Daniel Hillerström, Philipp Schuster, and Daan Leijen. 2020. Effect Handlers, Evidently. Proc. ACM Program. Lang., 4, ICFP (2020), Article 99, Aug., 29 pages. 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), Article 5, Jan., 29 pages. issn:2475-1421Google Scholar
- Yizhou Zhang, Guido Salvaneschi, Quinn Beightol, Barbara Liskov, and Andrew C. Myers. 2016. Accepting Blame for Safe Tunneled Exceptions. In Proceedings of the Conference on Programming Language Design and Implementation. ACM, New York, NY, USA. 281–295.Google Scholar
- Yizhou Zhang, Guido Salvaneschi, and Andrew C. Myers. 2020. Handling Bidirectional Control Flow. Proc. ACM Program. Lang., 4, OOPSLA (2020), Article 139, Nov., 30 pages. https://doi.org/10.1145/3428207 Google Scholar
Digital Library
- Nikita Zyuzin and Aleksandar Nanevski. 2021. Contextual Modal Types for Algebraic Effects and Handlers. Proc. ACM Program. Lang., 5, ICFP (2021), Article 75, Aug., 29 pages. https://doi.org/10.1145/3473580 Google Scholar
Digital Library
Index Terms
Effects, capabilities, and boxes: from scope-based reasoning to type-based reasoning and back
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 ...
Recursive type generativity
ICFP '05: Proceedings of the tenth ACM SIGPLAN international conference on Functional programmingExistential types provide a simple and elegant foundation for understanding generative abstract data types, of the kind supported by the Standard ML module system. However, in attempting to extend ML with support for recursive modules, we have found ...
Recursive type generativity
Proceedings of the tenth ACM SIGPLAN international conference on Functional programmingExistential types provide a simple and elegant foundation for understanding generative abstract data types, of the kind supported by the Standard ML module system. However, in attempting to extend ML with support for recursive modules, we have found ...






Comments