Practical type inference for arbitrary-rank types
Top Cited Papers
- 1 January 2007
- journal article
- research article
- Published by Cambridge University Press (CUP) in Journal of Functional Programming
- Vol. 17 (1) , 1-82
- https://doi.org/10.1017/s0956796806006034
Abstract
Haskell's popularity has driven the need for ever more expressive type system features, most of which threaten the decidability and practicality of Damas-Milner type inference. One such feature is the ability to write functions with higher-rank types – that is, functions that take polymorphic functions as their arguments. Complete type inference is known to be undecidable for higher-rank (impredicative) type systems, but in practice programmers are more than willing to add type annotations to guide the type inference engine, and to document their code. However, the choice of just what annotations are required, and what changes are required in the type system and its inference algorithm, has been an ongoing topic of research. We take as our starting point a λ-calculus proposed by Odersky and Läufer. Their system supports arbitrary-rank polymorphism through the exploitation of type annotations on λ-bound arguments and arbitrary sub-terms. Though elegant, and more convenient than some other proposals, Odersky and Läufer's system requires many annotations. We show how to use local type inference (invented by Pierce and Turner) to greatly reduce the annotation burden, to the point where higher-rank types become eminently usable. Higher-rank types have a very modest impact on type inference. We substantiate this claim in a very concrete way, by presenting a complete type-inference engine, written in Haskell, for a traditional Damas-Milner type system, and then showing how to extend it for higher-rank types. We write the type-inference engine using a monadic framework: it turns out to be a particularly compelling example of monads in action. The paper is long, but is strongly tutorial in style. Although we use Haskell as our example source language, and our implementation language, much of our work is directly applicable to any ML-like functional language.Keywords
This publication has 22 references indexed in Scilit:
- Scripting the type inference processPublished by Association for Computing Machinery (ACM) ,2003
- The subtyping problem for second-order types is undecidablePublished by Institute of Electrical and Electronics Engineers (IEEE) ,2002
- Typing dynamic typingPublished by Association for Computing Machinery (ACM) ,2002
- Higher Order Unification 30 Years LaterPublished by Springer Nature ,2002
- Colored local type inferencePublished by Association for Computing Machinery (ACM) ,2001
- A new approach to generic functional programmingPublished by Association for Computing Machinery (ACM) ,2000
- Semi-Explicit First-Class Polymorphism for MLInformation and Computation, 1999
- de Bruijn notation as a nested datatypeJournal of Functional Programming, 1999
- Unification under a mixed prefixJournal of Symbolic Computation, 1992
- Type reconstruction in finite rank fragments of the second-order λ-calculusInformation and Computation, 1992