Abstract
Intersection and union types are becoming more popular by the day, entering the mainstream in programming languages like TypeScript and Scala 3. Yet, no language so far has managed to combine these powerful types with principal polymorphic type inference. We present a solution to this problem in MLstruct, a language with subtyped records, equirecursive types, first-class unions and intersections, class-based instance matching, and ML-style principal type inference. While MLstruct is mostly structurally typed, it contains a healthy sprinkle of nominality for classes, which gives it desirable semantics, enabling the expression of a powerful form of extensible variants that does not need row variables. Technically, we define the constructs of our language using conjunction, disjunction, and negation connectives, making sure they form a Boolean algebra, and we show that the addition of a few nonstandard but sound subtyping rules gives us enough structure to derive a sound and complete type inference algorithm. With this work, we hope to foster the development of better type inference for present and future programming languages with expressive subtyping systems.
- Martin Abadi and Marcelo P. Fiore. 1996. Syntactic considerations on recursive types. In Proceedings 11th Annual IEEE Symposium on Logic in Computer Science. 242–252.
Google Scholar
Digital Library
- Alexander Aiken. 1996. Making set-constraint program analyses scale. In In CP96 Workshop on Set Constraints.
Google Scholar
- Alexander Aiken and Edward L. Wimmers. 1993. Type Inclusion Constraints and Type Inference. In Proceedings of the Conference on Functional Programming Languages and Computer Architecture (FPCA ’93). Association for Computing Machinery, New York, NY, USA. 31–41. isbn:089791595X https://doi.org/10.1145/165180.165188
Google Scholar
Digital Library
- Alexander Aiken, Edward L. Wimmers, and T. K. Lakshman. 1994. Soft Typing with Conditional Types. In Proceedings of the 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’94). Association for Computing Machinery, New York, NY, USA. 163–173. isbn:0897916360 https://doi.org/10.1145/174675.177847
Google Scholar
Digital Library
- João Alpuim, Bruno C. d. S. Oliveira, and Zhiyuan Shi. 2017. Disjoint Polymorphism. In Programming Languages and Systems, Hongseok Yang (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg. 1–28. isbn:978-3-662-54434-1
Google Scholar
- Roberto M. Amadio and Luca Cardelli. 1993. Subtyping Recursive Types. ACM Trans. Program. Lang. Syst., 15, 4 (1993), Sept., 575–631. issn:0164-0925 https://doi.org/10.1145/155183.155231
Google Scholar
Digital Library
- Andrew W. Appel, Paul-André Melliès, Christopher D. Richards, and Jérôme Vouillon. 2007. A Very Modal Model of a Modern, Major, General Type System. In Proceedings of the 34th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’07). Association for Computing Machinery, New York, NY, USA. 109–122. isbn:1595935754 https://doi.org/10.1145/1190216.1190235
Google Scholar
Digital Library
- 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. Journal of Symbolic Logic, 48, 4 (1983), 931–940. https://doi.org/10.2307/2273659
Google Scholar
Cross Ref
- David Binder, Ingo Skupin, David Läwen, and Klaus Ostermann. 2022. Structural Refinement Types. In Proceedings of the 7th ACM SIGPLAN International Workshop on Type-Driven Development (TyDe ’22). Association for Computing Machinery, New York, NY, USA. https://doi.org/10.1145/3546196.3550163
Google Scholar
Digital Library
- Michael Brandt and Fritz Henglein. 1998. Coinductive axiomatization of recursive type equality and subtyping. Fundamenta Informaticae, 33, 4 (1998), 309–338.
Google Scholar
Digital Library
- Giuseppe Castagna. 2012. Object-Oriented Programming A Unified Foundation. Springer Science & Business Media.
Google Scholar
- Giuseppe Castagna, Victor Lanvin, Mickaël Laurent, and Kim Nguyen. 2021. Revisiting Occurrence Typing. arxiv:1907.05590.
Google Scholar
- Giuseppe Castagna, Mickaël Laurent, Kim Nguyundefinedn, and Matthew Lutze. 2022. On Type-Cases, Union Elimination, and Occurrence Typing. Proc. ACM Program. Lang., 6, POPL (2022), Article 13, jan, 31 pages. https://doi.org/10.1145/3498674
Google Scholar
Digital Library
- Giuseppe Castagna, Tommaso Petrucciani, and Kim Nguyen. 2016. Set-theoretic types for polymorphic variants. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming (ICFP 2016). Association for Computing Machinery, Nara, Japan. 378–391. isbn:978-1-4503-4219-3 https://doi.org/10.1145/2951913.2951928
Google Scholar
Digital Library
- 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
- Pavel Curtis. 1990. Constrained Qualification in Polymorphic Type Analysis. Ph.D. Dissertation. USA. UMI Order No. GAX90-26980.
Google Scholar
- 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
- Luis Damas and Robin Milner. 1982. Principal type-schemes for functional programs. In Proceedings of the 9th ACM SIGPLAN-SIGACT symposium on Principles of programming languages (POPL ’82). Association for Computing Machinery, Albuquerque, New Mexico. 207–212. isbn:978-0-89791-065-1 https://doi.org/10.1145/582153.582176
Google Scholar
Digital Library
- 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). Association for Computing Machinery, New York, NY, USA. 198–208. isbn:1581132026 https://doi.org/10.1145/351240.351259
Google Scholar
Digital Library
- Van Bakel Dezani-Ciancaglini, S. Van Bakel, M. Dezani-ciancaglini, and Y. Motohama. 1998. The Minimal Relevant Logic and the Call-by-Value Lambda Calculus.
Google Scholar
- Stephen Dolan. 2017. Algebraic subtyping. Ph.D. Dissertation. isbn:978-1-78017-415-0
Google Scholar
- Stephen Dolan and Alan Mycroft. 2017. Polymorphism, subtyping, and type inference in MLsub. ACM SIGPLAN Notices, 52, 1 (2017), Jan., 60–72. issn:0362-1340 https://doi.org/10.1145/3093333.3009882
Google Scholar
Digital Library
- Jana Dunfield. 2012. Elaborating Intersection and Union Types. In Proceedings of the 17th ACM SIGPLAN International Conference on Functional Programming (ICFP ’12). Association for Computing Machinery, New York, NY, USA. 17–28. isbn:9781450310543 https://doi.org/10.1145/2364527.2364534
Google Scholar
Digital Library
- Jonathan Eifrig, Scott Smith, and Valery Trifonov. 1995. Sound Polymorphic Type Inference for Objects. In Proceedings of the Tenth Annual Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA ’95). Association for Computing Machinery, New York, NY, USA. 169–184. isbn:0897917030 https://doi.org/10.1145/217838.217858
Google Scholar
Digital Library
- Tim Freeman and Frank Pfenning. 1991. Refinement Types for ML. In Proceedings of the ACM SIGPLAN 1991 Conference on Programming Language Design and Implementation (PLDI ’91). ACM, New York, NY, USA. 268–277. isbn:978-0-89791-428-4 https://doi.org/10.1145/113445.113468 event-place: Toronto, Ontario, Canada.
Google Scholar
Digital Library
- A. Frisch, G. Castagna, and V. Benzaken. 2002. Semantic subtyping. In Proceedings 17th Annual IEEE Symposium on Logic in Computer Science. 137–146. https://doi.org/10.1109/LICS.2002.1029823
Google Scholar
Cross Ref
- 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
- You-Chin Fuh and Prateek Mishra. 1989. Polymorphic subtype inference: Closing the theory-practice gap. In TAPSOFT ’89, J. Díaz and F. Orejas (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 167–183. isbn:978-3-540-46118-0
Google Scholar
- You-Chin Fuh and Prateek Mishra. 1990. Type inference with subtypes. Theoretical Computer Science, 73, 2 (1990), 155–175. issn:0304-3975 https://doi.org/10.1016/0304-3975(90)90144-7
Google Scholar
Digital Library
- Vladimir Gapeyev, Michael Y Levin, and Benjamin C Pierce. 2002. Recursive subtyping revealed. Journal of Functional Programming, 12, 6 (2002), 511–548.
Google Scholar
Digital Library
- Jacques Garrigue. 1998. Programming with polymorphic variants. In ML Workshop. 13, 7.
Google Scholar
- Jacques Garrigue. 2001. Simple Type Inference for Structural Polymorphism.. In APLAS. 329–343.
Google Scholar
- Benedict R. Gaster and Mark P. Jones. 1996. A Polymorphic Type System for Extensible Records and Variants.
Google Scholar
- Silvia Ghilezan. 1996. Strong Normalization and Typability with Intersection Types. Notre Dame Journal of Formal Logic, 37, 1 (1996), 44 – 52. https://doi.org/10.1305/ndjfl/1040067315
Google Scholar
Cross Ref
- Roger Hindley. 1969. The Principal Type-Scheme of an Object in Combinatory Logic. Trans. Amer. Math. Soc., 146 (1969), 29–60. issn:0002-9947 https://doi.org/10.2307/1995158 Publisher: American Mathematical Society.
Google Scholar
Cross Ref
- Haruo Hosoya, Jérôme Vouillon, and Benjamin C. Pierce. 2005. Regular Expression Types for XML. ACM Trans. Program. Lang. Syst., 27, 1 (2005), Jan., 46–90. issn:0164-0925 https://doi.org/10.1145/1053468.1053470
Google Scholar
Digital Library
- Xuejing Huang and Bruno C. d. S. Oliveira. 2021. Distributing Intersection and Union Types with Splits and Duality (Functional Pearl). Proc. ACM Program. Lang., 5, ICFP (2021), Article 89, aug, 24 pages. https://doi.org/10.1145/3473594
Google Scholar
Digital Library
- Trevor Jim and Jens Palsberg. 1999. Type Inference in Systems of Recursive Types With Subtyping.
Google Scholar
- Dexter Kozen, Jens Palsberg, and Michael I. Schwartzbach. 1994. Efficient inference of partial types. J. Comput. System Sci., 49, 2 (1994), 306–324. issn:0022-0000 https://doi.org/10.1016/S0022-0000(05)80051-0
Google Scholar
Digital Library
- David MacQueen, Gordon Plotkin, and Ravi Sethi. 1986. An ideal model for recursive polymorphic types. Information and Control, 71, 1 (1986), 95–130. issn:0019-9958 https://doi.org/10.1016/S0019-9958(86)80019-5
Google Scholar
Digital Library
- Robin Milner. 1978. A theory of type polymorphism in programming. J. Comput. System Sci., 17, 3 (1978), Dec., 348–375. issn:0022-0000 https://doi.org/10.1016/0022-0000(78)90014-4
Google Scholar
Cross Ref
- John C. Mitchell. 1984. Coercion and Type Inference. In Proceedings of the 11th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages (POPL ’84). Association for Computing Machinery, New York, NY, USA. 175–185. isbn:0897911253 https://doi.org/10.1145/800017.800529
Google Scholar
Digital Library
- James Hiram Morris. 1969. Lambda-calculus models of programming languages.. Ph.D. Dissertation. Massachusetts Institute of Technology.
Google 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
- Martin Odersky, Martin Sulzmann, and Martin Wehr. 1999. Type inference with constrained types. Theory and Practice of Object Systems, 5, 1 (1999), 35–55.
Google Scholar
Digital Library
- Atsushi Ohori. 1995. A Polymorphic Record Calculus and Its Compilation. ACM Trans. Program. Lang. Syst., 17, 6 (1995), nov, 844–895. issn:0164-0925 https://doi.org/10.1145/218570.218572
Google Scholar
Digital Library
- Jens Palsberg, Mitchell Wand, and Patrick O’Keefe. 1997. Type inference with non-structural subtyping. Formal Aspects of Computing, 9, 1 (1997), Jan., 49–67. issn:1433-299X https://doi.org/10.1007/BF01212524
Google Scholar
Digital Library
- Lionel Parreaux. 2020. The Simple Essence of Algebraic Subtyping: Principal Type Inference with Subtyping Made Easy (Functional Pearl). Proc. ACM Program. Lang., 4, ICFP (2020), Article 124, Aug., 28 pages. https://doi.org/10.1145/3409006
Google Scholar
Digital Library
- Lionel Parreaux and Chun Yin Chau. 2022. MLstruct: Principal Type Inference in a Boolean Algebra of Structural Types (Extended Version). The Hong Kong University of Science and Technology. https://lptk.github.io/mlscript-paper
Google Scholar
- Lionel Parreaux, Luyu Cheng, Tony Chau, Ishan Bhanuka, Andong Fan, Malcolm Law, Ali Mahzoun, and Elise Rouillé. 2022. MLstruct: Principal Type Inference in a Boolean Algebra of Structural Types (Artifact). https://doi.org/10.5281/zenodo.7121838
Google Scholar
Digital Library
- 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.) (Lecture Notes in Computer Science). Springer, Berlin, Heidelberg. 335–354. isbn:978-3-642-35873-9 https://doi.org/10.1007/978-3-642-35873-9_21
Google Scholar
Digital Library
- Tommaso Petrucciani. 2019. Polymorphic set-theoretic types for functional languages. Ph.D. Dissertation. Università di Genova; Université Sorbonne Paris Cité – Université Paris Diderot.
Google Scholar
- Benjamin C Pierce. 1991. Programming with intersection types and bounded polymorphism. Ph.D. Dissertation. Citeseer.
Google Scholar
Digital Library
- Benjamin C. Pierce. 2002. Types and programming languages. MIT press.
Google Scholar
Digital Library
- François Pottier. 1996. Simplifying Subtyping Constraints. In Proceedings of the First ACM SIGPLAN International Conference on Functional Programming (ICFP ’96). Association for Computing Machinery, New York, NY, USA. 122–133. isbn:0897917707 https://doi.org/10.1145/232627.232642
Google Scholar
Digital Library
- François Pottier. 1998. A Framework for Type Inference with Subtyping. In Proceedings of the Third ACM SIGPLAN International Conference on Functional Programming (ICFP ’98). Association for Computing Machinery, New York, NY, USA. 228–238. isbn:1581130244 https://doi.org/10.1145/289423.289448
Google Scholar
Digital Library
- François Pottier. 1998. Type Inference in the Presence of Subtyping: from Theory to Practice. INRIA. https://hal.inria.fr/inria-00073205
Google Scholar
- François Pottier. 2001. Simplifying Subtyping Constraints: A Theory. Information and Computation, 170, 2 (2001), 153–183. issn:0890-5401 https://doi.org/10.1006/inco.2001.2963
Google Scholar
Digital Library
- François Pottier. 2003. A Constraint-Based Presentation and Generalization of Rows. In IEEE Symposium on Logic In Computer Science (LICS). Ottawa, Canada. 331–340. http://cambium.inria.fr/~fpottier/publis/fpottier-lics03.pdf
Google Scholar
Cross Ref
- Baber Rehman, Xuejing Huang, Ningning Xie, and Bruno C. d. S. Oliveira. 2022. Union Types with Disjoint Switches. In 36th European Conference on Object-Oriented Programming (ECOOP 2022), Karim Ali and Jan Vitek (Eds.) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 222). Schloss Dagstuhl – Leibniz-Zentrum für Informatik, Dagstuhl, Germany. 25:1–25:31. isbn:978-3-95977-225-9 issn:1868-8969 https://doi.org/10.4230/LIPIcs.ECOOP.2022.25
Google Scholar
Cross Ref
- Didier Rémy. 1994. Type Inference for Records in Natural Extension of ML. MIT Press, Cambridge, MA, USA. 67–95. isbn:026207155X
Google Scholar
- John C. Reynolds. 1997. Design of the Programming Language Forsythe. Birkhäuser Boston, Boston, MA. 173–233. isbn:978-1-4612-4118-8 https://doi.org/10.1007/978-1-4612-4118-8_9
Google Scholar
Cross Ref
- Vincent Simonet. 2003. Type Inference with Structural Subtyping: A Faithful Formalization of an Efficient Constraint Solver. In Programming Languages and Systems, Atsushi Ohori (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg. 283–302. isbn:978-3-540-40018-9
Google Scholar
- Geoffrey Seward Smith. 1991. Polymorphic type inference for languages with overloading and subtyping. Ph.D. Dissertation. Cornell University.
Google Scholar
- R. Stansifer. 1988. Type Inference with Subtypes. In Proceedings of the 15th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’88). Association for Computing Machinery, New York, NY, USA. 88–97. isbn:0897912527 https://doi.org/10.1145/73560.73568
Google Scholar
Digital Library
- Sam Tobin-Hochstadt and Matthias Felleisen. 2008. The Design and Implementation of Typed Scheme. In Proceedings of the 35th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’08). Association for Computing Machinery, New York, NY, USA. 395–406. isbn:9781595936899 https://doi.org/10.1145/1328438.1328486
Google Scholar
Digital Library
- Valery Trifonov and Scott Smith. 1996. Subtyping constrained types. In Static Analysis, Radhia Cousot and David A. Schmidt (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 349–365. isbn:978-3-540-70674-8
Google Scholar
- Leo White. 2015. Row polymorphism. https://www.cl.cam.ac.uk/teaching/1415/L28/rows.pdf
Google Scholar
Index Terms
MLstruct: principal type inference in a Boolean algebra of structural types
Recommendations
Type checking and inference for polymorphic and existential types
CATS '09: Proceedings of the Fifteenth Australasian Symposium on Computing: The Australasian Theory - Volume 94This paper proves undecidability of type checking and type inference problems in some variants of typed lambda calculi with polymorphic and existential types. First, type inference in the domain-free polymorphic lambda calculus is proved to be ...
Polymorphic type inference and abstract data types
Many statically typed programming languages provide an abstract data type construct, such as the module in Modula-2. However, in most of these languages, implementations of abstract data types are not first-class values. Thus, they cannot be assigned to ...






Comments