Abstract
In recent years, languages like Haskell have seen a dramatic surge of new features that significantly extends the expressive power of their type systems. With these features, the challenge of kind inference for datatype declarations has presented itself and become a worthy research problem on its own. This paper studies kind inference for datatypes. Inspired by previous research on type-inference, we offer declarative specifications for what datatype declarations should be accepted, both for Haskell98 and for a more advanced system we call PolyKinds, based on the extensions in modern Haskell, including a limited form of dependent types. We believe these formulations to be novel and without precedent, even for Haskell98. These specifications are complemented with implementable algorithmic versions. We study soundness, completeness and the existence of principal kinds in these systems, proving the properties where they hold. This work can serve as a guide both to language designers who wish to formalize their datatype declarations and also to implementors keen to have principled inference of principal types.
Supplemental Material
- 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
- P. B. Andrews. 1971. Resolution in type Theory. Journal of Symbolic Logic 36 (1971), 414–432.Google Scholar
Cross Ref
- Richard S. Bird and Lambert Meertens. 1998. Nested datatypes. In LNCS 1422: Proceedings of Mathematics of Program Construction, Johan Jeuring (Ed.). Springer-Verlag, Marstrand, Sweden, 52–67. http://www.cs.ox.ac.uk/people/richard. bird/online/BirdMeertens98Nested.pdfGoogle Scholar
- Joachim Breitner, Richard A Eisenberg, Simon Peyton Jones, and Stephanie Weirich. 2016. Safe zero-cost coercions for Haskell. Journal of Functional Programming 26 (2016).Google Scholar
- L. Cardelli. 1986. A polymorphic lambda-calculus with Type:Type. Technical Report 10. SRC.Google Scholar
- Manuel M. T. Chakravarty, Gabriele Keller, and Simon Peyton Jones. 2005. Associated type synonyms. In Proceedings of the Tenth ACM SIGPLAN International Conference on Functional Programming (ICFP ’05). ACM, New York, NY, USA, 241–253. Google Scholar
Digital Library
- Jesper Cockx, Dominique Devriese, and Frank Piessens. 2016. Unifiers as equivalences: proof-relevant unification of dependently typed data. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming (ICFP 2016). ACM, New York, NY, USA, 270–283. Google Scholar
Digital Library
- Claudio Sacerdoti Coen. 2004. Mathematical knowledge management and interactive theorem proving. Ph.D. Dissertation. University of Bologna, 2004. Technical Report UBLCS 2004-5.Google Scholar
- Marco Comini, Ferruccio Damiani, and Samuel Vrech. 2008. On polymorphic recursion, type systems, and abstract interpretation. In International Static Analysis Symposium. Springer, 144–158.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). ACM, New York, NY, USA, 207–212. Google Scholar
Digital Library
- Ferruccio Damiani. 2003. Rank 2 intersection types for local definitions and conditional expressions. ACM Transactions on Programming Languages and Systems (TOPLAS) 25, 4 (2003), 401–451.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). ACM, New York, NY, USA, 429–442. Google Scholar
Digital Library
- Richard A Eisenberg. 2016. Dependent types in haskell: Theory and practice. Ph.D. Dissertation. 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). ACM, New York, NY, USA, 671–683. Google Scholar
Digital Library
- Richard A Eisenberg, Stephanie Weirich, and Hamidhasan G Ahmed. 2016. Visible type application. In European Symposium on Programming. Springer, 229–254.Google Scholar
Digital Library
- Ronald Garcia and Matteo Cimini. 2015. Principal type schemes for gradual programs. In Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’15). ACM, New York, NY, USA, 303–315. Google Scholar
Digital Library
- Warren D Goldfarb. 1981. The undecidability of the second-order unification problem. Theoretical Computer Science 13, 2 (1981), 225–230.Google Scholar
- Roberta Gori and Giorgio Levi. 2002. An experiment in type inference and verification by abstract interpretation. In International Workshop on Verification, Model Checking, and Abstract Interpretation. Springer, 225–239.Google Scholar
Cross Ref
- Roberta Gori and Giorgio Levi. 2003. Properties of a type abstract interpreter. In International Workshop on Verification, Model Checking, and Abstract Interpretation. Springer, 132–145.Google Scholar
Cross Ref
- Adam Gundry and Conor McBride. 2013. A tutorial implementation of dynamic pattern unification. Unpublished draft (2013).Google Scholar
- 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. ACM, 43–54.Google Scholar
Digital Library
- Adam Michael Gundry. 2013. Type inference, Haskell and dependent types. Ph.D. Dissertation. University of Strathclyde.Google Scholar
- Fritz Henglein. 1993. Type inference with polymorphic recursion. ACM Trans. Program. Lang. Syst. 15, 2 (April 1993), 253–289. Google Scholar
Digital Library
- J. Roger Hindley. 1969. The principal type-scheme of an object in combinatory logic. Trans. Amer. Math. Soc. 146 (1969), 29–60.Google Scholar
- G. Huet. 1973. A unification algorithm for typed lambda calculus. Theoretical Computer Science 1, 1 (1973), 27–57.Google Scholar
Cross Ref
- Trevor Jim. 1996. What are principal typings and what are they good for?. In Proceedings of the 23rd ACM SIGPLAN-SIGACT symposium on Principles of programming languages. ACM, 42–53.Google Scholar
Digital Library
- Mark P Jones. 1995. A system of constructor classes: overloading and implicit higher-order polymorphism. Journal of functional programming 5, 1 (1995), 1–35.Google Scholar
Cross Ref
- Mark P. Jones. 1999. Typing Haskell in Haskell. In Proceedings of the 1999 Haskell Workshop (Haskell ’99), Erik Meijer (Ed.). Paris, France, pp. 9–22. University of Utrecht Technical Report UU-CS-1999-28.Google Scholar
- Csongor Kiss, Susan Eisenbach, Tony Field, and Simon Peyton Jones. 2019. Higher-order type-level programming in Haskell. In Proceedings of the 24th ACM SIGPLAN International Conference on Functional Programming (ICFP 2019). ACM.Google Scholar
Digital Library
- Didier Le Botlan and Didier Rémy. 2003. MLF: Raising ML to the Power of System F (ICFP ’03). 12.Google Scholar
Digital Library
- Daan Leijen. 2009. Flexible types: robust type inference for first-class polymorphism. In Proceedings of the 36th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’09). ACM, New York, NY, USA, 66–77. Google Scholar
Digital Library
- Dale Miller. 1991. Unification of simply typed lambda-terms as logic programming. (1991).Google Scholar
- Alan Mycroft. 1984. Polymorphic type schemes and recursive definitions. In International Symposium on Programming. Springer, 217–228.Google Scholar
Cross Ref
- 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). ACM, New York, NY, USA, 54–67. Google Scholar
Digital Library
- Simon Peyton Jones. 2003. Haskell 98 language and libraries: the revised report. Cambridge University Press.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
- Simon Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Geoffrey Washburn. 2006. Simple unification-based type inference for GADTs. In Proceedings of the Eleventh ACM SIGPLAN International Conference on Functional Programming (ICFP ’06). ACM, New York, NY, USA, 50–61. Google Scholar
Digital Library
- François Pottier and Didier Rémy. 2005. The essence of ML type inference. Advanced Topics in Types and Programming Languages (2005).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. ACM, 49–56.Google Scholar
Digital Library
- Didier Rémy and Boris Yakobowski. 2008. From ML to MLF: Graphic type constraints with efficient type inference. In Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming (ICFP ’08). ACM, New York, NY, USA, 63–74. Google Scholar
Digital Library
- Tom Schrijvers, Simon Peyton Jones, Martin Sulzmann, and Dimitrios Vytiniotis. 2009. Complete and decidable type inference for GADTs. In Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming (ICFP ’09). ACM, New York, NY, USA, 341–352. Google Scholar
Digital Library
- 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). ACM, New York, NY, USA, 783–796. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- Dimitrios Vytiniotis, Simon Peyton Jones, Tom Schrijvers, and Martin Sulzmann. 2011. OutsideIn (X) Modular type inference with local assumptions. Journal of functional programming 21, 4-5 (2011), 333–412.Google Scholar
Digital Library
- Dimitrios Vytiniotis, Stephanie Weirich, and Simon Peyton Jones. 2008. FPH: First-class polymorphism for Haskell (ICFP ’08). 12.Google Scholar
Digital Library
- Stephanie Weirich, Pritam Choudhury, Antoine Voizard, and Richard A. Eisenberg. 2019. A Role for dependent types in Haskell. Proc. ACM Program. Lang. 3, ICFP, Article 101 (July 2019), 29 pages. Google Scholar
Digital Library
- Stephanie Weirich, Justin Hsu, and Richard A. Eisenberg. 2013. System FC with Explicit Kind Equality. In Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming (ICFP ’13). ACM, New York, NY, USA, 275–286. Google Scholar
Digital Library
- Stephanie Weirich, Antoine Voizard, Pedro Henrique Azevedo de Amorim, and Richard A Eisenberg. 2017. A specification for dependent types in Haskell. In Proceedings of the 22th ACM SIGPLAN International Conference on Functional Programming (ICFP ’17). ACM.Google Scholar
Digital Library
- Hongwei Xi, Chiyan Chen, and Gang Chen. 2003. Guarded recursive datatype constructors. In Proceedings of the 30th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’03). ACM, New York, NY, USA, 224–235. Google Scholar
Digital Library
- Ningnign Xie and Richard A Eisenberg. 2018. Coercion Quantification. In Haskell Implementors’ Workshop.Google Scholar
- Brent A. Yorgey, Stephanie Weirich, Julien Cretin, Simon Peyton Jones, Dimitrios Vytiniotis, and José Pedro Magalhães. 2012. Giving Haskell a Promotion. In Proceedings of the 8th ACM SIGPLAN Workshop on Types in Language Design and Implementation (TLDI ’12). ACM, New York, NY, USA, 53–66. Google Scholar
Digital Library
- Beta Ziliani and Matthieu Sozeau. 2015. A Unification Algorithm for Coq Featuring Universe Polymorphism and Overloading. In Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming (ICFP 2015). ACM, New York, NY, USA, 179–191. Google Scholar
Digital Library
Index Terms
Kind inference for datatypes
Recommendations
System FC with explicit kind equality
ICFP '13System FC, the core language of the Glasgow Haskell Compiler, is an explicitly-typed variant of System F with first-class type equality proofs called coercions. This extensible proof system forms the foundation for type system extensions such as type ...
System FC with explicit kind equality
ICFP '13: Proceedings of the 18th ACM SIGPLAN international conference on Functional programmingSystem FC, the core language of the Glasgow Haskell Compiler, is an explicitly-typed variant of System F with first-class type equality proofs called coercions. This extensible proof system forms the foundation for type system extensions such as type ...
Depending on types
ICFP '14Is Haskell a dependently typed programming language? Should it be? GHC's many type-system features, such as Generalized Algebraic Datatypes (GADTs), datatype promotion, multiparameter type classes, and type families, give programmers the ability to ...






Comments