## Explaining Type Inference (1995)

Venue: | Science of Computer Programming |

Citations: | 53 - 0 self |

### BibTeX

@INPROCEEDINGS{Duggan95explainingtype,

author = {Dominic Duggan and Frederick Bent},

title = {Explaining Type Inference},

booktitle = {Science of Computer Programming},

year = {1995},

pages = {37--83}

}

### Years of Citing Articles

### OpenURL

### Abstract

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 Hindley-Milner type inference algorithm 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. 1 Introduction Type inference refers to the compile-time process of reconstructing missing t...

### Citations

1562 | The Definition of Standard ML
- Miller, Tofte, et al.
- 1990
(Show Context)
Citation Context ...nteger, so we may conclude that the type of the above expression is int ! int (where ! is the procedure or function type). ML and Haskell are two popular languages currently supporting type inference =-=[30, 21]-=-. Since these languages do not require the types of variables to be declared, they are said to be implicitly typed languages. In the example above, we consider the original implicitly typed expression... |

992 | Depth first search and linear graph algorithms
- Tarjan
- 1972
(Show Context)
Citation Context ... of the algorithm is that the occurs check is postponed until the end of the algorithm; the occurs check is then the standard linear-time depthfirst -search-based acyclicity check for directed graphs =-=[48]-=-. The Baxter/Huet algorithm thus is O(n \Delta G(n)), which means that for all practical purposes it is linear. Furthermore, as can be seen by comparing App. A and App. D, it is similar enough in some... |

945 |
A machine-oriented logic based on the resolution principle
- Robinson
- 1965
(Show Context)
Citation Context ...which are imposed by the use of the program variables, and using unification to resolve these constraints and compute most general unifiers. Figure 3 gives the standard Robinson unification algorithm =-=[44]-=-. Once the definition in a let-expression has been type checked, any remaining type variables which are not constrained by the program variables in the environment are generalized to generic type vari... |

332 | An efficient unification algorithm
- Martelli, Montanari
- 1982
(Show Context)
Citation Context ...basis for the algorithm developed in this paper, as well as all of the asymptotically superior algorithms discussed in the next section. This includes Martelli and Montanari's almost-linear algorithm =-=[28]-=-. Although their algorithm manipulates multisets of multiequations, the heart of the algorithm is ordering the processing of multiequations in such a way that substitutions are not applied. So their m... |

302 | Natural semantics
- Kahn
- 1987
(Show Context)
Citation Context ...i [28] Finally, unification is also used in several other tools besides type checkers. The Centaur programming environment [9] compiles specifications of language semantics in natural semantics style =-=[25]-=- into Prolog programs. Since, as noted, Prolog compilation is based on compiling naive graph unification into abstract machine code, our approach is immediately applicable to providing debugging suppo... |

287 | A logic programming language with lambda-abstraction, function variables, and simple unification
- Miller
- 1991
(Show Context)
Citation Context ...e code [2]. It might also be useful to consider extending this approach to explaining unification to higher-order unification algorithms. A practical example would be extending it to b 0 -unification =-=[29]-=-. Qian [43] has described a linear-time algorithm for b 0 -unification, based on the unpublished linear-time first-order unification algorithm due to Martelli and Montanari [27]. Although an efficient... |

255 |
The Gödel Programming Language
- Hill, Lloyd
- 1994
(Show Context)
Citation Context ...ove away from implicit typing in certain circles of the ML community, it is still popular in the community as a whole and in other language communities such as Miranda 2 , Haskell, l-Prolog and Godel =-=[51, 21, 31, 20]-=-. Moreover we may expect implicit typing to play an increasingly important role in scripting languages such as TCL and Python [38, 52], where currently the demands of rapid prototyping and fast develo... |

254 |
Efficiency of a good but not linear set union algorithm
- Tarjan
(Show Context)
Citation Context ...on the description given by Knight [26]. The algorithm is based on a well-known method for checking the equivalence of finite-state automata, using the UNION-FIND algorithm to merge equivalent states =-=[49]-=-. In this case states correspond to vertices in the type graph, while state transitions correspond to descendant edges [13] between parent and child vertices. Recursion is triggered in the case where ... |

225 | Report on programming language Haskel a non-strict, purely functional language version 1.2
- Hudak, Jones, et al.
- 1992
(Show Context)
Citation Context ...nteger, so we may conclude that the type of the above expression is int ! int (where ! is the procedure or function type). ML and Haskell are two popular languages currently supporting type inference =-=[30, 21]-=-. Since these languages do not require the types of variables to be declared, they are said to be implicitly typed languages. In the example above, we consider the original implicitly typed expression... |

200 | Tcl: An Embeddable Command Language
- Ousterhout
(Show Context)
Citation Context ...mmunities such as Miranda 2 , Haskell, l-Prolog and Godel [51, 21, 31, 20]. Moreover we may expect implicit typing to play an increasingly important role in scripting languages such as TCL and Python =-=[38, 52], where cu-=-rrently the demands of rapid prototyping and fast development of "throw-away" programs have been used to justify the absence of static typing. (Although these languages were intended for wri... |

195 | Standard ml of new jersey
- Appel, MacQueen
- 1991
(Show Context)
Citation Context ...les of deep polymorphic aliasing; these examples are useful in understanding the formal justification provided in the next section. Figure 17(a) illustrates that the explanation 'B0 'B0 'B1 'B1 F [H] =-=[3]-=- F [H] [3] (G x) G x F [H] [3] (G x) 'A0 'B2 'B2 list list list list 'B3 G [I] (a) F [H] [3] (G x) (b) F [[H]] [G [I]] F [[H]] F [[H]] [G [I]] Assume F:'B0->'B0->'B0 ->'B0, G:'B1 ->'B1, H:'B2, I:'B3, ... |

160 |
A non-strict functional language with polymorphic types
- Miranda
- 1985
(Show Context)
Citation Context ...ove away from implicit typing in certain circles of the ML community, it is still popular in the community as a whole and in other language communities such as Miranda 2 , Haskell, l-Prolog and Godel =-=[51, 21, 31, 20]-=-. Moreover we may expect implicit typing to play an increasingly important role in scripting languages such as TCL and Python [38, 52], where currently the demands of rapid prototyping and fast develo... |

147 |
Linear Unification
- Paterson, Wegman
- 1978
(Show Context)
Citation Context ...t instantiation is consistent with the explanation at exactly one of these points. This generalization of the notion of type explanation is applicable for example to the algorithms of Paterson-Wegman =-=[39]-=- and Martelli-Montanari [28] discussed in the next section, which improve the asymptotic performance of unification by a suitable reordering of the equations as they are being solved. The corresponden... |

136 | CENTAUR: The System
- Borras, Clement, et al.
- 1988
(Show Context)
Citation Context ...more practical almost-linear-time algorithm provided by Martelli and Montanari [28] Finally, unification is also used in several other tools besides type checkers. The Centaur programming environment =-=[9]-=- compiles specifications of language semantics in natural semantics style [25] into Prolog programs. Since, as noted, Prolog compilation is based on compiling naive graph unification into abstract mac... |

120 | The Glasgow Haskell compiler: A technical overview
- Jones, Hall, et al.
- 1993
(Show Context)
Citation Context ...n applicative and destructive substitutions is not one to be taken casually. Sansom [45] provides some data on the use of applicative substitutions, based on profiling of the Glasgow Haskell compiler =-=[40]-=-: 45% of [the compiler's] time [was] spent in the typechecker: : : [N]early 36% of the entire compilation time [was] spent extending the substitution (a routine consisting of only 30 lines of code), w... |

111 |
Recherches sur la Theorie de la Demonstration, Travaux de la Societe des Sciences et de Lettres de Varsovie
- Herbrand
- 1930
(Show Context)
Citation Context ...ntation. We now consider how our approach to type explanation can be adapted to these algorithms. We first of all clarify why it is useful to add type explanation to any of these algorithms. Herbrand =-=[19]-=- provided the original and most general characterization of unification, in terms of solving equations over a free term algebra. All of the algorithms discussed in this section essentially compute suc... |

105 | Unification: a multidisciplinary survey
- Knight
- 1989
(Show Context)
Citation Context ...considered the extension of this algorithm to unifying infinite terms. Although neither algorithm has ever been published, several very similar algorithms have been published in tutorials and surveys =-=[33, 1, 26]-=-. The algorithm presented in App. D is based on the description given by Knight [26]. The algorithm is based on a well-known method for checking the equivalence of finite-state automata, using the UNI... |

81 | Partial polymorphic type inference and higher-order unification
- Pfenning
- 1988
(Show Context)
Citation Context ...uire the types of variables to be declared, type inference is often found to be essential, in reconstructing the instantiations for generic type variables at the use sites for polymorphic functions 1 =-=[42, 8]-=-. Although there is a move away from implicit typing in certain circles of the ML community, it is still popular in the community as a whole and in other language communities such as Miranda 2 , Haske... |

77 | Basic polymorphic typechecking
- Cardelli
- 1987
(Show Context)
Citation Context ...ractice for debugging type errors. 1 Introduction Type inference refers to the compile-time process of reconstructing missing type information in a program based on the usage of some of its variables =-=[10]-=-. For example, for the ML function expression fn x =? x + 1, since mixed mode arithmetic is not supported, the occurrence of 1 implies that the integer version of + is being used. This further constra... |

62 |
The PSG system: From formal language definitions to interactive programming environments
- Bahlke, Snelting
- 1986
(Show Context)
Citation Context ...ation is based on compiling naive graph unification into abstract machine code, our approach is immediately applicable to providing debugging support in such a programming environment. The PSG system =-=[4] is based -=-on checking the static semantics of a program by generating a "context relation 8 " [46] in a bottom-up fashion from an abstract syntax tree. Order-sorted unification is used in a crucial wa... |

61 |
Functional unification of higher-order patterns
- Nipkow
- 1993
(Show Context)
Citation Context ... unpublished linear-time first-order unification algorithm due to Martelli and Montanari [27]. Although an efficient and practical implementation of b 0 -unification is still an open research problem =-=[16, 34]-=-, one possible avenue to pursue is an adaptation of the more practical almost-linear-time algorithm provided by Martelli and Montanari [28] Finally, unification is also used in several other tools bes... |

56 |
Rksoluiion d'e'quations dans les langages d'ordre 1,2,. . . w
- Huet
- 1976
(Show Context)
Citation Context ...ential blow-up in naive graph unification by merging any pair of vertices which are unified, and the children of those vertices. This algorithm was proposed independently by Baxter [5, 6] and by Huet =-=[22]-=-. Huet also considered the extension of this algorithm to unifying infinite terms. Although neither algorithm has ever been published, several very similar algorithms have been published in tutorials ... |

40 |
A maximum-flow approach to anomaly isolation in unification-based incremental type inference
- Johnson, Walz
- 1986
(Show Context)
Citation Context ...the standard implementation unchanged; we identify several changes which are necessary in the usual implementation of unification [1, Chapter 6] in order to support type explanation. Johnson and Walz =-=[24, 53]-=- use weightings on bindings and flow analysis to determine the most likely correct types for variables in reporting type errors. Although this approach appears more likely to scale, it can lead to cou... |

37 |
Warren’s Abstract Machine
- Ait-Kaci
- 1991
(Show Context)
Citation Context ...otically superior performance. This is also true of the logic programming community. Prolog compiler technology is essentially based on compiling the naive graph unification algorithm given in App. A =-=[2]-=-. Naive graph unification is based on unifying type graphs. In theory its worst-case complexity is exponential, due to the occurs check and the retraversal of shared subgraphs. However the kinds of ex... |

35 |
A rehabilitation of Robinson’s unification algorithm
- Corbin, Bidoit
- 1983
(Show Context)
Citation Context ...type inference 5 . 5 The author, and others, have observed the phenomenon wherein ML programmers treat the type-checker as a demanding but We conclude by mentioning the algorithm of Corbin and Bidoit =-=[11, 33]. Although-=- Corbin and Bidoit's algorithm is offered as a "rehabilitation" of Robinson's original algorithm, the data structures for their RG2 algorithm are actually somewhat similar to those for Baxte... |

35 | A Semi-Functional Implementation of a HigherOrder Logic Programming Language
- Elliott, Pfenning
- 1991
(Show Context)
Citation Context ... unpublished linear-time first-order unification algorithm due to Martelli and Montanari [27]. Although an efficient and practical implementation of b 0 -unification is still an open research problem =-=[16, 34]-=-, one possible avenue to pursue is an adaptation of the more practical almost-linear-time algorithm provided by Martelli and Montanari [28] Finally, unification is also used in several other tools bes... |

31 | Type checking type classes
- Nipkow, Prehofer
- 1993
(Show Context)
Citation Context ... perhaps be more interesting to try extending this algorithm to Haskell type classes, where the unification algorithm is augmented with a constraint solver for resolving the use of overloaded symbols =-=[15, 35]-=-. As discussed below, based on our experience with implementing the type explanation algorithm in the Standard ML of New Jersey compiler [3, 14], we do not believe that Haskell classes introduce any m... |

28 |
Type Classes and Overloading Resolution via Order-Sorted Unification
- Nipkow, Snelting
- 1991
(Show Context)
Citation Context ...ed in a crucial way in this construction. Order-sorted unification is similar in spirit to (although more complicated than) the constraint-solving unification algorithm used in Haskell type inference =-=[36, 35, 15]-=-. So our unification algorithm for type explanation provides a possible extension to the PSG system with debugging support. A prototype of this algorithm has been implemented in the type checker for t... |

27 |
Unification in linear time and space: a structured presentation, Internal Report B76-16, Instituto di Elaborazione delle Informazione, Consiglio Nazionale delle Ricerche
- Martelli, Montanari
- 1976
(Show Context)
Citation Context ...cally linear algorithms have also been proposed in the literature. Actually two different algorithms were developed independently and contemporaneously: Martelli and Montanari's linear-time algorithm =-=[27]-=- and Paterson and Wegman's algorithm [39, 12]. The first of these was never published. Since the latter is the only algorithm whose description is available in the published literature [39, 12], we co... |

19 |
The Complexity of Unification
- Baxter
- 1976
(Show Context)
Citation Context ...e theoretical exponential blow-up in naive graph unification by merging any pair of vertices which are unified, and the children of those vertices. This algorithm was proposed independently by Baxter =-=[5, 6]-=- and by Huet [22]. Huet also considered the extension of this algorithm to unifying infinite terms. Although neither algorithm has ever been published, several very similar algorithms have been publis... |

19 |
The Implementation of Functional Programming
- Peyton-Jones
- 1987
(Show Context)
Citation Context ... substitutionin the Glasgow Haskell compiler has been replaced by a destructive implementation, as described in App. A. The GlasgowHaskell implementation is based on the use of monadic mutable arrays =-=[41]-=-: The results : : : show quite spectacular speedups. Making the substitution representation nonidempotent improved the performance of the substitution algorithm by a factor of 5: : : [T]he introductio... |

17 |
Linear unification of higher-order patterns
- Qian
- 1993
(Show Context)
Citation Context ... It might also be useful to consider extending this approach to explaining unification to higher-order unification algorithms. A practical example would be extending it to b 0 -unification [29]. Qian =-=[43]-=- has described a linear-time algorithm for b 0 -unification, based on the unpublished linear-time first-order unification algorithm due to Martelli and Montanari [27]. Although an efficient and practi... |

14 | Practical polymorphism
- Nikhil
- 1985
(Show Context)
Citation Context ...ferred for program variables, to help the programmer in tracking down the source of type errors. There have been a few approaches to providing explanations for type errors with type inference. Nikhil =-=[32]-=- describes a practical realization of type inference, where the main consideration for reporting type errors is to report the application site where the type error arose (this is now standard in most ... |

11 |
Kinded parametric overloading
- Duggan, Ophel
- 1994
(Show Context)
Citation Context ... perhaps be more interesting to try extending this algorithm to Haskell type classes, where the unification algorithm is augmented with a constraint solver for resolving the use of overloaded symbols =-=[15, 35]-=-. As discussed below, based on our experience with implementing the type explanation algorithm in the Standard ML of New Jersey compiler [3, 14], we do not believe that Haskell classes introduce any m... |

10 |
Type inference in the presence of type abstraction
- Boehm
- 1989
(Show Context)
Citation Context ...uire the types of variables to be declared, type inference is often found to be essential, in reconstructing the instantiations for generic type variables at the use sites for polymorphic functions 1 =-=[42, 8]-=-. Although there is a move away from implicit typing in certain circles of the ML community, it is still popular in the community as a whole and in other language communities such as Miranda 2 , Haske... |

7 |
The calculus of context relations
- Snelting
- 1991
(Show Context)
Citation Context ...mmediately applicable to providing debugging support in such a programming environment. The PSG system [4] is based on checking the static semantics of a program by generating a "context relation=-= 8 " [46]-=- in a bottom-up fashion from an abstract syntax tree. Order-sorted unification is used in a crucial way in this construction. Order-sorted unification is similar in spirit to (although more complicate... |

4 |
An Efficient Unification Algorithm
- Baxter
- 1973
(Show Context)
Citation Context ...e theoretical exponential blow-up in naive graph unification by merging any pair of vertices which are unified, and the children of those vertices. This algorithm was proposed independently by Baxter =-=[5, 6]-=- and by Huet [22]. Huet also considered the extension of this algorithm to unifying infinite terms. Although neither algorithm has ever been published, several very similar algorithms have been publis... |

4 |
About the Paterson-Wegman linear unification algorithm
- Champeaux
- 1986
(Show Context)
Citation Context ...oposed in the literature. Actually two different algorithms were developed independently and contemporaneously: Martelli and Montanari's linear-time algorithm [27] and Paterson and Wegman's algorithm =-=[39, 12]-=-. The first of these was never published. Since the latter is the only algorithm whose description is available in the published literature [39, 12], we concentrate on Paterson and Wegman's algorithm.... |

4 |
Description, implementation, and practical comparison of unification algorithms
- Trum, Winterstein
- 1978
(Show Context)
Citation Context ... this pointer for each variable in a multiequation which is deleted. Martelli and Montanari cite a study by Trum and Winterstein (unfortunately, again, unpublished and not available in the literature =-=[50]-=-) which apparently demonstrates that overall their algorithm fares better than either Baxter/Huet or Paterson-Wegman. Despite this, their algorithm has never been implemented in a production-qualityML... |

3 | Efficient Type Inference Using Monads
- Hammond
- 1990
(Show Context)
Citation Context ... in the algorithm, including parent pointers on vertices, unified vertices needing to be deleted, and two traversals required of the graphs to be unified, before unification, to unset various markers =-=[18]-=-. The conventional wisdom among implementors of ML and Haskell type checkers is that the PatersonWegman algorithm is completely impractical for type inference [D. MacQueen, G. Morrisett, K. Hammond, p... |

3 |
Higher order logic programming
- Nadathur, Pfenning
- 1992
(Show Context)
Citation Context ...ove away from implicit typing in certain circles of the ML community, it is still popular in the community as a whole and in other language communities such as Miranda 2 , Haskell, l-Prolog and Godel =-=[51, 21, 31, 20]-=-. Moreover we may expect implicit typing to play an increasingly important role in scripting languages such as TCL and Python [38, 52], where currently the demands of rapid prototyping and fast develo... |

2 |
A Standard ML Type Error Explanation System
- Bent
- 1994
(Show Context)
Citation Context ...tion is a mapping from each vertex of an abstract syntax tree to the set of attributes of that vertex, represented by a (possibly non-ground) term in an order-sorted free algebra. sey compiler, v0.93 =-=[3, 7]-=-. The design of the algorithm benefited critically from practical experience with this implementation. Based on experience with this prototype, the type explainer has recently been completely reimplem... |

2 |
Time profiling a lazy functional compiler
- Sansom
- 1993
(Show Context)
Citation Context ...r efficiency this derefencing operation also performs path compression on the alias chain [1, 33]. The choice between applicative and destructive substitutions is not one to be taken casually. Sansom =-=[45]-=- provides some data on the use of applicative substitutions, based on profiling of the Glasgow Haskell compiler [40]: 45% of [the compiler's] time [was] spent in the typechecker: : : [N]early 36% of t... |

1 |
Practical subtype inference. In preparation. Earlier version submitted to
- Duggan
- 1995
(Show Context)
Citation Context ...te-state automata, using the UNION-FIND algorithm to merge equivalent states [49]. In this case states correspond to vertices in the type graph, while state transitions correspond to descendant edges =-=[13]-=- between parent and child vertices. Recursion is triggered in the case where two type constructor vertices are merged. In this case n subtrees are removed by merging, and n subtrees are traversed recu... |

1 |
A type inference explanation facility for ML
- Duggan
- 1995
(Show Context)
Citation Context ...int solver for resolving the use of overloaded symbols [15, 35]. As discussed below, based on our experience with implementing the type explanation algorithm in the Standard ML of New Jersey compiler =-=[3, 14]-=-, we do not believe that Haskell classes introduce any material complications into our approach to type explanation. In this case overload resolution is an operation which succeeds type inference, ens... |

1 |
Type checking and type deduction in polymorphic programming languages
- Giannini
- 1985
(Show Context)
Citation Context ...\Gamma FV(A) which corresponds to lifting the uninstantiated non-generic type variables in an inferred type to generic type variables. The correctness of these algorithms is provided by the following =-=[17]-=-: W A (x) = hqt; qi where ae 8a 1 \Delta \Delta \Delta 8am \Delta t = A(x) q = fbm =am g where the b i 's are new type variables W A (fn x =? e) = ht ! t 0 ; qi where ae ht 0 ; qi = W A;x:a (e) where ... |

1 |
Message on haskell electronic mailing list. Available by anonymous ftp from nebula.systemz.cs.yale.edu, in directory /pub/haskell/list-archive
- Hughes
- 1993
(Show Context)
Citation Context ...thm could be extended to deal with type explanation. On the other hand, circular types have been criticized for masking static typing errors which would be detected by the occurs check in unification =-=[23]-=-. It is not yet generally agreed whether they are worth the extra complication. It may perhaps be more interesting to try extending this algorithm to Haskell type classes, where the unification algori... |

1 |
Equational reasoning. Unpublished course notes
- Nipkow
- 1992
(Show Context)
Citation Context ...tice, but for which Wand's algorithm would give incomplete and sometimes incorrect explanations); nor does he consider practical aspects of the implementation of unification (such as path compression =-=[1, 33]-=-). Nevertheless his approach is a good starting point for understanding our approach to explaining the types of individual program variables. The underlying unification algorithm in Wand's work is ess... |

1 |
Parametric overloading and liberal resolution
- Ophel, Duggan, et al.
- 1994
(Show Context)
Citation Context ... overload resolution is an operation which succeeds type inference, ensuring that the type set membership constraints accumulated during type inference are satisfiable [15, 35]. On the other hand, in =-=[37]-=- it is shown that with a sufficiently rich combination of overloading and parameteric polymorphism, it might actually be useful to have some type variables instantiated as a result of overload resolut... |

1 |
An explanation-based polymorphic type checker for Standard ML
- Soosaipillai
- 1990
(Show Context)
Citation Context ...on but neglecting to update all the call sites which follow that function's definition; under this approach, conceivably the type checker would report an error in the function definition. Soosaipillai=-=[47]-=- provides a type explainer which provides an explanation of the type of a function by walking over an explicit type derivation tree for that function. However it is not clear from her thesis what expl... |