Efficient type inference using ranked type variables

  • Authors:
  • George Kuan;David MacQueen

  • Affiliations:
  • University of Chicago, Chicago, IL;University of Chicago, Chicago, IL

  • Venue:
  • ML '07 Proceedings of the 2007 workshop on Workshop on ML
  • Year:
  • 2007

Quantified Score

Hi-index 0.00

Visualization

Abstract

The Damas-Milner type inference algorithm (commonly known as algorithm W) is at the core of all ML type checkers. Although the algorithm is known to have poor worst-case behavior [8], in practice well-engineered type checkers will run in approximately linear time. To achieve this efficiency, implementations need to improve on algorithm W's method of scanning the complete type environment to determine whether a type variable can be generalized at a let binding. Following a suggestion of Damas, most ML type checkers use an alternative method based on ranking unification variables to track their position in the type environment. Here we formalize two such ranking systems, one based on lambda depth (used in the SML/NJ compiler), and the other based on let depth (used in OCaml, for instance). Each of these systems is formalized both with and without the value restriction, and they are proved correct relative to the classic algorithm W. Our formalizations of the various algorithms use simple abstract machines that are similar to small-step evaluation semantics.