Abstract
Type-level programming is becoming more and more popular in the realm of functional programming. However, the combination of type-level programming and subtyping remains largely unexplored in practical programming languages. This paper presents match types, a type-level equivalent of pattern matching. Match types integrate seamlessly into programming languages with subtyping and, despite their simplicity, offer significant additional expressiveness. We formalize the feature of match types in a calculus based on System F sub and prove its soundness. We practically evaluate our system by implementing match types in the Scala 3 reference compiler, thus making type-level programming readily available to a broad audience of programmers.
Supplemental Material
- Martín Abadi, Luca Cardelli, Benjamin Pierce, and Gordon Plotkin. 1991. Dynamic Typing in a Statically Typed Language. ACM Trans. Program. Lang. Syst., 13, 2 (1991), April, 237–268. issn:0164-0925 https://doi.org/10.1145/103135.103138 Google Scholar
Digital Library
- Nada Amin, Samuel Grütter, Martin Odersky, Tiark Rompf, and Sandro Stucki. 2016. The Essence of Dependent Object Types. Springer International Publishing, Cham. 249–272. isbn:978-3-319-30936-1 https://doi.org/10.1007/978-3-319-30936-1_14 Google Scholar
Cross Ref
- David Aspinall. 1995. Subtyping with singleton types. In International Workshop on Computer Science Logic. Springer Berlin Heidelberg, Berlin, Heidelberg. 1–15. https://doi.org/10.1007/BFb0022243 Google Scholar
Cross Ref
- Brian Aydemir, Arthur Charguéraud, Benjamin C. Pierce, Randy Pollack, and Stephanie Weirich. 2008. Engineering Formal Metatheory. 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. 3–15. isbn:9781595936899 https://doi.org/10.1145/1328438.1328443 Google Scholar
Digital Library
- Paul Barham and Michael Isard. 2019. Machine Learning Systems Are Stuck in a Rut. In Proceedings of the Workshop on Hot Topics in Operating Systems (HotOS ’19). ACM, New York, NY, USA. 177–183. isbn:978-1-4503-6727-1 https://doi.org/10.1145/3317550.3321441 Google Scholar
Digital Library
- Gavin Bierman, Martín Abadi, and Mads Torgersen. 2014. Understanding TypeScript. In Proceedings of the 28th European Conference on ECOOP 2014 — Object-Oriented Programming - Volume 8586. Springer-Verlag, Berlin, Heidelberg. 257–281. isbn:9783662442012 https://doi.org/10.1007/978-3-662-44202-9_11 Google Scholar
Digital Library
- Olivier Blanvillain, Jonathan Brachthäuser, Maxime Kjaer, and Martin Odersky. 2021. Type-Level Programming with Match Types. 70. http://infoscience.epfl.ch/record/290019Google Scholar
- Olivier Blanvillain, Jonathan Brachthäuser, Maxime Kjaer, and Martin Odersky. 2021. Type-Level Programming with Match Types Artifact. https://doi.org/10.5281/zenodo.5568850 Google Scholar
Digital Library
- Olivier Blanvillain, Marios Iliofotou, Adelbert Chang, Gleb Kanterov, and other open-source contributors. 2016–2021. Frameless. https://github.com/typelevel/framelessGoogle Scholar
- Luca Cardelli, Simone Martini, John C Mitchell, and Andre Scedrov. 1994. An extension of system F with subtyping. Information and computation, 109, 1-2 (1994), 4–56. https://doi.org/10.1006/inco.1994.1013 Google Scholar
Digital Library
- Manuel M. T. Chakravarty, Gabriele Keller, and Simon Peyton Jones. 2005. Associated Type Synonyms. SIGPLAN Not., 40, 9 (2005), Sept., 241–253. issn:0362-1340 https://doi.org/10.1145/1090189.1086397 Google Scholar
Digital Library
- Tongfei Chen. 2017. Typesafe Abstractions for Tensor Operations (Short Paper). In Proceedings of the 8th ACM SIGPLAN International Symposium on Scala (SCALA 2017). Association for Computing Machinery, New York, NY, USA. 45–50. isbn:9781450355292 https://doi.org/10.1145/3136000.3136001 Google Scholar
Digital Library
- Judicaël Courant. 2003. Strong normalization with singleton types. Electronic Notes in Theoretical Computer Science, 70, 1 (2003), 53–71. https://doi.org/10.1016/S1571-0661(04)80490-0 Google Scholar
Cross Ref
- Richard A Eisenberg. 2016. Dependent types in Haskell: Theory and practice. University of Pennsylvania.Google Scholar
- Richard A. Eisenberg, Dimitrios Vytiniotis, Simon Peyton Jones, and Stephanie Weirich. 2014. Closed Type Families with Overlapping Equations. In Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL’14). Association for Computing Machinery, New York, NY, USA. 671–683. isbn:9781450325448 https://doi.org/10.1145/2535838.2535856 Google Scholar
Digital Library
- Burak Emir, Martin Odersky, and John Williams. 2007. Matching Objects with Patterns. In Proceedings of the 21st European Conference on Object-Oriented Programming (ECOOP’07). Springer-Verlag, Berlin, Heidelberg. 273–298. isbn:3540735887 https://doi.org/10.1007/978-3-540-73589-2_14 Google Scholar
Cross Ref
- 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. Proc. ACM Program. Lang., 4, ICFP (2020), Article 114, 29 pages. https://doi.org/10.1145/3408996 Google Scholar
Digital Library
- Robert Harper and Greg Morrisett. 1995. Compiling Polymorphism Using Intensional Type Analysis. In Proceedings of the 22nd ACM SIGPLAN-SIGACT Symposium on Principle s of Programming Languages (POPL ’95). Association for Computing Machinery, New York, NY, USA. 130–141. isbn:0897916921 https://doi.org/10.1145/199448.199475 Google Scholar
Digital Library
- Charles R. Harris, K. Jarrod Millman, Stéfan J. van der Walt, Ralf Gommers, Pauli Virtanen, David Cournapeau, Eric Wieser, Julian Taylor, Sebastian Berg, Nathaniel J. Smith, Robert Kern, Matti Picus, Stephan Hoyer, Marten H. van Kerkwijk, Matthew Brett, Allan Haldane, Jaime Fernández del Río, Mark Wiebe, Pearu Peterson, Pierre Gérard-Marchant, Kevin Sheppard, Tyler Reddy, Warren Weckesser, Hameer Abbasi, Christoph Gohlke, and Travis E. Oliphant. 2020. Array programming with NumPy. Nature, 585, 7825 (2020), Sept., 357–362. https://doi.org/10.1038/s41586-020-2649-2 Google Scholar
- Austin Huang, Sam Stites, and Torsten Scholak. 2017–2021. HaskTorch. https://github.com/hasktorch/hasktorchGoogle Scholar
- DeLesley S. Hutchins. 2010. Pure Subtype Systems. In Proceedings of the 37th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL’10). Association for Computing Machinery, New York, NY, USA. 287–298. isbn:9781605584799 https://doi.org/10.1145/1706299.1706334 Google Scholar
Digital Library
- Oleg Kiselyov, Ralf Lämmel, and Keean Schupke. 2004. Strongly Typed Heterogeneous Collections. In Proceedings of the 2004 ACM SIGPLAN Workshop on Haskell (Haskell ’04). Association for Computing Machinery, New York, NY, USA. 96–107. isbn:1581138504 https://doi.org/10.1145/1017472.1017488 Google Scholar
Digital Library
- George Leontiev, Eugene Burmako, Jason Zaugg, Adriaan Moors, Paul Phillips, Oron Port, and Miles Sabin. 2014. SIP-23 - Literal-Based Singleton Types. https://docs.scala-lang.org/sips/42.type.htmlGoogle Scholar
- Fengyun Liu. 2016. A Generic Algorithm for Checking Exhaustivity of Pattern Matching (Short Paper). In Proceedings of the 2016 7th ACM SIGPLAN Symposium on Scala (SCALA 2016). Association for Computing Machinery, New York, NY, USA. 61–64. isbn:9781450346481 https://doi.org/10.1145/2998392.2998401 Google Scholar
Digital Library
- Abel Nieto, Yaoyu Zhao, Ondřej Lhoták, Angela Chang, and Justin Pu. 2020. Scala with Explicit Nulls. 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. 25:1–25:26. isbn:978-3-95977-154-2 issn:1868-8969 https://doi.org/10.4230/LIPIcs.ECOOP.2020.25 Google Scholar
Cross Ref
- Benjamin C. Pierce. 2002. Types and programming languages. MIT press. isbn:0262162091Google Scholar
- Michael Pilquist and Scodec open-source contributors. 2013–2021. Scodec. https://github.com/scodec/scodecGoogle Scholar
- Marianna Rapoport, Ifaz Kabir, Paul He, and Ondřej Lhoták. 2017. A Simple Soundness Proof for Dependent Object Types. Proc. ACM Program. Lang., 1, OOPSLA (2017), Article 46, Oct., 27 pages. https://doi.org/10.1145/3133870 Google Scholar
Digital Library
- Alexander Rush. 2019. Tensor Considered Harmful. https://nlp.seas.harvard.edu/NamedTensorGoogle Scholar
- Miles Sabin and Shapeless open-source contributors. 2011–2021. Shapeless. https://github.com/milessabin/shapelessGoogle Scholar
- Michel Schinz. 2005. Compiling Scala for the Java virtual machine. Ph.D. Dissertation. EPFL. Lausanne. https://doi.org/10.5075/epfl-thesis-3302 Google Scholar
Cross Ref
- Tom Schrijvers, Simon Peyton Jones, Manuel Chakravarty, and Martin Sulzmann. 2008. Type Checking with Open Type Functions. In Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming (ICFP’08). Association for Computing Machinery, New York, NY, USA. 51–62. isbn:9781595939197 https://doi.org/10.1145/1411204.1411215 Google Scholar
Digital Library
- Vilhelm Sjoberg. 2015. A Dependently Typed Language with Nontermination. Ph.D. Dissertation. University of Pennsylvania.Google Scholar
- Christopher A. Stone and Robert Harper. 2000. Deciding Type Equivalence in a Language with Singleton Kinds. In Proceedings of the 27th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL’00). Association for Computing Machinery, New York, NY, USA. 214–227. isbn:1581131259 https://doi.org/10.1145/325694.325724 Google Scholar
Digital Library
- TypeScript development team. 2020. The TypeScript Handbook. https://www.typescriptlang.org/Google Scholar
- Stephanie Weirich, Dimitrios Vytiniotis, Simon Peyton Jones, and Steve Zdancewic. 2011. Generative Type Abstraction and Type-Level Computation. In Proceedings of the 38th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL’11). Association for Computing Machinery, New York, NY, USA. 227–240. isbn:9781450304900 https://doi.org/10.1145/1926385.1926411 Google Scholar
Digital Library
- Yanpeng Yang and Bruno C. d. S. Oliveira. 2017. Unifying Typing and Subtyping. Proc. ACM Program. Lang., 1, OOPSLA (2017), Article 47, 26 pages. https://doi.org/10.1145/3133871 Google Scholar
Digital Library
- Jan Zwanenburg. 1999. Pure type systems with subtyping. In International Conference on Typed Lambda Calculi and Applications. Springer Berlin Heidelberg, Berlin, Heidelberg. 381–396. https://doi.org/10.1007/3-540-48959-2_27 Google Scholar
Cross Ref
Index Terms
Type-level programming with match types
Recommendations
Type soundness for dependent object types (DOT)
OOPSLA '16Scala’s type system unifies aspects of ML modules, object- oriented, and functional programming. The Dependent Object Types (DOT) family of calculi has been proposed as a new theoretic foundation for Scala and similar expressive languages. ...
Type soundness for dependent object types (DOT)
OOPSLA 2016: Proceedings of the 2016 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and ApplicationsScala’s type system unifies aspects of ML modules, object- oriented, and functional programming. The Dependent Object Types (DOT) family of calculi has been proposed as a new theoretic foundation for Scala and similar expressive languages. ...






Comments