Skip to main content

Linearity and Uniqueness: An Entente Cordiale

Part of the Lecture Notes in Computer Science book series (LNCS,volume 13240)

Abstract

Substructural type systems are growing in popularity because they allow for a resourceful interpretation of data which can be used to rule out various software bugs. Indeed, substructurality is finally taking hold in modern programming; Haskell now has linear types roughly based on Girard’s linear logic but integrated via graded function arrows, Clean has uniqueness types designed to ensure that values have at most a single reference to them, and Rust has an intricate ownership system for guaranteeing memory safety. But despite this broad range of resourceful type systems, there is comparatively little understanding of their relative strengths and weaknesses or whether their underlying frameworks can be unified. There is often confusion about whether linearity and uniqueness are essentially the same, or are instead ‘dual’ to one another, or somewhere in between. This paper formalises the relationship between these two well-studied but rarely contrasted ideas, building on two distinct bodies of literature, showing that it is possible and advantageous to have both linear and unique types in the same type system. We study the guarantees of the resulting system and provide a practical implementation in the graded modal setting of the Granule language, adding a third kind of modality alongside coeffect and effect modalities. We then demonstrate via a benchmark that our implementation benefits from expected efficiency gains enabled by adding uniqueness to a language that already has a linear basis.

Keywords

  • linear types
  • uniqueness types
  • substructural logic

References

  1. Ahrens, B., Spadotti, R.: Terminal semantics for codata types in intensional Martin-Löf type theory. In: Herbelin, H., Letouzey, P., Sozeau, M. (eds.) 20th International Conference on Types for Proofs and Programs (TYPES 2014). Leibniz International Proceedings in Informatics (LIPIcs), vol. 39, pp. 1–26. Schloss Dagstuhl, Germany (Oct 2015). https://doi.org/10.4230/LIPIcs.TYPES.2014.1

  2. Aldrich, J., Kostadinov, V., Chambers, C.: Alias annotations for program understanding. In: Proceedings of the 17th ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications. p. 311–330. OOPSLA ’02, Association for Computing Machinery, New York, NY, USA (2002). https://doi.org/10.1145/582419.582448

  3. Altenkirch, T., Chapman, J., Uustalu, T.: Monads need not be endofunctors. Logical Methods in Computer Science 11(1) (Mar 2015). https://doi.org/10.2168/lmcs-11(1:3)2015

  4. Baker, H.G.: Lively linear Lisp: “look ma, no garbage!". SIGPLAN Not. 27(8), 89–98 (Aug 1992). https://doi.org/10.1145/142137.142162

  5. Barendsen, E., Smetsers, S.: Conventional and uniqueness typing in graph rewrite systems. In: International Conference on Foundations of Software Technology and Theoretical Computer Science. pp. 41–51. Springer (1993)

    Google Scholar 

  6. Benton, P.N.: A mixed linear and non-linear logic: Proofs, terms and models. In: Pacholski, L., Tiuryn, J. (eds.) Computer Science Logic. pp. 121–135. Springer Berlin Heidelberg, Berlin, Heidelberg (1995)

    Google Scholar 

  7. Bernardy, J.P., Boespflug, M., Newton, R.R., Peyton Jones, S., Spiwack, A.: Linear Haskell: Practical linearity in a higher-order polymorphic language. Proc. ACM Program. Lang. 2(POPL) (Dec 2017). https://doi.org/10.1145/3158093

  8. Boyland, J.: Checking interference with fractional permissions. In: Cousot, R. (ed.) Static Analysis. pp. 55–72. Springer Berlin Heidelberg, Berlin, Heidelberg (2003)

    Google Scholar 

  9. Brady, E.: Idris 2: Quantitative Type Theory in Practice. In: Møller, A., Sridharan, M. (eds.) 35th European Conference on Object-Oriented Programming (ECOOP 2021). Leibniz International Proceedings in Informatics (LIPIcs), vol. 194, pp. 9:1–9:26. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, Dagstuhl, Germany (2021). https://doi.org/10.4230/LIPIcs.ECOOP.2021.9, https://drops.dagstuhl.de/opus/volltexte/2021/14052

  10. Bryant, A.B., Eades, H.D.: The graded Lambek calculus. In: 2020 Joint Workshop on Linearity & TLLA: The 6th Workshop on Linearity and the 4th Workshop on Trends in Linear Logic and Applications (2020), https://www.cs.unibo.it/~dallago/TLLALINEARITY2020/The_Graded_Lambek_Calculus.pdf

  11. Choudhury, P., Eades III, H., Eisenberg, R.A., Weirich, S.: A graded dependent type system with a usage-aware semantics. Proceedings of the ACM on Programming Languages 5(POPL), 1–32 (2021)

    Google Scholar 

  12. Choudhury, V., Krishnaswami, N.: Recovering purity with comonads and capabilities. Proc. ACM Program. Lang. 4(ICFP), 111:1–111:28 (2020). https://doi.org/10.1145/3408993

  13. Coutts, D., Leshchinskiy, R., Stewart, D.: Stream fusion: From lists to streams to nothing at all. In: Proceedings of the 12th ACM SIGPLAN International Conference on Functional Programming. p. 315–326. ICFP ’07, Association for Computing Machinery, New York, NY, USA (2007). https://doi.org/10.1145/1291151.1291199

  14. Fluet, M., Morrisett, G., Ahmed, A.: Linear regions are all you need. In: Sestoft, P. (ed.) Programming Languages and Systems. pp. 7–21. Springer Berlin Heidelberg, Berlin, Heidelberg (2006)

    Google Scholar 

  15. Girard, J.Y.: Linear logic. Theoretical Computer Science 50(1), 1 – 101 (1987). https://doi.org/10.1016/0304-3975(87)90045-4, http://www.sciencedirect.com/science/article/pii/0304397587900454

  16. Girard, J.Y., Scedrov, A., Scott, P.J.: Bounded linear logic: a modular approach to polynomial-time computability. Theoretical computer science 97(1), 1–66 (1992)

    Google Scholar 

  17. Gordon, C.S.: Designing with Static Capabilities and Effects: Use, Mention, and Invariants (Pearl). In: Hirschfeld, R., Pape, T. (eds.) 34th European Conference on Object-Oriented Programming (ECOOP 2020). Leibniz International Proceedings in Informatics (LIPIcs), vol. 166, pp. 10:1–10:25. Schloss Dagstuhl–Leibniz-Zentrum für Informatik, Dagstuhl, Germany (2020). https://doi.org/10.4230/LIPIcs.ECOOP.2020.10, https://drops.dagstuhl.de/opus/volltexte/2020/13167

  18. Guzman, J., Hudak, P.: Single-threaded polymorphic lambda calculus. In: [1990] Proceedings. Fifth Annual IEEE Symposium on Logic in Computer Science. pp. 333–343 (1990). https://doi.org/10.1109/LICS.1990.113759

  19. Haller, P., Odersky, M.: Capabilities for uniqueness and borrowing. In: D’Hondt, T. (ed.) ECOOP 2010 – Object-Oriented Programming. pp. 354–378. Springer Berlin Heidelberg, Berlin, Heidelberg (2010)

    Google Scholar 

  20. Harrington, D.: Uniqueness logic. Theoretical Computer Science 354(1), 24–41 (2006)

    Google Scholar 

  21. Hicks, M., Morrisett, G., Grossman, D., Jim, T.: Experience with safe manual memory-management in Cyclone. In: Proceedings of the 4th International Symposium on Memory Management. p. 73–84. ISMM ’04, Association for Computing Machinery, New York, NY, USA (2004). https://doi.org/10.1145/1029873.1029883

  22. Hughes, J., Marshall, D., Wood, J., Orchard, D.: Linear Exponentials as Graded Modal Types. In: 5th International Workshop on Trends in Linear Logic and Applications (TLLA 2021). Rome (virtual), Italy (Jun 2021), https://hal-lirmm.ccsd.cnrs.fr/lirmm-03271465

  23. Jouvelot, P., Gifford, D.: Algebraic reconstruction of types and effects. In: Proceedings of the 18th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. p. 303–310. POPL ’91, Association for Computing Machinery, New York, NY, USA (1991). https://doi.org/10.1145/99583.99623

  24. Jung, R., Jourdan, J.H., Krebbers, R., Dreyer, D.: RustBelt: Securing the foundations of the Rust programming language. Proc. ACM Program. Lang. 2(POPL) (Dec 2017). https://doi.org/10.1145/3158154

  25. Keller, G., Chakravarty, M.M., Leshchinskiy, R., Peyton Jones, S., Lippmeier, B.: Regular, Shape-Polymorphic, Parallel Arrays in Haskell. In: Proceedings of the 15th ACM SIGPLAN International Conference on Functional Programming. p. 261–272. ICFP ’10, Association for Computing Machinery, New York, NY, USA (2010). https://doi.org/10.1145/1863543.1863582

  26. Lucassen, J.M., Gifford, D.K.: Polymorphic effect systems. In: Proceedings of the 15th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. p. 47–57. POPL ’88, Association for Computing Machinery, New York, NY, USA (1988). https://doi.org/10.1145/73560.73564

  27. Mainland, G., Leshchinskiy, R., Peyton Jones, S.: Exploiting vector instructions with generalized stream fusion. In: Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming. p. 37–48. ICFP ’13, Association for Computing Machinery, New York, NY, USA (2013). https://doi.org/10.1145/2500365.2500601

  28. Marshall, D., Vollmer, M., Orchard, D.: Linearity and Uniqueness: An Entente Cordiale (Appendix). https://doi.org/10.5281/zenodo.5919193

  29. Marshall, D., Vollmer, M., Orchard, D.: Linearity and Uniqueness: An Entente Cordiale (Artifact). https://doi.org/10.5281/zenodo.5919209

  30. McBride, C.: I Got Plenty o’ Nuttin’. In: A List of Successes That Can Change the World - Essays Dedicated to Philip Wadler on the Occasion of His 60th Birthday. pp. 207–233 (2016). https://doi.org/10.1007/978-3-319-30936-1_12

  31. Moon, B., Eades III, H., Orchard, D.: Graded modal dependent type theory. In: Yoshida, N. (ed.) Programming Languages and Systems. pp. 462–490. Springer International Publishing, Cham (2021)

    Google Scholar 

  32. Morris, J.G.: The Best of Both Worlds: Linear Functional Programming without Compromise. In: Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming. p. 448–461. ICFP 2016, Association for Computing Machinery, New York, NY, USA (2016). https://doi.org/10.1145/2951913.2951925

  33. Morrisett, G., Ahmed, A., Fluet, M.: L\(^3\): A linear language with locations. In: Urzyczyn, P. (ed.) Typed Lambda Calculi and Applications. pp. 293–307. Springer Berlin Heidelberg, Berlin, Heidelberg (2005)

    Google Scholar 

  34. Mycroft, A., Voigt, J.: Notions of aliasing and ownership. In: Clarke, D., Noble, J., Wrigstad, T. (eds.) Aliasing in Object-Oriented Programming. Types, Analysis and Verification, Lecture Notes in Computer Science, vol. 7850, pp. 59–83. Springer (2013). https://doi.org/10.1007/978-3-642-36946-9_4

  35. O’Connor, L., Chen, Z., Rizkallah, C., Jackson, V., Amani, S., Klein, G., Murray, T., Sewell, T., Keller, G.: Cogent: Uniqueness types and certified compilation. J. Funct. Program. (2021)

    Google Scholar 

  36. Orchard, D., Liepelt, V.B., Eades III, H.: Quantitative Program Reasoning with Graded Modal Types. Proc. ACM Program. Lang. 3(ICFP) (Jul 2019). https://doi.org/10.1145/3341714

  37. Orchard, D., Mycroft, A.: Categorical programming for data types with restricted parametricity. Unpublished note. (2012), https://www.cs.kent.ac.uk/people/staff/dao7/drafts/tfp-structures-orchard12.pdf

  38. Paykin, J., Zdancewic, S.: The linearity monad. In: Proceedings of the 10th ACM SIGPLAN International Symposium on Haskell. p. 117–132. Haskell 2017, Association for Computing Machinery, New York, NY, USA (2017). https://doi.org/10.1145/3122955.3122965

  39. Pearce, D.J.: A lightweight formalism for reference lifetimes and borrowing in Rust. ACM Trans. Program. Lang. Syst. 43(1) (Apr 2021). https://doi.org/10.1145/3443420

  40. Plasmeijer, R., van Eekelen, M., van Groningen, J.: Clean Version 2.2 Language Report (2011), https://clean.cs.ru.nl/download/doc/CleanLangRep.2.2.pdf

  41. Pottier, F., Protzenko, J.: Programming with permissions in Mezzo. In: Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming. p. 173–184. ICFP ’13, Association for Computing Machinery, New York, NY, USA (2013). https://doi.org/10.1145/2500365.2500598

  42. Prawitz, D.: Natural Deduction: A proof-theoretical study. Stockholm Studies in Philosophy. Almqvist & Wiksell, Stockholm 3 (1965)

    Google Scholar 

  43. Radanne, G., Saffrich, H., Thiemann, P.: Kindly bent to free us. Proc. ACM Program. Lang. 4(ICFP) (Aug 2020). https://doi.org/10.1145/3408985

  44. Sammler, M., Lepigre, R., Krebbers, R., Memarian, K., Dreyer, D., Garg, D.: RefinedC: Automating the foundational verification of C code with refined ownership types. Proc. ACM Program. Lang. (Jun 2021)

    Google Scholar 

  45. Scholz, S.B.: Single Assignment C - Entwurf und Implementierung einer funktionalen C-Variante mit spezieller Unterstützung shape-invarianter Array-Operationen. Ph.D. thesis, Institut für Informatik und Praktische Mathematik, Christian-Albrechts-Universität, Kiel, Germany (1996), https://www.sac-home.org/_media/publications:pdf:sac-design-sbs-phd-96.pdf, Shaker Verlag, Aachen, 1997

  46. Selinger, P., Valiron, B.: Quantum Lambda Calculus, p. 135–172. Cambridge University Press (2009). https://doi.org/10.1017/CBO9781139193313.005

  47. Smetsers, S., Barendsen, E., van Eekelen, M., Plasmeijer, R.: Guaranteeing safe destructive updates through a type system with uniqueness information for graphs. In: Schneider, H.J., Ehrig, H. (eds.) Graph Transformations in Computer Science. pp. 358–379. Springer, Berlin Heidelberg, Berlin, Heidelberg (1994). https://doi.org/10.1007/3-540-57787-4_23

  48. Somogyi, Z., Henderson, F., Conway, T.: The execution algorithm of Mercury, an efficient purely declarative logic programming language. The Journal of Logic Programming 29(1), 17–64 (1996). https://doi.org/10.1016/S0743-1066(96)00068-4, https://www.sciencedirect.com/science/article/pii/S0743106696000684, high-Performance Implementations of Logic Programming Systems

  49. Spiwack, A., Kiss, C., Bernardy, J.P., Wu, N., Eisenberg, R.: Linear constraints (2021), https://arxiv.org/abs/2103.06127

  50. Terui, K.: Light affine lambda calculus and polytime strong normalization. In: LICS ’01. pp. 209–220. IEEE Computer Society (2001)

    Google Scholar 

  51. Tofte, M., Birkedal, L., Elsman, M., Hallenberg, N.: A Retrospective on Region-Based Memory Management. Higher-Order and Symbolic Computation 17(3), 245–265 (Sep 2004). https://doi.org/10.1023/B:LISP.0000029446.78563.a4

  52. Tov, J.A., Pucella, R.: Practical affine types. In: Proceedings of the 38th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. p. 447–458. POPL ’11, Association for Computing Machinery, New York, NY, USA (2011). https://doi.org/10.1145/1926385.1926436

  53. de Vries, E.: Modelling unique and affine typing using polymorphism. In: Essays Dedicated to Rinus Plasmeijer on the Occasion of His 61st Birthday on The Beauty of Functional Code - Volume 8106. p. 181–192. Springer-Verlag, Berlin, Heidelberg (2013). https://doi.org/10.1007/978-3-642-40355-2_13

  54. de Vries, E., Francalanza, A., Hennessy, M.: Uniqueness typing for resource management in message-passing concurrency. In: Florido, M., Mackie, I. (eds.) Proceedings First International Workshop on Linearity, LINEARITY 2009, Coimbra, Portugal, 12th September 2009. EPTCS, vol. 22, pp. 26–37 (2009). https://doi.org/10.4204/EPTCS.22.3

  55. de Vries, E., Plasmeijer, R., Abrahamson, D.M.: Uniqueness typing redefined. In: Proceedings of the 18th International Conference on Implementation and Application of Functional Languages. p. 181–198. IFL’06, Springer-Verlag, Berlin, Heidelberg (2006)

    Google Scholar 

  56. de Vries, E., Plasmeijer, R., Abrahamson, D.M.: Uniqueness typing simplified. In: Chitil, O., Horváth, Z., Zsók, V. (eds.) Implementation and Application of Functional Languages. pp. 201–218. Springer Berlin Heidelberg, Berlin, Heidelberg (2008)

    Google Scholar 

  57. Wadler, P.: Linear Types Can Change the World! In: Broy, M., Jones, C.B. (eds.) Programming Concepts and Methods: Proceedings of the IFIP Working Group 2.2/2.3 Working Conference on Programming Concepts and Methods, Sea of Galilee, Israel, 2–5 April, 1990. pp. 561–581. North-Holland, Amsterdam (1990), https://homepages.inf.ed.ac.uk/wadler/topics/linear-logic.html#linear-types

  58. Wadler, P.: Is there a use for linear logic? In: Proceedings of the 1991 ACM SIGPLAN Symposium on Partial Evaluation and Semantics-Based Program Manipulation. p. 255–273. PEPM ’91, Association for Computing Machinery, New York, NY, USA (1991). https://doi.org/10.1145/115865.115894

  59. Wadler, P.: There’s no substitute for linear logic. In: 8th International Workshop on the Mathematical Foundations of Programming Semantics (1992)

    Google Scholar 

  60. Wadler, P.: A syntax for linear logic. In: Mathematical Foundations of Programming Semantics, 9th International Conference, New Orleans, LA, USA, April 7–10, 1993, Proceedings. pp. 513–529 (1993). https://doi.org/10.1007/3-540-58027-1_24

  61. Wadler, P.: A taste of linear logic. In: Borzyszkowski, A.M., Sokołowski, S. (eds.) Mathematical Foundations of Computer Science 1993. pp. 185–210. Springer Berlin Heidelberg, Berlin, Heidelberg (1993)

    Google Scholar 

  62. Walker, D.: Substructural type systems. Advanced Topics in Types and Programming Languages pp. 3–44 (2005)

    Google Scholar 

  63. Walker, D., Crary, K., Morrisett, G.: Typed memory management via static capabilities. ACM Trans. Program. Lang. Syst. 22(4), 701–771 (jul 2000). https://doi.org/10.1145/363911.363923

  64. Weiss, A., Gierczak, O., Patterson, D., Ahmed, A.: Oxide: The essence of Rust (2021), https://arxiv.org/abs/1903.00982

  65. Zhu, D., Xi, H.: Safe programming with pointers through stateful views. In: Hermenegildo, M.V., Cabeza, D. (eds.) Practical Aspects of Declarative Languages. pp. 83–97. Springer Berlin Heidelberg, Berlin, Heidelberg (2005)

    Google Scholar 

Download references

Author information

Affiliations

Authors

Corresponding author

Correspondence to Daniel Marshall .

Rights and permissions

Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes were made.

The images or other third party material in this chapter are included in the chapter's Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the chapter's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.

Reprints and Permissions

Copyright information

© 2022 The Author(s)

About this paper

Verify currency and authenticity via CrossMark

Cite this paper

Marshall, D., Vollmer, M., Orchard, D. (2022). Linearity and Uniqueness: An Entente Cordiale. In: Sergey, I. (eds) Programming Languages and Systems. ESOP 2022. Lecture Notes in Computer Science, vol 13240. Springer, Cham. https://doi.org/10.1007/978-3-030-99336-8_13

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-99336-8_13

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-99335-1

  • Online ISBN: 978-3-030-99336-8

  • eBook Packages: Computer ScienceComputer Science (R0)