2010 Volume 5 Issue 4 Pages 1241-1254
We propose a type inference algorithm for a polymorphic type system which provides improved error messages. While the standard type inference algorithms often produce unnecessarily long or incomplete error messages, our algorithm provides relevant and complete information for type errors. It is relevant in the sense that all the program points and types in the output of our algorithm contribute to some type error, and is complete in the sense that, for each type error, our algorithm identifies not only two conflicting types, but also all types which conflict with each other. The latter property is particularly useful for debugging programs with lists or case branches. Our algorithm keeps track of the set of program points that are relevant to each type. To achieve completeness, we introduce a new type variable which represents a conflict among two or more incompatible types, and extend the unification algorithm to handle the special type variable appropriately. Finally, we argue that our algorithm is more efficient than those in the literature when there are more than two conflicting types in the given expression.