Skip to main content Accessibility help
×
Home
Hostname: page-component-684899dbb8-4btjb Total loading time: 0.375 Render date: 2022-05-25T07:07:26.412Z Has data issue: true Feature Flags: { "shouldUseShareProductTool": true, "shouldUseHypothesis": true, "isUnsiloEnabled": true, "useRatesEcommerce": false, "useNewApi": true }

Practical type inference for arbitrary-rank types

Published online by Cambridge University Press:  01 January 2007

SIMON PEYTON JONES
Affiliation:
Microsoft Research
DIMITRIOS VYTINIOTIS
Affiliation:
University of Pennsylvania
STEPHANIE WEIRICH
Affiliation:
University of Pennsylvania
MARK SHIELDS
Affiliation:
Microsoft Research
Rights & Permissions[Opens in a new window]

Abstract

HTML view is not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

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.

Type
Article
Copyright
Copyright © Cambridge University Press 2006

References

Baars, Arthur L, & Swierstra, S. Doaitse. (2002). Typing dynamic typing. Pages 157166 of: ACM SIGPLAN International Conference on Functional Programming (ICFP'02). Pittsburgh: ACM.CrossRefGoogle Scholar
Bird, Richard, & Paterson, Ross. (1999). De Bruijn notation as a nested datatype. Journal of Functional Programming, 9 (1), 7791.CrossRefGoogle Scholar
Cardelli, L. (1987). Basic polymorphic typechecking. Science of Computer Programming, 8 (2), 147172.CrossRefGoogle Scholar
Clement, D, Despeyroux, J, Despeyroux, T, & Kahn, G. (1986). A simple applicative language: Mini-ML. Pages 1327 of: ACM Symposium on Lisp and Functional Programming. ACM.Google Scholar
Damas, Luis, & Milner, Robin. (1982). Principal type-schemes for functional programs. Pages 207–12 of: Conference record of the 9th annual acm symposium on principles of programming languages. New York: ACM Press.Google Scholar
Garrigue, Jacques, & Remy, Didier. (1999). Semi-explicit first-class polymorphism for ML. Journal of information and computation, 155, 134169.CrossRefGoogle Scholar
Gill, A, Launchbury, J, & Peyton Jones, SL. (1993). A short cut to deforestation. Pages 223232 of: ACM Conference on Functional Programming and Computer Architecture (FPCA'93). Cophenhagen: ACM Press. ISBN 0-89791-595-X.Google Scholar
Girard, J-Y. (1990). The system F of variable types: fifteen years later. Huet, G (ed), Logical foundations of functional programming. Addison-Wesley.Google Scholar
Hancock, P. (1987). A type checker. Pages 163182 of: Peyton Jones, SL (ed), The implementation of functional programming languages. Prentice Hall.Google Scholar
Heeren, B, Hage, J, & Swierstra, SD. (2003). Scripting the type inference process. In: CFP03, 2003.Google Scholar
Hinze, Ralf. (2000). A new approach to generic functional programming. Pages 119132 of: 27th ACM Symposium on Principles of Programming Languages (POPL'00). Boston: ACM.CrossRefGoogle Scholar
Hinze, Ralf. (2001). Manufacturing datatypes. Journal of Functional Programming, 1.Google Scholar
Huet, G. (2002). Higher order unification 30 years later. 15th international workshop on higher order logic theorem proving and its applications (IWHOLTP'02). LNCS.CrossRefGoogle Scholar
ICFP03. (2003). ACM SIGPLAN International Conference on Functional Programming (ICFP'03). Uppsala, Sweden: ACM.Google Scholar
ICFP05. (2005). ACM SIGPLAN International Conference on Functional Programming (ICFP'05). Tallinn, Estonia: ACM.Google Scholar
Jones, Mark. (1999). Typing Haskell in Haskell. Meijer, Erik (ed), Proceedings of the 1999 haskell workshop. Technical Reports, nos. UU–CS–1999–28. Available at ftp://ftp.cs.uu.nl/pub/RUU/CS/techreps/CS-1999/1999-28.pdf.Google Scholar
Kfoury, AJ, & Tiuryn, J. (1992). Type reconstruction in finite rank fragments of second-order lambda calculus. Information and Computation, 98 (2), 228257.CrossRefGoogle Scholar
Kfoury, AJ, & Wells, JB. (1994). A direct algorithm for type inference in the rank-2 fragment of the second-order lambda calculus. Pages 196207 of: ACM Symposium on Lisp and Functional Programming. Orlando, Florida: ACM.Google Scholar
Lämmel, Ralf, & Peyton Jones, Simon. (2003). Scrap your boilerplate: a practical approach to generic programming. Pages 2637 of: ACM SIGPLAN International Workshop on Types in Language Design and Implementation (TLDI'03). New Orleans: ACM Press.Google Scholar
Launchbury, J, & Peyton Jones, SL. (1995). State in Haskell. Lisp and Symbolic Computation, 8 (4), 293342.CrossRefGoogle Scholar
Le Botlan, D, & émy, D. (2003). MLF: raising ML to the power of System F. In: ICFP03, 2003.Google Scholar
Lee, Oukseh, & Yi, Kwangkeun. (1998). Proofs about a folklore let-polymorphic type inference algorithm. ACM Transactions on Programming Languages and Systems, 20 (4), 707723.CrossRefGoogle Scholar
Leijen, Daan, & Löh, Andres. (2005). Qualified types for MLF. In: ICFP05, 2005.Google Scholar
Longo, Giuseppe, Milsted, Kathleen, & Soloviev, Sergei. (1995). A logic of subtyping (extended abstract). Pages 292–299 of: |lics95|.Google Scholar
Miller, Dale. (1992). Unification under a mixed prefix. J. symb. comput., 14 (4), 321358.CrossRefGoogle Scholar
Milner, R. (1978). A theory of type polymorphism in programming. Jcss, 13 (3).Google Scholar
Mitchell, John C. (1988). Polymorphic type inference and containment. Inf. comput., 76 (2–3), 211249.CrossRefGoogle Scholar
Morrisett, G. 1995 (Dec.). Compiling with types. Ph.D. thesis, Carnegie Mellon University.Google Scholar
Odersky, M, & Läufer, K. (1996). Putting type annotations to work. Pages 5467 of: 23rd ACM Symposium on Principles of Programming Languages (POPL'96). St Petersburg Beach, Florida: ACM.CrossRefGoogle Scholar
Odersky, Martin, Zenger, Matthias, & Zenger, Christoph. (2001). Colored local type inference. 28th ACM Symposium on Principles of Programming Languages (POPL'01). London: ACM.CrossRefGoogle Scholar
Okasaki, C. (1999). From fast exponentiation to square matrices: an adventure in types. Pages 2835 of: ACM SIGPLAN International Conference on Functional Programming (ICFP'99). Paris: ACM.CrossRefGoogle Scholar
Peyton Jones, Simon. (2001). Tackling the awkward squad: monadic input/output, concurrency, exceptions, and foreign-language calls in Haskell. Pages 4796 of: Hoare, CAR, Broy, M, & Steinbrueggen, R (eds), Engineering theories of software construction, Marktoberdorf Summer School 2000. NATO ASI Series. IOS Press.Google Scholar
Peyton Jones, SL, & Santos, A. (1998). A transformation-based optimiser for Haskell. Science of Computer Programming, 32 (1–3), 347.CrossRefGoogle Scholar
Pierce, Benjamin. (2002). Types and programming languages. MIT Press.Google Scholar
Pierce, Benjamin C., & Turner, David N. (1998). Local type inference. Pages 252265 of: 25th ACM Symposium on Principles of Programming Languages (POPL'98). San Diego: ACM.CrossRefGoogle Scholar
Pottier, F, & Rémy, D. (2004). ML. Pierce, BC (ed), Advanced topics in types and programming languages. MIT Press.Google Scholar
Rémy, Didier. (2005). Simple, partial type inference for System F, based on type containment. In: ICFP05, 2005.Google Scholar
Shao, Zhong. 1997 (June). An overview of the FLINT/ML compiler. Proc. 1997 ACM SIGPLAN workshop on types in compilation (TIC'97).Google Scholar
Shields, Mark, & Peyton Jones, Simon. (2002). Lexically scoped type variables. Microsoft Research.Google Scholar
Tarditi, D, Morrisett, G, Cheng, P, Stone, C, Harper, R, & Lee, P. (1996). TIL: A type-directed optimizing compiler for ML. Pages 181192 of: ACM Conference on Programming Languages Design and Implementation (PLDI'96). Philadelphia: ACM.Google Scholar
Tiuryn, J, & Urzyczyn, P. (1996). The subtyping problem for second order types is undecidable. Proc. IEEE Symposium on Logic in Computer Science (LICS'96).Google Scholar
Tiuryn, Jerzy. (2001). A sequent calculus for subtyping polymorphic types. Inf. comput., 164 (2), 345369.CrossRefGoogle Scholar
Vytiniotis, Dimitrios, Weirich, Stephanie, & Peyton Jones, Simon. 2005 (July). Practical type inference for arbitrary-rank types, Technical Appendix. Tech. rept. MS-CIS-05-14. University of Pennsylvania.Google Scholar
Wells, JB. (1999). Typability and type checking in system F are equivalent and undecidable. Ann. Pure Appl. Logic, 98, 111156.CrossRefGoogle Scholar
Submit a response

Discussions

No Discussions have been published for this article.
You have Access
89
Cited by

Save article to Kindle

To save this article to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

Practical type inference for arbitrary-rank types
Available formats
×

Save article to Dropbox

To save this article to your Dropbox account, please select one or more formats and confirm that you agree to abide by our usage policies. If this is the first time you used this feature, you will be asked to authorise Cambridge Core to connect with your Dropbox account. Find out more about saving content to Dropbox.

Practical type inference for arbitrary-rank types
Available formats
×

Save article to Google Drive

To save this article to your Google Drive account, please select one or more formats and confirm that you agree to abide by our usage policies. If this is the first time you used this feature, you will be asked to authorise Cambridge Core to connect with your Google Drive account. Find out more about saving content to Google Drive.

Practical type inference for arbitrary-rank types
Available formats
×
×

Reply to: Submit a response

Please enter your response.

Your details

Please enter a valid email address.

Conflicting interests

Do you have any conflicting interests? *