skip to main content
research-article
Open Access

Kind inference for datatypes

Published:20 December 2019Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

a53-xie.webm

References

  1. 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
  2. P. B. Andrews. 1971. Resolution in type Theory. Journal of Symbolic Logic 36 (1971), 414–432.Google ScholarGoogle ScholarCross RefCross Ref
  3. 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 ScholarGoogle Scholar
  4. 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 ScholarGoogle Scholar
  5. L. Cardelli. 1986. A polymorphic lambda-calculus with Type:Type. Technical Report 10. SRC.Google ScholarGoogle Scholar
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. Claudio Sacerdoti Coen. 2004. Mathematical knowledge management and interactive theorem proving. Ph.D. Dissertation. University of Bologna, 2004. Technical Report UBLCS 2004-5.Google ScholarGoogle Scholar
  9. 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 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). ACM, New York, NY, USA, 207–212. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. Richard A Eisenberg. 2016. Dependent types in haskell: Theory and practice. Ph.D. Dissertation. University of Pennsylvania.Google ScholarGoogle Scholar
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. Richard A Eisenberg, Stephanie Weirich, and Hamidhasan G Ahmed. 2016. Visible type application. In European Symposium on Programming. Springer, 229–254.Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. Warren D Goldfarb. 1981. The undecidability of the second-order unification problem. Theoretical Computer Science 13, 2 (1981), 225–230.Google ScholarGoogle Scholar
  18. 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 ScholarGoogle ScholarCross RefCross Ref
  19. 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 ScholarGoogle ScholarCross RefCross Ref
  20. Adam Gundry and Conor McBride. 2013. A tutorial implementation of dynamic pattern unification. Unpublished draft (2013).Google ScholarGoogle Scholar
  21. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  22. Adam Michael Gundry. 2013. Type inference, Haskell and dependent types. Ph.D. Dissertation. University of Strathclyde.Google ScholarGoogle Scholar
  23. Fritz Henglein. 1993. Type inference with polymorphic recursion. ACM Trans. Program. Lang. Syst. 15, 2 (April 1993), 253–289. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. J. Roger Hindley. 1969. The principal type-scheme of an object in combinatory logic. Trans. Amer. Math. Soc. 146 (1969), 29–60.Google ScholarGoogle Scholar
  25. G. Huet. 1973. A unification algorithm for typed lambda calculus. Theoretical Computer Science 1, 1 (1973), 27–57.Google ScholarGoogle ScholarCross RefCross Ref
  26. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  27. 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 ScholarGoogle ScholarCross RefCross Ref
  28. 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 ScholarGoogle Scholar
  29. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  30. Didier Le Botlan and Didier Rémy. 2003. MLF: Raising ML to the Power of System F (ICFP ’03). 12.Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  32. Dale Miller. 1991. Unification of simply typed lambda-terms as logic programming. (1991).Google ScholarGoogle Scholar
  33. Alan Mycroft. 1984. Polymorphic type schemes and recursive definitions. In International Symposium on Programming. Springer, 217–228.Google ScholarGoogle ScholarCross RefCross Ref
  34. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  35. Simon Peyton Jones. 2003. Haskell 98 language and libraries: the revised report. Cambridge University Press.Google ScholarGoogle Scholar
  36. 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
  37. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  38. François Pottier and Didier Rémy. 2005. The essence of ML type inference. Advanced Topics in Types and Programming Languages (2005).Google ScholarGoogle Scholar
  39. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  40. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  41. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  42. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  43. 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
  44. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  45. Dimitrios Vytiniotis, Stephanie Weirich, and Simon Peyton Jones. 2008. FPH: First-class polymorphism for Haskell (ICFP ’08). 12.Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  47. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  48. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  49. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  50. Ningnign Xie and Richard A Eisenberg. 2018. Coercion Quantification. In Haskell Implementors’ Workshop.Google ScholarGoogle Scholar
  51. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  52. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Kind inference for datatypes

          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

          • Published in

            cover image Proceedings of the ACM on Programming Languages
            Proceedings of the ACM on Programming Languages  Volume 4, Issue POPL
            January 2020
            1984 pages
            EISSN:2475-1421
            DOI:10.1145/3377388
            Issue’s Table of Contents

            Copyright © 2019 Owner/Author

            Publisher

            Association for Computing Machinery

            New York, NY, United States

            Publication History

            • Published: 20 December 2019
            Published in pacmpl Volume 4, Issue POPL

            Permissions

            Request permissions about this article.

            Request Permissions

            Check for updates

            Qualifiers

            • research-article

          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!