skip to main content

A case for DOT: theoretical foundations for objects with pattern matching and GADT-style reasoning

Published:31 October 2022Publication History
Skip Abstract Section

Abstract

Many programming languages in the OO tradition now support pattern matching in some form. Historical examples include Scala and Ceylon, with the more recent additions of Java, Kotlin, TypeScript, and Flow. But pattern matching on generic class hierarchies currently results in puzzling type errors in most of these languages. Yet this combination of features occurs naturally in many scenarios, such as when manipulating typed ASTs. To support it properly, compilers needs to implement a form of subtyping reconstruction: the ability to reconstruct subtyping information uncovered at runtime during pattern matching. We introduce cDOT, a new calculus in the family of Dependent Object Types (DOT) intended to serve as a formal foundation for subtyping reconstruction. Being descended from pDOT, itself a formal foundation for Scala, cDOT can be used to encode advanced object-oriented features such as generic inheritance, type constructor variance, F-bounded polymorphism, and first-class recursive modules. We demonstrate that subtyping reconstruction subsumes GADTs by encoding λ2,Gµ, a classical constraint-based GADT calculus, into cDOT.

References

  1. Nada Amin, Samuel Grütter, Martin Odersky, Tiark Rompf, and Sandro Stucki. 2016. The Essence of Dependent Object Types. In A List of Successes That Can Change the World. Springer, 249–272. Google ScholarGoogle Scholar
  2. Nada Amin, Tiark Rompf, and Martin Odersky. 2014. Foundations of Path-Dependent Types. ACM SIGPLAN Notices, 49, 10 (2014), Oct., 233–249. issn:0362-1340 https://doi.org/10.1145/2714064.2660216 Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Aleksander Boruch-Gruszecki. 2017. Verifying the totality of pattern matching in Scala. Master’s thesis. Wrocł aw University of Science and Technology. Google ScholarGoogle Scholar
  4. Aleksander Boruch-Gruszecki, Radosł aw Waśko, Yichen Xu, and Lionel Parreaux. 2022. A Case for DOT: Theoretical Foundations for Objects With Pattern Matching and GADT-style Reasoning. https://doi.org/10.48550/arXiv.2209.07427 arxiv:2209.07427. Google ScholarGoogle Scholar
  5. Aleksander Boruch-Gruszecki, Radosł aw Waśko, Yichen Xu, and Lionel Parreaux. 2022. Mechanized proof of "A Case for DOT: Theoretical Foundations for Objects With Pattern Matching and GADT-style Reasoning". https://doi.org/10.5281/zenodo.7079463 Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. László Böszörményi and Carsten Weich. 2012. Programming in Modula-3: an introduction in programming with style. Springer Science & Business Media. Google ScholarGoogle Scholar
  7. Gilad Bracha, Martin Odersky, David Stoutamire, and Philip Wadler. 1998. Making the Future Safe for the Past: Adding Genericity to the Java Programming Language. In Proceedings of the 13th ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA ’98). Association for Computing Machinery, New York, NY, USA. 183–200. isbn:1581130058 https://doi.org/10.1145/286936.286957 Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Peter Canning, William Cook, Walter Hill, Walter Olthoff, and John C Mitchell. 1989. F-bounded polymorphism for object-oriented programming. In Proceedings of the fourth international conference on functional programming languages and computer architecture. 273–280. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Luca Cardelli and Peter Wegner. 1985. On Understanding Types, Data Abstraction, and Polymorphism. ACM Comput. Surv., 17, 4 (1985), dec, 471–523. issn:0360-0300 https://doi.org/10.1145/6041.6042 Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Richard A. Eisenberg. 2020. Stitch: The Sound Type-Indexed Type Checker (Functional Pearl). In Proceedings of the 13th ACM SIGPLAN International Symposium on Haskell (Haskell 2020). Association for Computing Machinery, New York, NY, USA. 39–53. isbn:978-1-4503-8050-8 https://doi.org/10.1145/3406088.3409015 Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Burak Emir, Andrew Kennedy, Claudio Russo, and Dachuan Yu. 2006. Variance and Generalized Constraints for C^♯ Generics. In ECOOP 2006 – Object-Oriented Programming, Dave Thomas (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg. 279–303. isbn:978-3-540-35727-8 Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Burak Emir, Martin Odersky, and John Williams. 2007. Matching Objects with Patterns. In ECOOP 2007 – Object-Oriented Programming, Erik Ernst (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg. 273–298. isbn:978-3-540-73589-2 Google ScholarGoogle Scholar
  13. Jacques Garrigue and J. L. Normand. 2011. Adding GADTs to OCaml: The Direct Approach. In Workshop on ML. Google ScholarGoogle Scholar
  14. Paolo G. Giarrusso. 2013. Open GADTs and Declaration-site Variance: A Problem Statement. In Proceedings of the 4th Workshop on Scala (SCALA ’13). ACM, New York, NY, USA. 5:1–5:4. isbn:978-1-4503-2064-1 https://doi.org/10.1145/2489837.2489842 Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Paolo G. Giarrusso, Léo Stefanesco, Amin Timany, Lars Birkedal, and Robbert Krebbers. 2020. Scala Step-by-Step: Soundness for DOT with Step-Indexed Logical Relations in Iris. Proceedings of the ACM on Programming Languages, 4, ICFP (2020), Aug., 114:1–114:29. https://doi.org/10.1145/3408996 Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Radu Grigore. 2017. Java Generics Are Turing Complete. ACM SIGPLAN Notices, 52, 1 (2017), Jan., 73–85. issn:0362-1340 https://doi.org/10.1145/3093333.3009871 Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Robert Harper and Greg Morrisett. 1995. Compiling Polymorphism Using Intensional Type Analysis. In Proceedings of the 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’95). Association for Computing Machinery, New York, NY, USA. 130–141. isbn:978-0-89791-692-9 https://doi.org/10.1145/199448.199475 Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Jason Z. S. Hu and Ondřej Lhoták. 2019. Undecidability of D<: And Its Decidable Fragments. Proc. ACM Program. Lang., 4, POPL (2019), Article 9, Dec., 30 pages. https://doi.org/10.1145/3371077 Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Inria, CNRS and contributors. 2021. Extended pattern matching — Coq 8.13.2 documentation. https://coq.inria.fr/distrib/V8.13.2/refman/language/extensions/match.html#nested-patterns Google ScholarGoogle Scholar
  20. Georgios Karachalias, Tom Schrijvers, Dimitrios Vytiniotis, and Simon Peyton Jones. 2015. GADTs Meet Their Match: Pattern-Matching Warnings That Account for GADTs, Guards, and Laziness. In Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming (ICFP 2015). Association for Computing Machinery, New York, NY, USA. 424–436. isbn:978-1-4503-3669-7 https://doi.org/10.1145/2784731.2784748 Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Andrew Kennedy and Benjamin C. Pierce. 2007. On Decidability of Nominal Subtyping with Variance. In International Workshop on Foundations and Developments of Object-Oriented Languages (FOOL/WOOD). Google ScholarGoogle Scholar
  22. Andrew Kennedy and Claudio V. Russo. 2005. Generalized Algebraic Data Types and Object-Oriented Programming. In Proceedings of the 20th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA ’05). Association for Computing Machinery, New York, NY, USA. 21–40. isbn:1595930310 https://doi.org/10.1145/1094811.1094814 Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Luc Maranget. 2008. Compiling Pattern Matching to Good Decision Trees. In Proceedings of the 2008 ACM SIGPLAN Workshop on ML (ML ’08). ACM, New York, NY, USA. 35–46. isbn:978-1-60558-062-3 https://doi.org/10.1145/1411304.1411311 Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Guillaume Martres. 2022. Type-Preserving Compilation of Class-Based Languages. Ph. D. Dissertation. EPFL. Lausanne. Google ScholarGoogle Scholar
  25. 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:978-0-89791-125-2 https://doi.org/10.1145/800017.800529 Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Bengt Nordström, Kent Petersson, and Jan M. Smith. 1990. Programming in Martin-Löf’s Type Theory. 200, Oxford University Press Oxford. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Chris Parnin, Christian Bird, and Emerson Murphy-Hill. 2013. Adoption and use of Java generics. Empirical Software Engineering, 18, 6 (2013), 1047–1089. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Lionel Parreaux, Aleksander Boruch-Gruszecki, and Paolo G. Giarrusso. 2019. Towards Improved GADT Reasoning in Scala. In Proceedings of the Tenth ACM SIGPLAN Symposium on Scala (Scala ’19). Association for Computing Machinery, New York, NY, USA. 12–16. isbn:978-1-4503-6824-7 https://doi.org/10.1145/3337932.3338813 Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Lionel Emile Vincent Parreaux. 2020. Type-Safe Metaprogramming and Compilation Techniques For Designing Efficient Systems in High-Level Languages. Ph. D. Dissertation. EPFL. Lausanne. https://doi.org/10.5075/epfl-thesis-10285 Google ScholarGoogle ScholarCross RefCross Ref
  30. 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
  31. Simon Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Geoffrey Washburn. 2006. Simple Unification-based Type Inference for GADTs. In Proceedings of the Eleventh ACM SIGPLAN International Conference on Functional Programming (ICFP ’06). ACM, New York, NY, USA. 50–61. isbn:978-1-59593-309-6 https://doi.org/10.1145/1159803.1159811 Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Marianna Rapoport, Ifaz Kabir, Paul He, and Ondrej Lhoták. 2017. A Simple Soundness Proof for Dependent Object Types. In Proc. ACM Program. Lang.. 46:1–46:27. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Marianna Rapoport and Ondřej Lhoták. 2019. A Path To DOT: Formalizing Fully-Path-Dependent Types. arXiv:1904.07298 [cs], April, arxiv:1904.07298. Google ScholarGoogle Scholar
  34. Tiark Rompf and Nada Amin. 2016. Type Soundness for Dependent Object Types (DOT). In Proceedings of the 2016 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA 2016). Association for Computing Machinery, New York, NY, USA. 624–641. isbn:978-1-4503-4444-9 https://doi.org/10.1145/2983990.2984008 Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. AMR Sabry and Matthias Felleisen. 1993. Reasoning about Programs in Continuation-Passing Style. LISP and Symbolic Computation, 6, 3 (1993), Nov., 289–360. issn:1573-0557 https://doi.org/10.1007/BF01019462 Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Gabriel Scherer and Didier Rémy. 2013. GADTs Meet Subtyping. In Programming Languages and Systems, Matthias Felleisen and Philippa Gardner (Eds.) (Lecture Notes in Computer Science). Springer, Berlin, Heidelberg. 554–573. isbn:978-3-642-37036-6 https://doi.org/10.1007/978-3-642-37036-6_30 Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Jan Stolarek, Simon Peyton Jones, and Richard A. Eisenberg. 2015. Injective Type Families for Haskell. ACM SIGPLAN Notices, 50, 12 (2015), Aug., 118–128. issn:0362-1340 https://doi.org/10.1145/2887747.2804314 Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Aaron Stump. 2009. Directly Reflective Meta-Programming. Higher-Order and Symbolic Computation, 22, 2 (2009), June, 115–144. issn:1573-0557 https://doi.org/10.1007/s10990-007-9022-0 Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Martin Sulzmann, Manuel M. T. Chakravarty, Simon Peyton Jones, and Kevin Donnelly. 2007. System F with Type Equality Coercions. In Proceedings of the 2007 ACM SIGPLAN International Workshop on Types in Languages Design and Implementation (TLDI ’07). Association for Computing Machinery, New York, NY, USA. 53–66. isbn:978-1-59593-393-5 https://doi.org/10.1145/1190315.1190324 Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Valery Trifonov, Bratin Saha, and Zhong Shao. 2000. Fully Reflexive Intensional Type Analysis. In Proceedings of the Fifth ACM SIGPLAN International Conference on Functional Programming (ICFP ’00). Association for Computing Machinery, New York, NY, USA. 82–93. isbn:978-1-58113-202-1 https://doi.org/10.1145/351240.351248 Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Radosław Waśko. 2021. Formal foundations for Generalized Algebraic Data Types in Scala. Master’s thesis. University of Warsaw. https://apd.uw.edu.pl/diplomas/197329/ Google ScholarGoogle Scholar
  42. A. K. Wright and M. Felleisen. 1994. A Syntactic Approach to Type Soundness. Information and Computation, 115, 1 (1994), Nov., 38–94. issn:0890-5401 https://doi.org/10.1006/inco.1994.1093 Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Hongwei Xi, Chiyan Chen, and Gang Chen. 2003. Guarded Recursive Datatype Constructors. In ACM SIGPLAN Notices. 38, ACM, 224–235. Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. Yichen Xu, Aleksander Boruch-Gruszecki, and Lionel Parreaux. 2021. Implementing Path-Dependent GADT Reasoning for Scala 3. In Proceedings of the 12th ACM SIGPLAN International Symposium on Scala (SCALA 2021). Association for Computing Machinery, New York, NY, USA. 22–32. isbn:978-1-4503-9113-9 https://doi.org/10.1145/3486610.3486892 Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Jeremy Yallop and Stephen Dolan. 2019. First-Class Subtypes. Electronic Proceedings in Theoretical Computer Science, 294 (2019), May, 74–85. issn:2075-2180 https://doi.org/10.4204/EPTCS.294.4 arxiv:1905.06546. Google ScholarGoogle ScholarCross RefCross Ref

Index Terms

  1. A case for DOT: theoretical foundations for objects with pattern matching and GADT-style reasoning

          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

          • Article Metrics

            • Downloads (Last 12 months)210
            • Downloads (Last 6 weeks)22

            Other Metrics

          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!