skip to main content
research-article
Open Access
Artifacts Evaluated & Functional

A mechanical formalization of higher-ranked polymorphic type inference

Published:26 July 2019Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

a112-zhao.webm

References

  1. 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 ScholarGoogle Scholar
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. Arthur Charguéraud. 2012. The Locally Nameless Representation. Journal of Automated Reasoning 49, 3 (01 Oct 2012), 363–408.Google ScholarGoogle Scholar
  8. Paul Chiusano and Runar Bjarnason. 2015. Unison. http://unisonweb.orgGoogle ScholarGoogle Scholar
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. Catherine Dubois. 2000. Proving ML type soundness within Coq. Theorem Proving in Higher Order Logics (2000), 126–144. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. Phil Freeman. 2017. PureScript. http://www.purescript.org/Google ScholarGoogle Scholar
  16. Andrew Gacek. 2008. The Abella Interactive Theorem Prover (System Description). In Proceedings of IJCAR 2008 (Lecture Notes in Artificial Intelligence). Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. 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 ScholarGoogle ScholarCross RefCross Ref
  18. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  19. Roger Hindley. 1969. The principal type-scheme of an object in combinatory logic. Transactions of the american mathematical society 146 (1969), 29–60.Google ScholarGoogle Scholar
  20. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  21. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  22. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  23. Xavier Leroy et al. 2012. The CompCert verified compiler. Documentation and user’s manual. INRIA Paris-Rocquencourt (2012).Google ScholarGoogle Scholar
  24. Alberto Martelli and Ugo Montanari. 1982. An Efficient Unification Algorithm. ACM Trans. Program. Lang. Syst. 4, 2 (April 1982), 258–282. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Dale Miller. 2000. Abstract Syntax for Variable Binders: An Overview. In CL 2000: Computational Logic (Lecture Notes in Artificial Intelligence). Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Robin Milner. 1978. A theory of type polymorphism in programming. Journal of computer and system sciences 17, 3 (1978), 348–375.Google ScholarGoogle ScholarCross RefCross Ref
  27. Wolfgang Naraschewski and Tobias Nipkow. 1999. Type inference verified: Algorithm W in Isabelle/HOL. Journal of Automated Reasoning 23, 3 (1999), 299–318. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  29. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  30. 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 ScholarGoogle Scholar
  31. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  32. 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 ScholarGoogle Scholar
  33. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  34. John C Reynolds. 1983. Types, Abstraction and Parametric Polymorphism. Information Processing (1983), 513–523.Google ScholarGoogle Scholar
  35. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  36. The Coq development team. 2017. The Coq proof assistant. https://coq.inria.fr/Google ScholarGoogle Scholar
  37. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  38. Christian Urban. 2008. Nominal techniques in Isabelle/HOL. Journal of Automated Reasoning 40, 4 (2008), 327–356. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. 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 ScholarGoogle Scholar
  40. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  41. 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 ScholarGoogle ScholarCross RefCross Ref
  42. 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 ScholarGoogle Scholar
  43. 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 ScholarGoogle Scholar

Index Terms

  1. A mechanical formalization of higher-ranked polymorphic type inference

        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
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!