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 2019Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

a9-krishnaswami.webm

webm

81.6 MB

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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle ScholarCross RefCross Ref
  4. Matthias Blume. 2001. No-Longer-Foreign: Teaching an ML compiler to speak C “natively”. Electronic Notes in Theoretical Computer Science 59, 1 (2001).Google ScholarGoogle Scholar
  5. James Cheney and Ralf Hinze. 2003. First-Class Phantom Types. Technical Report CUCIS TR2003-1901. Cornell University.Google ScholarGoogle Scholar
  6. Jacek Chrząszcz. 1998. Polymorphic Subtyping Without Distributivity. In Mathematical Foundations of Computer Science (LNCS), Vol. 1450. Springer, 346–355. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Thierry Coquand. 1996. An Algorithm for Type-Checking Dependent Types. Science of Computer Programming 26, 1–3 (1996), 167–177. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Luis Damas and Robin Milner. 1982. Principal type-schemes for functional programs. In POPL. ACM Press, 207–212. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Rowan Davies and Frank Pfenning. 2000. Intersection Types and Computational Effects. In ICFP. ACM Press, 198–208. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Stephen Dolan and Alan Mycroft. 2017. Polymorphism, Subtyping, and Type Inference in MLsub. In POPL. ACM Press, 60–72. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Jana Dunfield. 2007a. Refined typechecking with Stardust. In Programming Languages meets Programming Verification (PLPV ’07). ACM Press, 21–32. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Jana Dunfield. 2007b. A Unified System of Type Refinements. Ph.D. Dissertation. Carnegie Mellon University. CMU-CS-07-129.Google ScholarGoogle Scholar
  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} . Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Jana Dunfield and Frank Pfenning. 2003. Type Assignment for Intersections and Unions in Call-by-Value Languages. In FoSSaCS. Springer, 250–266. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Matthew Fluet and Riccardo Pucella. 2006. Phantom types and subtyping. (2006). arXiv: cs/0403034 {cs.PL} . Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle Scholar
  17. Jacques Garrigue and Didier Rémy. 2013. Ambivalent Types for Principal Type Inference with GADTs. In APLAS. Springer, 257–272. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 .Google ScholarGoogle Scholar
  19. Robert Harper and Greg Morrisett. 1995. Compiling polymorphism using intensional type analysis. In POPL. ACM Press, 130–141. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Neelakantan R. Krishnaswami. 2009. Focusing on Pattern Matching. In POPL. ACM Press, 366–378. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Daan Leijen and Erik Meijer. 1999. Domain specific embedded compilers. In USENIX Conf. Domain-Specific Languages (DSL ’99). ACM Press, 109–122. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Martin Odersky, Matthias Zenger, and Christoph Zenger. 2001. Colored Local Type Inference. In POPL. ACM Press, 41–53. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Benjamin C. Pierce. 2002. Types and Programming Languages. MIT Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Benjamin C. Pierce and David N. Turner. 2000. Local Type Inference. ACM Trans. Prog. Lang. Sys. 22 (2000), 1–44. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. François Pottier and Yann Régis-Gianas. 2006. Stratified type inference for generalized algebraic data types. In POPL. ACM Press, 232–244. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Patrick Rondon, Ming Kawaguchi, and Ranjit Jhala. 2008. Liquid types. In PLDI. ACM Press, 159–169. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Peter Schroeder-Heister. 1994. Definitional reflection and the completion. In Extensions of Logic Programming (LNCS). Springer, 333–347. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Jerzy Tiuryn and Paweł Urzyczyn. 1996. The Subtyping Problem for Second-Order Types is Undecidable. In LICS. IEEE Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle ScholarCross RefCross Ref
  38. Hongwei Xi, Chiyan Chen, and Gang Chen. 2003. Guarded recursive datatype constructors. In POPL. ACM Press, 224–235. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Hongwei Xi and Frank Pfenning. 1999. Dependent Types in Practical Programming. In POPL. ACM Press, 214–227. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Noam Zeilberger. 2009. Refinement Types and Computational Duality. In Programming Languages meets Programming Verification (PLPV ’09). ACM Press, 15–26. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Sound and complete bidirectional typechecking for higher-rank polymorphism with existentials and indexed 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