Abstract
Modern functional programming languages, such as Haskell or OCaml, use sophisticated forms of type inference. While an important topic in the Programming Languages research, there is little work on the mechanization of the metatheory of type inference in theorem provers. In particular we are unaware of any complete formalization of the type inference algorithms that are the backbone of modern functional languages.
This paper presents the first full mechanical formalization of the metatheory for higher-ranked polymorphic type inference. The system that we formalize is the bidirectional type system by Dunfield and Krishnaswami (DK). The DK type system has two variants (a declarative and an algorithmic one) that have been manually proven sound, complete and decidable. We present a mechanical formalization in the Abella theorem prover of DK’s declarative type system with a novel algorithmic system. We have a few reasons to use a new algorithm. Firstly, our new algorithm employs worklist judgments, which precisely capture the scope of variables and simplify the formalization of scoping in a theorem prover. Secondly, while DK’s original formalization comes with very well-written manual proofs, there are several details missing and some incorrect proofs, which complicate the task of writing a mechanized proof. Despite the use of a different algorithm we prove the same results as DK, although with significantly different proofs and proof techniques. Since such type inference algorithms are quite subtle and have a complex metatheory, mechanical formalizations are an important advance in type-inference research.
Supplemental Material
Available for Download
This is the appendices for paper "A Mechanical Formalization of Higher-Ranked Polymorphic Type Inference".
- Andreas Abel, Guillaume Allais, Aliya Hameer, Brigitte Pientka, Alberto Momigliano, Steven Schäfer, and Kathrin Stark. 2018. POPLMark Reloaded: Mechanizing Proofs by Logical Relations. Submitted to the Journal of functional programming (2018).Google Scholar
- Andreas Abel and Brigitte Pientka. 2011. Higher-order dynamic pattern unification for dependent types and records. In International Conference on Typed Lambda Calculi and Applications. Springer, 10–26. Google Scholar
Digital Library
- 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). Google Scholar
Digital Library
- Brian E Aydemir, Aaron Bohannon, Matthew Fairbairn, J Nathan Foster, Benjamin C Pierce, Peter Sewell, Dimitrios Vytiniotis, Geoffrey Washburn, Stephanie Weirich, and Steve Zdancewic. 2005. Mechanized metatheory for the masses: The POPLmark challenge. In The 18th International Conference on Theorem Proving in Higher Order Logics. Google Scholar
Digital Library
- Yves Bertot, Benjamin Grégoire, and Xavier Leroy. 2006. A Structured Approach to Proving Compiler Optimizations Based on Dataflow Analysis. In Proceedings of the 2004 International Conference on Types for Proofs and Programs (TYPES’04). Google Scholar
Digital Library
- Bor-Yuh Evan Chang, Adam Chlipala, and George C. Necula. 2006. A Framework for Certified Program Analysis and Its Applications to Mobile-code Safety. In Proceedings of the 7th International Conference on Verification, Model Checking, and Abstract Interpretation (VMCAI’06). Google Scholar
Digital Library
- Arthur Charguéraud. 2012. The Locally Nameless Representation. Journal of Automated Reasoning 49, 3 (01 Oct 2012), 363–408.Google Scholar
- Paul Chiusano and Runar Bjarnason. 2015. Unison. http://unisonweb.orgGoogle Scholar
- Adam Chlipala. 2008. Parametric Higher-order Abstract Syntax for Mechanized Semantics. In Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming (ICFP ’08). Google Scholar
Digital Library
- 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). Google Scholar
Digital Library
- Catherine Dubois. 2000. Proving ML type soundness within Coq. Theorem Proving in Higher Order Logics (2000), 126–144. Google Scholar
Digital Library
- Catherine Dubois and Valerie Menissier-Morain. 1999. Certification of a type inference tool for ML: Damas–Milner within Coq. Journal of Automated Reasoning 23, 3 (1999), 319–346. Google Scholar
Digital Library
- Joshua Dunfield and Neelakantan R. Krishnaswami. 2013. Complete and Easy Bidirectional Typechecking for Higher-rank Polymorphism. In Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming (ICFP ’13). Google Scholar
Digital Library
- Joshua Dunfield and Neelakantan R. Krishnaswami. 2019. Sound and Complete Bidirectional Typechecking for Higher-rank Polymorphism with Existentials and Indexed Types. Proc. ACM Program. Lang. 3, POPL, Article 9 (Jan. 2019), 28 pages. Google Scholar
Digital Library
- Phil Freeman. 2017. PureScript. http://www.purescript.org/Google Scholar
- Andrew Gacek. 2008. The Abella Interactive Theorem Prover (System Description). In Proceedings of IJCAR 2008 (Lecture Notes in Artificial Intelligence). Google Scholar
Digital Library
- Jacques Garrigue. 2015. A certified implementation of ML with structural polymorphism and recursive types. Mathematical Structures in Computer Science 25, 4 (2015), 867–891.Google Scholar
Cross Ref
- Adam Gundry, Conor McBride, and James McKinna. 2010. Type Inference in Context. In Proceedings of the Third ACM SIGPLAN Workshop on Mathematically Structured Functional Programming (MSFP ’10). Google Scholar
Digital Library
- Roger Hindley. 1969. The principal type-scheme of an object in combinatory logic. Transactions of the american mathematical society 146 (1969), 29–60.Google Scholar
- Casey Klein, John Clements, Christos Dimoulas, Carl Eastlund, Matthias Felleisen, Matthew Flatt, Jay A. McCarthy, Jon Rafkind, Sam Tobin-Hochstadt, and Robert Bruce Findler. 2012. Run Your Research: On the Effectiveness of Lightweight Mechanization. In Proceedings of the 39th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’12). 285–296. Google Scholar
Digital Library
- Didier Le Botlan and Didier Rémy. 2003. MLF: Raising ML to the Power of System F. In Proceedings of the Eighth ACM SIGPLAN International Conference on Functional Programming (ICFP ’03). Google Scholar
Digital Library
- Daan Leijen. 2008. HMF: Simple Type Inference for First-class Polymorphism. In Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming (ICFP ’08). Google Scholar
Digital Library
- Xavier Leroy et al. 2012. The CompCert verified compiler. Documentation and user’s manual. INRIA Paris-Rocquencourt (2012).Google Scholar
- Alberto Martelli and Ugo Montanari. 1982. An Efficient Unification Algorithm. ACM Trans. Program. Lang. Syst. 4, 2 (April 1982), 258–282. Google Scholar
Digital Library
- Dale Miller. 2000. Abstract Syntax for Variable Binders: An Overview. In CL 2000: Computational Logic (Lecture Notes in Artificial Intelligence). Google Scholar
Digital Library
- Robin Milner. 1978. A theory of type polymorphism in programming. Journal of computer and system sciences 17, 3 (1978), 348–375.Google Scholar
Cross Ref
- Wolfgang Naraschewski and Tobias Nipkow. 1999. Type inference verified: Algorithm W in Isabelle/HOL. Journal of Automated Reasoning 23, 3 (1999), 299–318. Google Scholar
Digital Library
- Tobias Nipkow, Lawrence C Paulson, and Markus Wenzel. 2002. Isabelle/HOL: a proof assistant for higher-order logic. Vol. 2283. Springer Science & Business Media. Google Scholar
Digital Library
- Martin Odersky and Konstantin Läufer. 1996. Putting Type Annotations to Work. In Proceedings of the 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’96). Google Scholar
Digital Library
- Simon Peyton Jones and Mark Shields. 2004. Lexically-scoped type variables. (2004). http://research.microsoft.com/enus/um/people/simonpj/papers/scoped- tyvars/ Draft.Google Scholar
- Simon Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Mark Shields. 2007. Practical type inference for arbitraryrank types. Journal of functional programming 17, 1 (2007), 1–82. Google Scholar
Digital Library
- François Pottier and Didier Rémy. 2005. Advanced Topics in Types and Programming Languages. The MIT Press, Chapter The Essence of ML Type Inference, 387–489.Google Scholar
- Jason Reed. 2009. Higher-order Constraint Simplification in Dependent Type Theory. In Proceedings of the Fourth International Workshop on Logical Frameworks and Meta-Languages: Theory and Practice (LFMTP ’09). Google Scholar
Digital Library
- John C Reynolds. 1983. Types, Abstraction and Parametric Polymorphism. Information Processing (1983), 513–523.Google Scholar
- Alejandro Serrano, Jurriaan Hage, Dimitrios Vytiniotis, and Simon Peyton Jones. 2018. Guarded Impredicative Polymorphism. In Proceedings of the 39th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 2018). Google Scholar
Digital Library
- The Coq development team. 2017. The Coq proof assistant. https://coq.inria.fr/Google Scholar
- Jerzy Tiuryn and Pawel Urzyczyn. 1996. The subtyping problem for second-order types is undecidable. In Proceedings 11th Annual IEEE Symposium on Logic in Computer Science. Google Scholar
Digital Library
- Christian Urban. 2008. Nominal techniques in Isabelle/HOL. Journal of Automated Reasoning 40, 4 (2008), 327–356. Google Scholar
Digital Library
- Christian Urban and Tobias Nipkow. 2008. Nominal verification of algorithm W. From Semantics to Computer Science. Essays in Honour of Gilles Kahn (2008), 363–382.Google Scholar
- Dimitrios Vytiniotis, Stephanie Weirich, and Simon Peyton Jones. 2008. FPH: First-class Polymorphism for Haskell. In Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming (ICFP ’08). Google Scholar
Digital Library
- Joe B Wells. 1999. Typability and type checking in System F are equivalent and undecidable. Annals of Pure and Applied Logic 98, 1-3 (1999), 111–156.Google Scholar
Cross Ref
- Ningning Xie and Bruno C. d. S. Oliveira. 2018. Let Arguments Go First. In Programming Languages and Systems, Amal Ahmed (Ed.). Springer International Publishing, Cham, 272–299.Google Scholar
- Jinxu Zhao, Bruno C. d. S. Oliveira, and Tom Schrijvers. 2018. Formalization of a Polymorphic Subtyping Algorithm. In ITP (Lecture Notes in Computer Science), Vol. 10895. Springer, 604–622.Google Scholar
Index Terms
A mechanical formalization of higher-ranked polymorphic type inference
Recommendations
Sound and complete bidirectional typechecking for higher-rank polymorphism with existentials and indexed types
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 ...
Type checking and inference for polymorphic and existential types
CATS '09: Proceedings of the Fifteenth Australasian Symposium on Computing: The Australasian Theory - Volume 94This paper proves undecidability of type checking and type inference problems in some variants of typed lambda calculi with polymorphic and existential types. First, type inference in the domain-free polymorphic lambda calculus is proved to be ...
Polymorphic type inference and abstract data types
Many statically typed programming languages provide an abstract data type construct, such as the module in Modula-2. However, in most of these languages, implementations of abstract data types are not first-class values. Thus, they cannot be assigned to ...






Comments