skip to main content

Effects, capabilities, and boxes: from scope-based reasoning to type-based reasoning and back

Published:29 April 2022Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. 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 ScholarGoogle Scholar
  4. Yves Bertot and Pierre Castéran. 2004. Interactive Theorem Proving and Program Development, Coq’Art:The Calculus of Inductive Constructions. Springer-Verlag.Google ScholarGoogle Scholar
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. 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 ScholarGoogle Scholar
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. 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 ScholarGoogle ScholarCross RefCross Ref
  11. Jonathan Immanuel Brachthäuser and Daan Leijen. 2019. Programming with Implicit Values, Functions, and Control. Microsoft Research.Google ScholarGoogle Scholar
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle Scholar
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. Stephen Dolan, Spiros Eliopoulos, Daniel Hillerström, Anil Madhavapeddy, KC Sivaramakrishnan, and Leo White. 2017. Effectively Tackling the Awkward Squad. In ML Workshop.Google ScholarGoogle Scholar
  18. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  19. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  21. 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 ScholarGoogle ScholarCross RefCross Ref
  22. 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 ScholarGoogle Scholar
  23. John Hannan. 1998. A Type-based Escape Analysis for Functional Languages. Journal of Functional Programming, 8, 3 (1998), May, 239–273.Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  25. Daan Leijen. 2005. Extensible records with scoped labels. In Proceedings of the Symposium on Trends in Functional Programming. 297–312.Google ScholarGoogle Scholar
  26. Daan Leijen. 2014. Koka: Programming with Row Polymorphic Effect Types. In Proceedings of the Workshop on Mathematically Structured Functional Programming.Google ScholarGoogle ScholarCross RefCross Ref
  27. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  28. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  29. 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 ScholarGoogle Scholar
  30. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  31. Sam Lindley. 2018. Encapsulating effects. Dagstuhl Reports, 8, 4 (2018).Google ScholarGoogle Scholar
  32. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  33. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  34. 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 ScholarGoogle Scholar
  35. 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 ScholarGoogle Scholar
  36. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  37. Flemming Nielson, Hanne Riis Nielson, and Chris Hankin. 1999. Type and effect systems. In Principles of Program Analysis. Springer, 283–363.Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  39. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  40. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  41. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  42. Gordon Plotkin and John Power. 2003. Algebraic operations and generic effects. Applied Categorical Structures, 11, 1 (2003), 69–94.Google ScholarGoogle Scholar
  43. Gordon Plotkin and Matija Pretnar. 2009. Handlers of algebraic effects. In European Symposium on Programming. 80–94.Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. Gordon D. Plotkin and Matija Pretnar. 2013. Handling Algebraic Effects. Logical Methods in Computer Science, 9, 4 (2013).Google ScholarGoogle Scholar
  45. Matija Pretnar. 2015. An introduction to algebraic effects and handlers. invited tutorial paper. Electronic Notes in Theoretical Computer Science, 319 (2015), 19–35.Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  47. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  48. 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 ScholarGoogle Scholar
  49. Dorai Sitaram. 1993. Handling Control. In Proceedings of the Conference on Programming Language Design and Implementation. ACM, New York, NY, USA. 147–155.Google ScholarGoogle Scholar
  50. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  51. Andrew K. Wright and Matthias Felleisen. 1994. A syntactic approach to type soundness. Inf. Comput., 115, 1 (1994), Nov., 38–94.Google ScholarGoogle ScholarDigital LibraryDigital Library
  52. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  53. 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 ScholarGoogle Scholar
  54. 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 ScholarGoogle Scholar
  55. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  56. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Effects, capabilities, and boxes: from scope-based reasoning to type-based reasoning and back

        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

        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!