skip to main content
research-article
Open Access

Linearly qualified types: generic inference for capabilities and uniqueness

Published:31 August 2022Publication History
Skip Abstract Section

Abstract

A linear parameter must be consumed exactly once in the body of its function. When declaring resources such as file handles and manually managed memory as linear arguments, a linear type system can verify that these resources are used safely. However, writing code with explicit linear arguments requires bureaucracy. This paper presents linear constraints, a front-end feature for linear typing that decreases the bureaucracy of working with linear types. Linear constraints are implicit linear arguments that are filled in automatically by the compiler. We present linear constraints as a qualified type system,together with an inference algorithm which extends GHC's existing constraint solver algorithm. Soundness of linear constraints is ensured by the fact that they desugar into Linear Haskell.

References

  1. Andreas Abel and Jean-Philippe Bernardy. 2020. A unified view of modalities in type systems. Proceedings of the ACM on Programming Languages, 4, ICFP (2020). Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Jean-Philippe Bernardy, Mathieu Boespflug, Ryan R. Newton, Simon Peyton Jones, and Arnaud Spiwack. 2017. Linear Haskell: Practical Linearity in a Higher-order Polymorphic Language. Proc. ACM Program. Lang., 2, POPL (2017), Article 5, Dec., 29 pages. issn:2475-1421 https://doi.org/10.1145/3158093 Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Gert-Jan Bottu, Georgios Karachalias, Tom Schrijvers, Bruno C. d. S. Oliveira, and Philip Wadler. 2017. Quantified Class Constraints. In Proceedings of the 10th ACM SIGPLAN International Symposium on Haskell (Haskell 2017). Association for Computing Machinery, New York, NY, USA. 148–161. isbn:9781450351829 https://doi.org/10.1145/3122955.3122967 Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Iliano Cervesato, Joshua S. Hodas, and Frank Pfenning. 2000. Efficient resource management for linear logic proof search. Theoretical Computer Science, 232, 1 (2000), 133 – 163. issn:0304-3975 https://doi.org/10.1016/S0304-3975(99)00173-5 Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Karl Crary, David Walker, and J. Gregory Morrisett. 1999. Typed Memory Management in a Calculus of Capabilities. In POPL ’99, Proceedings of the 26th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, San Antonio, TX, USA, January 20-22, 1999, Andrew W. Appel and Alex Aiken (Eds.). ACM, 262–275. https://doi.org/10.1145/292540.292564 Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Vincent Danos, Jean Baptiste Joinet, and Harold Schellinx. 1993. The structure of exponentials: Uncovering the dynamics of linear logic proofs. In Computational Logic and Proof Theory, Georg Gottlob, Alexander Leitsch, and Daniele Mundici (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 159–171. isbn:978-3-540-47943-7 Google ScholarGoogle Scholar
  7. Robert DeLine and Manuel Fähndrich. 2001. Enforcing High-Level Protocols in Low-Level Software. In Proceedings of the 2001 ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI), Snowbird, Utah, USA, June 20-22, 2001, Michael Burke and Mary Lou Soffa (Eds.). ACM, 59–69. https://doi.org/10.1145/378795.378811 Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Facundo Domínguez. 2020. Safe memory management in inline-java using linear types. https://web.archive.org/web/20200926082552/https://www.tweag.io/blog/2020-02-06-safe-inline-java/ Blog post Google ScholarGoogle Scholar
  9. Richard A. Eisenberg, Guillaume Duboc, Stephanie Weirich, and Daniel Lee. 2021. An Existential Crisis Resolved: Type inference for first-class existential types. Proc. ACM Program. Lang., 5, ICFP (2021). Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Richard A. Eisenberg, Stephanie Weirich, and Hamidhasan G. Ahmed. 2016. Visible Type Application. In Programming Languages and Systems, Peter Thiemann (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg. 229–254. isbn:978-3-662-49498-1 Google ScholarGoogle Scholar
  11. Matthew Fluet, Greg Morrisett, and Amal J. Ahmed. 2006. Linear Regions Are All You Need. In Programming Languages and Systems, 15th European Symposium on Programming, ESOP 2006, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2006, Vienna, Austria, March 27-28, 2006, Proceedings, Peter Sestoft (Ed.) (Lecture Notes in Computer Science, Vol. 3924). Springer, 7–21. https://doi.org/10.1007/11693024_2 Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Jean-Yves Girard. 1987. Linear logic. Theoretical Computer Science, 50, 1 (1987), 1–101. issn:0304-3975 https://doi.org/10.1016/0304-3975(87)90045-4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Cordelia V. Hall, Kevin Hammond, Simon L. Peyton Jones, and Philip L. Wadler. 1996. Type Classes in Haskell. ACM Trans. Program. Lang. Syst., 18, 2 (1996), March. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. J.S. Hodas and D. Miller. 1994. Logic Programming in a Fragment of Intuitionistic Linear Logic. Information and Computation, 110, 2 (1994), 327 – 365. issn:0890-5401 https://doi.org/inco.1994.1036 Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Joshua Seth Hodas. 1994. Logic programming in intuitionistic linear logic: Theory, design, and implementation. https://repository.upenn.edu/dissertations/AAI9427546 Google ScholarGoogle Scholar
  16. Mark P. Jones. 1994. A theory of qualified types. Science of Computer Programming, 22, 3 (1994), 231 – 256. issn:0167-6423 https://doi.org/10.1016/0167-6423(94)00005-0 Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Csongor Kiss, Arnaud Spiwack, Jean-Philippe Bernardy, Nicolas Wu, and Richard A. Eisenberg. 2022. Prototype implementation of linear constraints in GHC. http://archive.softwareheritage.org/swh:1:rev:f6fc5ba23770b42d1d6020e177787757b16a9ea0;origin=https://github.com/kcsongor/ghc;visit=swh:1:snp:aa61d803eaec9eb4425e3eb8ed2b0fbbd60633cc Code fragment Google ScholarGoogle Scholar
  18. Naoki Kobayashi, Benjamin C. Pierce, and David N. Turner. 1999. Linearity and the Pi-Calculus. ACM Trans. Program. Lang. Syst., 21, 5 (1999), Sept., 914–947. issn:0164-0925 https://doi.org/10.1145/330249.330251 Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Kazutaka Matsuda. 2020. Modular Inference of Linear Types for Multiplicity-Annotated Arrows. In Programming Languages and Systems, Peter Müller (Ed.). Springer International Publishing, Cham. 456–483. isbn:978-3-030-44914-8 Google ScholarGoogle Scholar
  20. Dale A. Miller, Gopalan Nadathur, and Andre Scedrov. 1987. Hereditary Harrop Formulas and Uniform Proof Systems. In Proceedings of the Second Annual IEEE Symposium on Logic in Computer Science (LICS 1987). IEEE Computer Society Press, 98–105. Google ScholarGoogle Scholar
  21. Simon Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Mark Shields. 2007. Practical type inference for arbitrary-rank types. Journal of Functional Programming, 17, 1 (2007), 1–82. https://doi.org/10.1017/S0956796806006034 Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Benjamin C. Pierce. 2002. Types and Programming Languages. MIT Press, Cambridge, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. François Pottier and Jonathan Protzenko. 2013. Programming with Permissions in Mezzo. In Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming (ICFP ’13). Association for Computing Machinery, New York, NY, USA. 173–184. isbn:9781450323260 https://doi.org/10.1145/2500365.2500598 Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. François Pottier and Didier Rémy. 2005. The essence of ML type inference. Google ScholarGoogle Scholar
  25. Gabriel Radanne, Hannes Saffrich, and Peter Thiemann. 2020. Kindly Bent to Free Us. Proc. ACM Program. Lang., 4, ICFP (2020), Article 103, Aug., 29 pages. https://doi.org/10.1145/3408985 Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Michael Shulman. 2018. Linear logic for constructive mathematics. arxiv:1805.07518. Google ScholarGoogle Scholar
  27. Frederick Smith, David Walker, and J. Gregory Morrisett. 2000. Alias Types. In Programming Languages and Systems, 9th European Symposium on Programming, ESOP 2000, Held as Part of the European Joint Conferences on the Theory and Practice of Software, ETAPS 2000, Berlin, Germany, March 25 - April 2, 2000, Proceedings, Gert Smolka (Ed.) (Lecture Notes in Computer Science, Vol. 1782). Springer, 366–381. https://doi.org/10.1007/3-540-46425-5_24 Google ScholarGoogle ScholarCross RefCross Ref
  28. Arnaud Spiwack, Csongor Kiss, Jean-Philippe Bernardy, Nicolas Wu, and Richard A. Eisenberg. 2021. Linear Constraints. CoRR, abs/2103.06127 (2021), arXiv:2103.06127. arxiv:2103.06127 Google ScholarGoogle Scholar
  29. Martin Sulzmann, Manuel M. T. Chakravarty, Simon Peyton Jones, and Kevin Donnelly. 2007. System F with Type Equality Coercions. In Proceedings of the 2007 ACM SIGPLAN International Workshop on Types in Languages Design and Implementation (TLDI ’07). Association for Computing Machinery, New York, NY, USA. 53–66. isbn:159593393X https://doi.org/10.1145/1190315.1190324 Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Dimitrios Vytiniotis, Simon Peyton Jones, and Tom Schrijvers. 2010. Let Should Not Be Generalized. In Proceedings of the 5th ACM SIGPLAN Workshop on Types in Language Design and Implementation (TLDI ’10). Association for Computing Machinery, New York, NY, USA. 39–50. isbn:9781605588919 https://doi.org/10.1145/1708016.1708023 Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Dimitrios Vytiniotis, Simon Peyton Jones, Tom Schrijvers, and Martin Sulzmann. 2011. OutsideIn(X) Modular type inference with local assumptions. Journal of Functional Programming, 21, 4-5 (2011), 333–412. https://doi.org/10.1017/S0956796811000098 Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. David Walker and J. Gregory Morrisett. 2000. Alias Types for Recursive Data Structures. In Types in Compilation, Third International Workshop, TIC 2000, Montreal, Canada, September 21, 2000, Revised Selected Papers, Robert Harper (Ed.) (Lecture Notes in Computer Science, Vol. 2071). Springer, 177–206. https://doi.org/10.1007/3-540-45332-6_7 Google ScholarGoogle ScholarCross RefCross Ref
  33. Stephanie Weirich, Antoine Voizard, Pedro Henrique Azevedo de Amorim, and Richard A. Eisenberg. 2017. A Specification for Dependent Types in Haskell. Proc. ACM Program. Lang., 1, ICFP (2017), Article 31, Aug., 29 pages. https://doi.org/10.1145/3110275 Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Dengping Zhu and Hongwei Xi. 2005. Safe Programming with Pointers Through Stateful Views. In Practical Aspects of Declarative Languages, Manuel V. Hermenegildo and Daniel Cabeza (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 83–97. isbn:978-3-540-30557-6 Google ScholarGoogle Scholar

Index Terms

  1. Linearly qualified types: generic inference for capabilities and uniqueness

        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!