skip to main content

Distributing intersection and union types with splits and duality (functional pearl)

Published:19 August 2021Publication History
Skip Abstract Section

Abstract

Subtyping with intersection and union types is nowadays common in many programming languages. From the perspective of logic, the subtyping problem is essentially the problem of determining logical entailment: does a logical statement follow from another one? Unfortunately, algorithms for deciding subtyping and logical entailment with intersections, unions and various distributivity laws can be highly non-trivial.

This functional pearl presents a novel algorithmic formulation for subtyping (and logical entailment) in the presence of various distributivity rules between intersections, unions and implications (i.e. function types). Unlike many existing algorithms which first normalize types and then apply a subtyping algorithm on the normalized types, our new subtyping algorithm works directly on source types. Our algorithm is based on two recent ideas: a generalization of subtyping based on the duality of language constructs called duotyping; and splittable types, which characterize types that decompose into two simpler types. We show that our algorithm is sound, complete and decidable with respect to a declarative formulation of subtyping based on the minimal relevant logic B+. Moreover, it leads to a simple and compact implementation in under 50 lines of functional code.

Skip Supplemental Material Section

Supplemental Material

Auxiliary Presentation Video

This is a presentation video of my talk at ICFP 2021 on our paper accepted in the research track. This functional pearl presents a novel algorithmic formulation for subtyping (and logical entailment) in the presence of various distributivity rules between intersections, unions and implications (i.e. function types). Unlike many existing algorithms which first normalize types and then apply a subtyping algorithm on the normalized types, our new subtyping algorithm works directly on source types. Our algorithm is based on two recent ideas: a generalization of subtyping based on the duality of language constructs called duotyping; and splittable types, which characterize types that decompose into two simpler types. We show that our algorithm is sound, complete and decidable with respect to a declarative formulation of subtyping based on the minimal relevant logic B+. Moreover, it leads to a simple and compact implementation in under 50 lines of functional code.

3473594.mp4

Presentation Videos

References

  1. Nada Amin, Karl Samuel Grütter, Martin Odersky, Tiark Rompf, and Sandro Stucki. 2016. The Essence of Dependent Object Types. A List of Successes That Can Change the World: Essays Dedicated to Philip Wadler on the Occasion of His 60th Birthday, 249–272. https://doi.org/10.1007/978-3-319-30936-1_14 Google ScholarGoogle ScholarCross RefCross Ref
  2. F. Barbanera, M. Dezaniciancaglini, and U. Deliguoro. 1995. Intersection and Union Types: Syntax and Semantics. Information and Computation, 119, 2 (1995), 202–230. issn:0890-5401 https://doi.org/10.1006/inco.1995.1086 Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Henk Barendregt, Mario Coppo, and Mariangiola Dezani-Ciancaglini. 1983. A Filter Lambda Model and the Completeness of Type Assignment. The Journal of Symbolic Logic, 48, 4 (1983), 931–940. issn:00224812 http://www.jstor.org/stable/2273659Google ScholarGoogle ScholarCross RefCross Ref
  4. Véronique Benzaken, Giuseppe Castagna, and Alain Frisch. 2003. CDuce: An XML-Centric General-Purpose Language. 51–63. isbn:1581137567 https://doi.org/10.1145/944705.944711 Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Jeff Bezanson, Alan Edelman, Stefan Karpinski, and Viral B. Shah. 2017. Julia: A Fresh Approach to Numerical Computing. SIAM Rev., 59, 1 (2017), 65–98. https://doi.org/10.1137/141000671 Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Xuan Bi, Bruno C. d. S. Oliveira, and Tom Schrijvers. 2018. The Essence of Nested Composition. In 32nd European Conference on Object-Oriented Programming, ECOOP 2018, July 16-21, 2018, Amsterdam, The Netherlands, Todd D. Millstein (Ed.) (LIPIcs, Vol. 109). Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 22:1–22:33. https://doi.org/10.4230/LIPIcs.ECOOP.2018.22 Google ScholarGoogle Scholar
  7. Arthur Charguéraud and François Pottier. [n.d.]. TLC: a non-constructive library for Coq. https://www.chargueraud.org/softs/tlc/Google ScholarGoogle Scholar
  8. M. Coppo and M. Dezani-Ciancaglini. 1980. An extension of the basic functionality theory for the λ -calculus. Notre Dame Journal of Formal Logic, 21, 4 (1980), 685 – 693. https://doi.org/10.1305/ndjfl/1093883253 Google ScholarGoogle ScholarCross RefCross Ref
  9. Mario Coppo, Mariangiola Dezani-Ciancaglini, and Betti Venneri. 1980. Principal Type Schemes and Lambda-calculus Semantics. 535–560. http://www.di.unito.it/~dezani/papers/CDV80.pdfGoogle ScholarGoogle Scholar
  10. Mario Coppo, Mariangiola Dezani-Ciancaglini, and Betti Venneri. 1981. Functional Characters of Solvable Terms. Math. Log. Q., 27, 2-6 (1981), 45–58. https://doi.org/10.1002/malq.19810270205 Google ScholarGoogle Scholar
  11. The Coq Development Team. 2021. The Coq Reference Manual, version 8.13.2. Available electronically at https://coq.inria.fr/distrib/current/refman/Google ScholarGoogle Scholar
  12. Rowan Davies and Frank Pfenning. 2000. Intersection types and computational effects. In Proceedings of the Fifth ACM SIGPLAN International Conference on Functional Programming (ICFP ’00), Montreal, Canada, September 18-21, 2000, Martin Odersky and Philip Wadler (Eds.). ACM, 198–208. https://doi.org/10.1145/351240.351259 Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Martin Erwig and Simon Peyton Jones. 2000. Pattern Guards and Transformational Patterns. In Haskell Workshop 2000 (haskell workshop 2000 ed.). https://www.microsoft.com/en-us/research/publication/pattern-guards-and-transformational-patterns/Google ScholarGoogle Scholar
  14. Facebook. 2014. Flow. https://flow.orgGoogle ScholarGoogle Scholar
  15. Alain Frisch. 2004. Théorie, conception et réalisation d’un langage de programmation adapté à XML. Ph.D. Dissertation. PhD thesis, Université Paris 7.Google ScholarGoogle Scholar
  16. Alain Frisch, Giuseppe Castagna, and Véronique Benzaken. 2008. Semantic Subtyping: Dealing Set-Theoretically with Function, Union, Intersection, and Negation Types. J. ACM, 55, 4 (2008), Article 19, Sept., 64 pages. issn:0004-5411 https://doi.org/10.1145/1391289.1391293 Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Paul Gochet, Pascal Gribomont, and Didier Rossetto. 1995. ALGORITHMS FOR RELEVANT LOGIC: Leo Apostel in memoriam. Logique et Analyse, 38, 150/152 (1995), 329–346. issn:00245836, 22955836 http://www.jstor.org/stable/44084547Google ScholarGoogle Scholar
  18. William A. Howard. 1980. The formulae-as-types notion of construction. In To H.B. Curry: Essays on Combinatory Logic, λ -calculus and Formalism, J. Hindley and J. Seldin (Eds.). Academic Press, 479–490.Google ScholarGoogle Scholar
  19. Xuejing Huang, Jinxu Zhao, and Bruno C. d. S. Oliveira. 2021. Taming the Merge Operator: a Type-directed Operational Semantics Approach. Department of Computer Science, The University of Hong Kong. https://www.cs.hku.hk/data/techreps/document/TR-2021-01.pdfGoogle ScholarGoogle Scholar
  20. Microsoft. 2012. TypeScript. https://www.typescriptlang.orgGoogle ScholarGoogle Scholar
  21. Fabian Muehlboeck and Ross Tate. 2018. Empowering Union and Intersection Types with Integrated Subtyping. Proc. ACM Program. Lang., 2, OOPSLA (2018), Article 112, Oct., 29 pages. https://doi.org/10.1145/3276482 Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Bruno C. d. S. Oliveira, Cui Shaobo, and Baber Rehman. 2020. The Duality of Subtyping. 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. 29:1–29:29. isbn:978-3-95977-154-2 issn:1868-8969 https://doi.org/10.4230/LIPIcs.ECOOP.2020.29 Google ScholarGoogle ScholarCross RefCross Ref
  23. David J. Pearce. 2013. Sound and Complete Flow Typing with Unions, Intersections and Negations. In Verification, Model Checking, and Abstract Interpretation, Roberto Giacobazzi, Josh Berdine, and Isabella Mastroeni (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 335–354. isbn:978-3-642-35873-9Google ScholarGoogle Scholar
  24. Benjamin C. Pierce. 1991. Programming with Intersection Types and Bounded Polymorphism. Ph.D. Dissertation. Carnegie Mellon University.Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Benjamin C. Pierce. 2018. A decision procedure for the subtype relation on intersection types with bounded variables. https://doi.org/10.1184/R1/6587339.v1 Google ScholarGoogle ScholarCross RefCross Ref
  26. Redhat. 2011. Ceylon. https://ceylon-lang.orgGoogle ScholarGoogle Scholar
  27. John C Reynolds. 1988. Preliminary design of the programming language Forsythe. Carnegie Mellon University.Google ScholarGoogle Scholar
  28. John C Reynolds. 1997. Design of the Programming Language Forsythe. In ALGOL-like languages. Springer, 173–233.Google ScholarGoogle Scholar
  29. Richard Routley and Robert K. Meyer. 1972. The Semantics of Entailment: III. Journal of Philosophical Logic, 1, 2 (1972), 192–208. issn:00223611, 15730433 http://www.jstor.org/stable/30226036Google ScholarGoogle ScholarCross RefCross Ref
  30. Peter Sewell, Francesco Zappa Nardelli, Scott Owens, Gilles Peskine, Thomas Ridge, Susmit Sarkar, and Rok Strniša. 2007. Ott: Effective Tool Support for the Working Semanticist. SIGPLAN Not., 42, 9 (2007), Oct., 1–12. issn:0362-1340 https://doi.org/10.1145/1291220.1291155 Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Claude Stolze. 2019. Combining union, intersection and dependent types in an explicitly typed lambda-calculus. Ph.D. Dissertation. Université Côte d’Azur.Google ScholarGoogle Scholar
  32. The Scala Center team and community contributors. 2020. Scala 3. https://dotty.epfl.chGoogle ScholarGoogle Scholar
  33. Steffen van Bakel, Mariangiola Dezani-Ciancaglini, Ugo de’ Liguoro, and Yoko Motohama. 2000. The Minimal Relevant Logic and the Call-by-Value Lambda Calculus. The Australian National University. http://www.di.unito.it/~deligu/papers/vBDdLM-trANU00.pdfGoogle ScholarGoogle Scholar
  34. Luca Viganò. 2000. An O(n log n)-Space Decision Procedure for the Relevance Logic B+. Studia Logica: An International Journal for Symbolic Logic, 66, 3 (2000), 385–407. issn:00393215, 15728730 http://www.jstor.org/stable/20016237Google ScholarGoogle ScholarCross RefCross Ref
  35. Francesco Zappa Nardelli, Julia Belyakova, Artem Pelenitsyn, Benjamin Chung, Jeff Bezanson, and Jan Vitek. 2018. Julia Subtyping: A Rational Reconstruction. Proc. ACM Program. Lang., 2, OOPSLA (2018), Article 113, Oct., 27 pages. https://doi.org/10.1145/3276483 Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Distributing intersection and union types with splits and duality (functional pearl)

      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!