Explaining Type Inference

Type inference is the compile-time process of reconstructing missing type information in a program based on the usage of its variables. ML and Haskell are two languages where this aspect of compilation has enjoyed some popularity, allowing type information to be omitted while static type checking is still performed. Type inference may be expected to have some application in the prototyping and scripting languages which are becoming increasingly popular. A difficulty with type inference is the confusing and sometimes counter-intuitive diagnostics produced by the type checker as a result of type errors. A modification of the unification algorithm used in Hindley-Milner type inference is presented, which allows the specific reasoning which led to a program variable having a particular type to be recorded for type explanation. This approach is close to the intuitive process used in practice for debugging type errors. The algorithm is practical, and has been implemented in the Standard ML of New Jersey compiler. The modified unification algorithm also appears useful in other domains, including logic program debuggers and semantics-based programming environments.

[1]  Alberto Martelli,et al.  An Efficient Unification Algorithm , 1982, TOPL.

[2]  Tobias Nipkow,et al.  Type checking type classes , 1993, POPL '93.

[3]  Dennis de Champeaux,et al.  About the Paterson-Wegman Linear Unification Algorithm , 1986, J. Comput. Syst. Sci..

[4]  Michel Bidoit,et al.  A Rehabilitation of Robinson's Unification Algorithm , 1983, IFIP Congress.

[5]  John W. Lloyd,et al.  The Gödel programming language , 1994 .

[6]  Luca Cardelli,et al.  Basic Polymorphic Typechecking , 1987, Sci. Comput. Program..

[7]  Simon L. Peyton Jones,et al.  Report on the programming language Haskell: a non-strict, purely functional language version 1.2 , 1992, SIGP.

[8]  Gilles Kahn,et al.  Natural Semantics , 1987, STACS.

[9]  Lewis Denver Baxter The complexity of unification. , 1976 .

[10]  Robert E. Tarjan,et al.  Depth-First Search and Linear Graph Algorithms , 1972, SIAM J. Comput..

[11]  T. Nipkom Functional unification of higher-order patterns , 1993, LICS 1993.

[12]  Frank Pfenning,et al.  Partial polymorphic type inference and higher-order unification , 1988, LISP and Functional Programming.

[13]  Paola Giannini,et al.  Type checking and type deduction techniques for polymorphic programming languages , 1985 .

[14]  Rishiyur S. Nikhil,et al.  Practical Polymorphism , 1985, FPCA.

[15]  Gregor Snelting,et al.  The PSG system: from formal language definitions to interactive programming environments , 1986, TOPL.

[16]  Kevin Hammond Efficient Type Inference Using Monads (Summary) , 1991, Functional Programming.

[17]  G. vanRossum,et al.  Interactively testing remote servers using the Python programming language , 1991 .

[18]  Mitchell Wand Finding the source of type errors , 1986, POPL '86.

[19]  Andrew W. Appel,et al.  Standard ML of New Jersey , 1991, PLILP.

[20]  D. A. Turner,et al.  Miranda: A Non-Strict Functional language with Polymorphic Types , 1985, FPCA.

[21]  Robert E. Tarjan,et al.  Efficiency of a Good But Not Linear Set Union Algorithm , 1972, JACM.

[22]  John K. Ousterhout,et al.  Tcl: An Embeddable Command Language , 1989, USENIX Winter.

[23]  Hassan Aït-Kaci Warren's Abstract Machine , 1991, ICLP.

[24]  Simon L. Peyton Jones,et al.  Imperative functional programming , 1993, POPL '93.

[25]  Gregory F. Johnson,et al.  A maximum-flow approach to anomaly isolation in unification-based incremental type inference , 1986, POPL '86.

[26]  Frank Pfenning,et al.  Types in Logic Programming , 1992, ICLP.

[27]  Patrick Borras,et al.  Centaur: the system , 1988, Software Development Environments.

[28]  Jacques Herbrand Recherches sur la théorie de la démonstration , 1930 .

[29]  Peter Lee,et al.  Topics in advanced language implementation , 1991 .

[30]  Alfred V. Aho,et al.  Compilers: Principles, Techniques, and Tools , 1986, Addison-Wesley series in computer science / World student series edition.

[31]  Dale Miller,et al.  A Logic Programming Language with Lambda-Abstraction, Function Variables, and Simple Unification , 1991, J. Log. Comput..

[32]  J. A. Robinson,et al.  A Machine-Oriented Logic Based on the Resolution Principle , 1965, JACM.

[33]  Zhenyu Qian,et al.  Linear Unification of Higher-Order Patterns , 1993, TAPSOFT.

[34]  Frank Pfenning,et al.  A Semi-Functional Implementation of a Higher-Order Logic Programming Language , 1990 .

[35]  Tobias Nipkow,et al.  Type Classes and Overloading Resolution via Order-Sorted Unification , 1991, FPCA.

[36]  Mike Paterson,et al.  Linear Unification , 1978, J. Comput. Syst. Sci..

[37]  Janet Walz Extending attribute grammar and type inference algorithms , 1989 .

[38]  Alberto Martelli,et al.  Unification in linear time and space: a structured presentation , 1976 .

[39]  Kevin Knight,et al.  Unification: a multidisciplinary survey , 1989, CSUR.

[40]  Robin Milner,et al.  Definition of standard ML , 1990 .

[41]  Gopalan Nadathur,et al.  Types in Higher-Order Logic Programming , 1992 .

[42]  Philip Wadler,et al.  The Glasgow Haskell Compiler: a technical overview , 1993 .

[43]  Patrick M. Sansom Time Profiling a Lazy Functional Compiler , 1993, Functional Programming.

[44]  Hans-Juergen Boehm Type inference in the presence of type abstraction , 1989, PLDI '89.