skip to main content

MLstruct: principal type inference in a Boolean algebra of structural types

Published:31 October 2022Publication History
Skip Abstract Section

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.

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. Alexander Aiken. 1996. Making set-constraint program analyses scale. In In CP96 Workshop on Set Constraints. Google ScholarGoogle Scholar
  3. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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 ScholarGoogle Scholar
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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
  9. 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 ScholarGoogle ScholarCross RefCross Ref
  10. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. Michael Brandt and Fritz Henglein. 1998. Coinductive axiomatization of recursive type equality and subtyping. Fundamenta Informaticae, 33, 4 (1998), 309–338. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Giuseppe Castagna. 2012. Object-Oriented Programming A Unified Foundation. Springer Science & Business Media. Google ScholarGoogle Scholar
  13. Giuseppe Castagna, Victor Lanvin, Mickaël Laurent, and Kim Nguyen. 2021. Revisiting Occurrence Typing. arxiv:1907.05590. Google ScholarGoogle Scholar
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. 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
  17. Pavel Curtis. 1990. Constrained Qualification in Polymorphic Type Analysis. Ph.D. Dissertation. USA. UMI Order No. GAX90-26980. Google ScholarGoogle Scholar
  18. 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
  19. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  21. 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 ScholarGoogle Scholar
  22. Stephen Dolan. 2017. Algebraic subtyping. Ph.D. Dissertation. isbn:978-1-78017-415-0 Google ScholarGoogle Scholar
  23. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  24. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  25. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  26. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  27. 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 ScholarGoogle ScholarCross RefCross Ref
  28. 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
  29. 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 ScholarGoogle Scholar
  30. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  31. Vladimir Gapeyev, Michael Y Levin, and Benjamin C Pierce. 2002. Recursive subtyping revealed. Journal of Functional Programming, 12, 6 (2002), 511–548. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Jacques Garrigue. 1998. Programming with polymorphic variants. In ML Workshop. 13, 7. Google ScholarGoogle Scholar
  33. Jacques Garrigue. 2001. Simple Type Inference for Structural Polymorphism.. In APLAS. 329–343. Google ScholarGoogle Scholar
  34. Benedict R. Gaster and Mark P. Jones. 1996. A Polymorphic Type System for Extensible Records and Variants. Google ScholarGoogle Scholar
  35. 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 ScholarGoogle ScholarCross RefCross Ref
  36. 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 ScholarGoogle ScholarCross RefCross Ref
  37. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  38. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  39. Trevor Jim and Jens Palsberg. 1999. Type Inference in Systems of Recursive Types With Subtyping. Google ScholarGoogle Scholar
  40. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  41. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  42. 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 ScholarGoogle ScholarCross RefCross Ref
  43. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  44. James Hiram Morris. 1969. Lambda-calculus models of programming languages.. Ph.D. Dissertation. Massachusetts Institute of Technology. Google ScholarGoogle Scholar
  45. 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
  46. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  47. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  48. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  49. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  50. 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 ScholarGoogle Scholar
  51. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  52. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  53. Tommaso Petrucciani. 2019. Polymorphic set-theoretic types for functional languages. Ph.D. Dissertation. Università di Genova; Université Sorbonne Paris Cité – Université Paris Diderot. Google ScholarGoogle Scholar
  54. Benjamin C Pierce. 1991. Programming with intersection types and bounded polymorphism. Ph.D. Dissertation. Citeseer. Google ScholarGoogle ScholarDigital LibraryDigital Library
  55. Benjamin C. Pierce. 2002. Types and programming languages. MIT press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  56. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  57. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  58. François Pottier. 1998. Type Inference in the Presence of Subtyping: from Theory to Practice. INRIA. https://hal.inria.fr/inria-00073205 Google ScholarGoogle Scholar
  59. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  60. 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 ScholarGoogle ScholarCross RefCross Ref
  61. 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 ScholarGoogle ScholarCross RefCross Ref
  62. Didier Rémy. 1994. Type Inference for Records in Natural Extension of ML. MIT Press, Cambridge, MA, USA. 67–95. isbn:026207155X Google ScholarGoogle Scholar
  63. 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 ScholarGoogle ScholarCross RefCross Ref
  64. 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 ScholarGoogle Scholar
  65. Geoffrey Seward Smith. 1991. Polymorphic type inference for languages with overloading and subtyping. Ph.D. Dissertation. Cornell University. Google ScholarGoogle Scholar
  66. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  67. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  68. 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 ScholarGoogle Scholar
  69. Leo White. 2015. Row polymorphism. https://www.cl.cam.ac.uk/teaching/1415/L28/rows.pdf Google ScholarGoogle Scholar

Index Terms

  1. MLstruct: principal type inference in a Boolean algebra of structural types

      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!