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.
Supplemental Material
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- Arthur Charguéraud and François Pottier. [n.d.]. TLC: a non-constructive library for Coq. https://www.chargueraud.org/softs/tlc/Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
- 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 Scholar
- The Coq Development Team. 2021. The Coq Reference Manual, version 8.13.2. Available electronically at https://coq.inria.fr/distrib/current/refman/Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- Facebook. 2014. Flow. https://flow.orgGoogle Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- 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 Scholar
- Microsoft. 2012. TypeScript. https://www.typescriptlang.orgGoogle Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
- Benjamin C. Pierce. 1991. Programming with Intersection Types and Bounded Polymorphism. Ph.D. Dissertation. Carnegie Mellon University.Google Scholar
Digital Library
- 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 Scholar
Cross Ref
- Redhat. 2011. Ceylon. https://ceylon-lang.orgGoogle Scholar
- John C Reynolds. 1988. Preliminary design of the programming language Forsythe. Carnegie Mellon University.Google Scholar
- John C Reynolds. 1997. Design of the Programming Language Forsythe. In ALGOL-like languages. Springer, 173–233.Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- Claude Stolze. 2019. Combining union, intersection and dependent types in an explicitly typed lambda-calculus. Ph.D. Dissertation. Université Côte d’Azur.Google Scholar
- The Scala Center team and community contributors. 2020. Scala 3. https://dotty.epfl.chGoogle Scholar
- 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 Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
Index Terms
Distributing intersection and union types with splits and duality (functional pearl)
Recommendations
Gradual typing with union and intersection types
We propose a type system for functional languages with gradual types and set-theoretic type connectives and prove its soundness. In particular, we show how to lift the definition of the domain and result type of an application from non-gradual types to ...
Gradual typing: a new perspective
We define a new, more semantic interpretation of gradual types and use it to ``gradualize'' two forms of polymorphism: subtyping polymorphism and implicit parametric polymorphism. In particular, we use the new interpretation to define three gradual type ...
Intersection and Union Types in the λμμ~-calculus
The original @l@[email protected]@m@? of Curien and Herbelin has a system of simple types, based on sequent calculus, embodying a Curry-Howard correspondence with classical logic. We introduce and discuss three type assignment systems that are extensions of @l@[email protected]@m@?...






Comments