skip to main content
research-article
Open Access

Constraint-based type inference for FreezeML

Published:31 August 2022Publication History
Skip Abstract Section

Abstract

FreezeML is a new approach to first-class polymorphic type inference that employs term annotations to control when and how polymorphic types are instantiated and generalised. It conservatively extends Hindley-Milner type inference and was first presented as an extension to Algorithm W. More modern type inference techniques such as HM(X) and OutsideIn(X) employ constraints to support features such as type classes, type families, rows, and other extensions. We take the first step towards modernising FreezeML by presenting a constraint-based type inference algorithm. We introduce a new constraint language, inspired by the Pottier/Rémy presentation of HM(X), in order to allow FreezeML type inference problems to be expressed as constraints. We present a deterministic stack machine for solving FreezeML constraints and prove its termination and correctness.

References

  1. Luís Damas and Robin Milner. 1982. Principal Type-Schemes for Functional Programs. In POPL. ACM Press, 207–212. https://doi.org/10.1145/582153.582176 Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Frank Emrich, Sam Lindley, Jan Stolarek, James Cheney, and Jonathan Coates. 2020. FreezeML: Complete and Easy Type Inference for First-class Polymorphism. In PLDI. ACM, 423–437. Extended version available at https://doi.org/10.48550/arXiv.2004.00396 Google ScholarGoogle Scholar
  3. Frank Emrich, Jan Stolarek, James Cheney, and Sam Lindley. 2022. Constraint-based type inference for FreezeML (extended version). https://doi.org/10.48550/arXiv.2207.09914 arXiv:2207.09914 Google ScholarGoogle Scholar
  4. Jacques Garrigue and Didier Rémy. 1999. Semi-Explicit First-Class Polymorphism for ML. Inf. Comput., 155, 1-2 (1999), 134–169. https://doi.org/10.1006/inco.1999.2830 Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Adam Gundry. 2015. A typechecker plugin for units of measure: domain-specific constraint solving in GHC Haskell. In Proceedings of the 8th ACM SIGPLAN Symposium on Haskell, Haskell 2015, Vancouver, BC, Canada, September 3-4, 2015, Ben Lippmeier (Ed.). ACM, 11–22. https://doi.org/10.1145/2804302.2804305 Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Adam Gundry, Conor McBride, and James McKinna. 2010. Type Inference in Context. In [email protected]. ACM, 43–54. https://doi.org/10.1006/inco.1999.2830 Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Mark P. Jones. 1994. A Theory of Qualified Types. Sci. Comput. Program., 22, 3 (1994), 231–256. https://doi.org/10.1016/0167-6423(94)00005-0 Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Andrew Kennedy. 2009. Types for Units-of-Measure: Theory and Practice. In CEFP (Lecture Notes in Computer Science, Vol. 6299). Springer, 268–305. https://doi.org/10.1007/978-3-642-17685-2_8 Google ScholarGoogle ScholarCross RefCross Ref
  9. George Kuan and David MacQueen. 2007. Efficient type inference using ranked type variables. In ML. ACM, 3–14. https://doi.org/10.1145/1292535.1292538 Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Didier Le Botlan and Didier Rémy. 2003. ML^ F: raising ML to the power of System F. In ICFP. ACM, 27–38. https://doi.org/10.1145/944705.944709 Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Daan Leijen. 2008. HMF: simple type inference for first-class polymorphism. In ICFP. ACM, 283–294. https://doi.org/10.1145/1411204.1411245 Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Daan Leijen. 2014. Koka: Programming with Row Polymorphic Effect Types. In MSFP (EPTCS, Vol. 153). 100–126. https://doi.org/10.4204/EPTCS.153.8 Google ScholarGoogle ScholarCross RefCross Ref
  13. Xavier Leroy and Michel Mauny. 1993. Dynamics in ML. J. Funct. Program., 3, 4 (1993), 431–463. https://doi.org/10.1017/S0956796800000848 Google ScholarGoogle ScholarCross RefCross Ref
  14. Sam Lindley and James Cheney. 2012. Row-based effect types for database integration. In TLDI. ACM, 91–102. https://doi.org/10.1145/2103786.2103798 Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. J. Garrett Morris and James McKinna. 2019. Abstracting extensible data types: or, rows by any other name. Proc. ACM Program. Lang., 3, POPL (2019), 12:1–12:28. https://doi.org/10.1145/3290325 Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Martin Odersky, Martin Sulzmann, and Martin Wehr. 1999. Type Inference with Constrained Types. Theory Pract. Object Syst., 5, 1 (1999), 35–55. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Frank Pfenning. 1993. On the Undecidability of Partial Polymorphic Type Reconstruction. Fundam. Inform., 19, 1/2 (1993), 185–199. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. François Pottier. 2014. Hindley-Milner Elaboration in Applicative Style: Functional Pearl. In ICFP. ACM, 203–212. https://doi.org/10.1145/2628136.2628145 Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. François Pottier and Didier Rémy. 2005. The Essence of ML Type Inference. MIT Press, 389–489. Google ScholarGoogle Scholar
  20. Didier Rémy. 1992. Extension of ML Type System with a Sorted Equational Theory on Types. Institut National de Recherche en Informatique et en Automatique. Google ScholarGoogle Scholar
  21. Claudio V. Russo and Dimitrios Vytiniotis. 2009. QML: Explicit First-class Polymorphism for ML. In ML. ACM, 3–14. Google ScholarGoogle Scholar
  22. Alejandro Serrano, Jurriaan Hage, Simon Peyton Jones, and Dimitrios Vytiniotis. 2020. A quick look at impredicativity. Proc. ACM Program. Lang., 4, ICFP (2020), 89:1–89:29. https://doi.org/10.1145/3408971 Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Alejandro Serrano, Jurriaan Hage, Dimitrios Vytiniotis, and Simon Peyton Jones. 2018. Guarded impredicative polymorphism. In PLDI. ACM, 783–796. https://doi.org/10.1145/3192366.3192389 Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Vincent Simonet and François Pottier. 2007. A constraint-based approach to guarded algebraic data types. ACM Trans. Program. Lang. Syst., 29, 1 (2007), 1. https://doi.org/10.1145/1180475.1180476 Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Dimitrios Vytiniotis, Simon L. Peyton Jones, Tom Schrijvers, and Martin Sulzmann. 2011. OutsideIn(X): Modular type inference with local assumptions. J. Funct. Program., 21, 4-5 (2011), 333–412. https://doi.org/10.1017/S0956796811000098 Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Dimitrios Vytiniotis, Stephanie Weirich, and Simon L. Peyton Jones. 2006. Boxy types: inference for higher-rank types and impredicativity. In ICFP. ACM, 251–262. https://doi.org/10.1145/1159803.1159838 Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Mitchell Wand. 1987. A simple algorithm and proof for type inference. Fundamenta Informaticae. Google ScholarGoogle Scholar
  28. J. B. Wells. 1994. Typability and Type-Checking in the Second-Order lambda-Calculus are Equivalent and Undecidable. In LICS. IEEE Computer Society, 176–185. https://doi.org/10.1109/LICS.1994.316068 Google ScholarGoogle ScholarCross RefCross Ref
  29. Andrew K. Wright. 1995. Simple Imperative Polymorphism. LISP Symb. Comput., 8, 4 (1995), 343–355. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Constraint-based type inference for FreezeML

      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

      • Article Metrics

        • Downloads (Last 12 months)159
        • Downloads (Last 6 weeks)17

        Other Metrics

      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!