Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Sound and complete bidirectional typechecking for higher-rank polymorphism with existentials and indexed types

Published: 02 January 2019 Publication History

Abstract

Bidirectional typechecking, in which terms either synthesize a type or are checked against a known type, has become popular for its applicability to a variety of type systems, its error reporting, and its ease of implementation. Following principles from proof theory, bidirectional typing can be applied to many type constructs. The principles underlying a bidirectional approach to indexed types (generalized algebraic datatypes) are less clear. Building on proof-theoretic treatments of equality, we give a declarative specification of typing based on focalization. This approach permits declarative rules for coverage of pattern matching, as well as support for first-class existential types using a focalized subtyping judgment. We use refinement types to avoid explicitly passing equality proofs in our term syntax, making our calculus similar to languages such as Haskell and OCaml. We also extend the declarative specification with an explicit rules for deducing when a type is principal, permitting us to give a complete declarative specification for a rich type system with significant type inference. We also give a set of algorithmic typing rules, and prove that it is sound and complete with respect to the declarative system. The proof requires a number of technical innovations, including proving soundness and completeness in a mutually recursive fashion.

Supplementary Material

WEBM File (a9-krishnaswami.webm)

References

[1]
Andreas Abel. 2006. Towards Generic Programming with Sized Types. In Mathematics of Program Construction (LNCS), Tarmo Uustalu (Ed.), Vol. 4014. Springer, 10–28.
[2]
Andreas Abel, Thierry Coquand, and Peter Dybjer. 2008. Verifying a Semantic βη-Conversion Test for Martin-Löf Type Theory. In Mathematics of Program Construction (MPC’08) (LNCS), Vol. 5133. Springer, 29–56.
[3]
Henk Barendregt, Mario Coppo, and Mariangiola Dezani-Ciancaglini. 1983. A Filter Lambda Model and the Completeness of Type Assignment. J. Symbolic Logic 48, 4 (1983), 931–940.
[4]
Matthias Blume. 2001. No-Longer-Foreign: Teaching an ML compiler to speak C “natively”. Electronic Notes in Theoretical Computer Science 59, 1 (2001).
[5]
James Cheney and Ralf Hinze. 2003. First-Class Phantom Types. Technical Report CUCIS TR2003-1901. Cornell University.
[6]
Jacek Chrząszcz. 1998. Polymorphic Subtyping Without Distributivity. In Mathematical Foundations of Computer Science (LNCS), Vol. 1450. Springer, 346–355.
[7]
Thierry Coquand. 1996. An Algorithm for Type-Checking Dependent Types. Science of Computer Programming 26, 1–3 (1996), 167–177.
[8]
Luis Damas and Robin Milner. 1982. Principal type-schemes for functional programs. In POPL. ACM Press, 207–212.
[9]
Rowan Davies and Frank Pfenning. 2000. Intersection Types and Computational Effects. In ICFP. ACM Press, 198–208.
[10]
Stephen Dolan and Alan Mycroft. 2017. Polymorphism, Subtyping, and Type Inference in MLsub. In POPL. ACM Press, 60–72.
[11]
Jana Dunfield. 2007a. Refined typechecking with Stardust. In Programming Languages meets Programming Verification (PLPV ’07). ACM Press, 21–32.
[12]
Jana Dunfield. 2007b. A Unified System of Type Refinements. Ph.D. Dissertation. Carnegie Mellon University. CMU-CS-07-129.
[13]
Jana Dunfield and Neelakantan R. Krishnaswami. 2013. Complete and Easy Bidirectional Typechecking for Higher-Rank Polymorphism. In ICFP. ACM Press, 429–442. arXiv: 1306.6032 {cs.PL} .
[14]
Jana Dunfield and Frank Pfenning. 2003. Type Assignment for Intersections and Unions in Call-by-Value Languages. In FoSSaCS. Springer, 250–266.
[15]
Matthew Fluet and Riccardo Pucella. 2006. Phantom types and subtyping. (2006). arXiv: cs/0403034 {cs.PL} .
[16]
Jacques Garrigue and Jacques Le Normand. 2015. GADTs and Exhaustiveness: Looking for the Impossible. In Proceedings ML Family / OCaml Users and Developers workshops, ML Family/OCaml 2015 (EPTCS). 23–35.
[17]
Jacques Garrigue and Didier Rémy. 2013. Ambivalent Types for Principal Type Inference with GADTs. In APLAS. Springer, 257–272.
[18]
Jean-Yves Girard. 1992. A Fixpoint Theorem in Linear Logic. (1992). Post to Linear Logic mailing list, http://www.seas. upenn.edu/~sweirich/types/archive/1992/msg00030.html .
[19]
Robert Harper and Greg Morrisett. 1995. Compiling polymorphism using intensional type analysis. In POPL. ACM Press, 130–141.
[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 ICFP. ACM Press, 424–436.
[21]
Neelakantan R. Krishnaswami. 2009. Focusing on Pattern Matching. In POPL. ACM Press, 366–378.
[22]
Konstantin Läufer and Martin Odersky. 1994. Polymorphic type inference and abstract data types. ACM Trans. Prog. Lang. Sys. 16, 5 (1994), 1411–1430.
[23]
Daan Leijen and Erik Meijer. 1999. Domain specific embedded compilers. In USENIX Conf. Domain-Specific Languages (DSL ’99). ACM Press, 109–122.
[24]
Martin Odersky, Matthias Zenger, and Christoph Zenger. 2001. Colored Local Type Inference. In POPL. ACM Press, 41–53.
[25]
Simon Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Mark Shields. 2007. Practical type inference for arbitraryrank types. J. Functional Programming 17, 1 (2007), 1–82.
[26]
Simon Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Geoffrey Washburn. 2006. Simple unification-based type inference for GADTs. In ICFP. ACM Press, 50–61.
[27]
Brigitte Pientka. 2008. A type-theoretic foundation for programming with higher-order abstract syntax and first-class substitutions. In POPL. ACM Press, 371–382.
[28]
Benjamin C. Pierce. 2002. Types and Programming Languages. MIT Press.
[29]
Benjamin C. Pierce and David N. Turner. 2000. Local Type Inference. ACM Trans. Prog. Lang. Sys. 22 (2000), 1–44.
[30]
François Pottier and Yann Régis-Gianas. 2006. Stratified type inference for generalized algebraic data types. In POPL. ACM Press, 232–244.
[31]
Patrick Rondon, Ming Kawaguchi, and Ranjit Jhala. 2008. Liquid types. In PLDI. ACM Press, 159–169.
[32]
Peter Schroeder-Heister. 1994. Definitional reflection and the completion. In Extensions of Logic Programming (LNCS). Springer, 333–347.
[33]
Vincent Simonet and François Pottier. 2007. A constraint-based approach to guarded algebraic data types. ACM Transactions on Programming Languages and Systems (TOPLAS) 29, 1 (2007), 1.
[34]
Jerzy Tiuryn and Paweł Urzyczyn. 1996. The Subtyping Problem for Second-Order Types is Undecidable. In LICS. IEEE Press.
[35]
Dimitrios Vytiniotis, Simon Peyton Jones, and Tom Schrijvers. 2010. Let should not be generalised. In Workshop on Types in Language Design and Impl. (TLDI ’10). ACM Press, 39–50.
[36]
Dimitrios Vytiniotis, Simon Peyton Jones, Tom Schrijvers, and Martin Sulzmann. 2011. OutsideIn(X): Modular type inference with local assumptions. J. Functional Programming 21, 4–5 (2011), 333–412.
[37]
Kevin Watkins, Iliano Cervesato, Frank Pfenning, and David Walker. 2004. A Concurrent Logical Framework: The Propositional Fragment. In Types for Proofs and Programs. Springer LNCS 3085, 355–377.
[38]
Hongwei Xi, Chiyan Chen, and Gang Chen. 2003. Guarded recursive datatype constructors. In POPL. ACM Press, 224–235.
[39]
Hongwei Xi and Frank Pfenning. 1999. Dependent Types in Practical Programming. In POPL. ACM Press, 214–227.
[40]
Noam Zeilberger. 2009. Refinement Types and Computational Duality. In Programming Languages meets Programming Verification (PLPV ’09). ACM Press, 15–26.

Cited By

View all
  • (2024)When Subtyping Constraints Liberate: A Novel Type Inference Approach for First-Class PolymorphismProceedings of the ACM on Programming Languages10.1145/36328908:POPL(1418-1450)Online publication date: 5-Jan-2024
  • (2024)The Essence of Generalized Algebraic Data TypesProceedings of the ACM on Programming Languages10.1145/36328668:POPL(695-723)Online publication date: 5-Jan-2024
  • (2023)Greedy Implicit Bounded QuantificationProceedings of the ACM on Programming Languages10.1145/36228717:OOPSLA2(2083-2111)Online publication date: 16-Oct-2023
  • Show More Cited By

Index Terms

  1. Sound and complete bidirectional typechecking for higher-rank polymorphism with existentials and indexed types

      Recommendations

      Comments

      Information & Contributors

      Information

      Published In

      cover image Proceedings of the ACM on Programming Languages
      Proceedings of the ACM on Programming Languages  Volume 3, Issue POPL
      January 2019
      2275 pages
      EISSN:2475-1421
      DOI:10.1145/3302515
      Issue’s Table of Contents
      This work is licensed under a Creative Commons Attribution International 4.0 License.

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      Published: 02 January 2019
      Published in PACMPL Volume 3, Issue POPL

      Permissions

      Request permissions for this article.

      Check for updates

      Author Tags

      1. GADTs
      2. bidirectional typechecking
      3. equality types
      4. existential types
      5. higher-rank polymorphism
      6. indexed types

      Qualifiers

      • Research-article

      Funding Sources

      Contributors

      Other Metrics

      Bibliometrics & Citations

      Bibliometrics

      Article Metrics

      • Downloads (Last 12 months)181
      • Downloads (Last 6 weeks)23
      Reflects downloads up to 13 Sep 2024

      Other Metrics

      Citations

      Cited By

      View all
      • (2024)When Subtyping Constraints Liberate: A Novel Type Inference Approach for First-Class PolymorphismProceedings of the ACM on Programming Languages10.1145/36328908:POPL(1418-1450)Online publication date: 5-Jan-2024
      • (2024)The Essence of Generalized Algebraic Data TypesProceedings of the ACM on Programming Languages10.1145/36328668:POPL(695-723)Online publication date: 5-Jan-2024
      • (2023)Greedy Implicit Bounded QuantificationProceedings of the ACM on Programming Languages10.1145/36228717:OOPSLA2(2083-2111)Online publication date: 16-Oct-2023
      • (2023)Focusing on Refinement TypingACM Transactions on Programming Languages and Systems10.1145/361040845:4(1-62)Online publication date: 20-Dec-2023
      • (2023)Compilation Semantics for a Programming Language with VersionsProgramming Languages and Systems10.1007/978-981-99-8311-7_1(3-23)Online publication date: 26-Nov-2023
      • (2022)On type-cases, union elimination, and occurrence typingProceedings of the ACM on Programming Languages10.1145/34986746:POPL(1-31)Online publication date: 12-Jan-2022
      • (2022)Polarized SubtypingProgramming Languages and Systems10.1007/978-3-030-99336-8_16(431-461)Online publication date: 29-Mar-2022
      • (2021)An existential crisis resolved: type inference for first-class existential typesProceedings of the ACM on Programming Languages10.1145/34735695:ICFP(1-29)Online publication date: 19-Aug-2021
      • (2021)Bidirectional TypingACM Computing Surveys10.1145/345095254:5(1-38)Online publication date: 25-May-2021
      • (2021)A Systematic Literature Review on Federated Machine LearningACM Computing Surveys10.1145/345028854:5(1-39)Online publication date: 25-May-2021
      • Show More Cited By

      View Options

      View options

      PDF

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader

      Get Access

      Login options

      Full Access

      Media

      Figures

      Other

      Tables

      Share

      Share

      Share this Publication link

      Share on social media