Heuristics for Type Error Discovery and Recovery

  • Jurriaan Hage
  • Bastiaan Heeren
Part of the Lecture Notes in Computer Science book series (LNCS, volume 4449)


Type error messages that are reported for incorrect functional programs can be difficult to understand. The reason for this is that most type inference algorithms proceed in a mechanical, syntax-directed way, and are unaware of inference techniques used by experts to explain type inconsistencies. We formulate type inference as a constraint problem, and analyze the collected constraints to improve the error messages (and, as a result, programming efficiency). A special data structure, the type graph, is used to detect global properties of a program, and furthermore enables us to uniformly describe a large collection of heuristics which embed expert knowledge in explaining type errors. Some of these also suggest corrections to the programmer. Our work has been fully implemented and is used in practical situations, showing that it scales up well. We include a number of statistics from actual use of the compiler showing us the frequency with which heuristics are used, and the kind and number of suggested corrections.


type inferencing type graph constraints heuristics error messages error recovery 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Hage, J., Heeren, B.: Ordering type constraints: A structured approach. Technical Report UU-CS-2005-016, Department of Information and Computing Science, Utrecht University, Netherlands, Technical Report (April 2005)Google Scholar
  2. 2.
    Heeren, B.: Top Quality Type Error Messages. PhD thesis, Universiteit Utrecht, The Netherlands (2005), http://www.cs.uu.nl/people/bastiaan/phdthesis
  3. 3.
    Heeren, B., Hage, J.: A first attempt at type class directives. Technical Report UU-CS-2002-031, Department of Information and Computing Science, University Utrecht, Netherlands, Technical Report (September 2004)Google Scholar
  4. 4.
    Heeren, B., Hage, J.: Type class directives. In: Seventh International Symposium on Practical Aspects of Declarative Languages, pp. 253–267. Springer, Heidelberg (2005)Google Scholar
  5. 5.
    Heeren, B., Hage, J., Swierstra, S.D.: Scripting the type inference process. In: Eighth ACM Sigplan International Conference on Functional Programming, pp. 3–13. ACM Press, New York (2003)CrossRefGoogle Scholar
  6. 6.
    Heeren, B., Leijen, D., van IJzendoorn, A.: Helium, for learning Haskell. In: ACM Sigplan 2003 Haskell Workshop, pp. 62–71. ACM Press, New York (2003)CrossRefGoogle Scholar
  7. 7.
    Langebaerd, A.: Repair systems, automatic correction of type errors in functional programs. http://www.cs.uu.nl/wiki/Top/Publications
  8. 8.
    Lee, O., Yi, K.: Proofs about a folklore let-polymorphic type inference algorithm. ACM Transanctions on Programming Languages and Systems 20(4), 707–723 (1998)CrossRefGoogle Scholar
  9. 9.
    McAdam, B.J.: Generalising techniques for type debugging. In: Trinder, P.,Michaelson, G., Loidl, H-W. (eds.) Trends in Functional Programming, Bristol, UK, Intellect, vol. 1, pp. 50–59 (2000)Google Scholar
  10. 10.
    McAdam, B.J.: How to repair type errors automatically. Trends in Functional Programming 3, 87–98 (2002)Google Scholar
  11. 11.
    Port, G.S.: A simple approach to finding the cause of non-unifiability. In: Kowalski, R.A., Bowen, K.A. (eds.) Proceedings of the Fifth International Conference and Symposium on Logic Programming, pp. 651–665. The MIT Press, Cambridge (1988)Google Scholar
  12. 12.
    Stuckey, P.J., Sulzmann, M., Wazny, J.: Interactive type debugging in Haskell. In: Haskell 2003: Proceedings of the ACM SIGPLAN Workshop on Haskell, pp. 72–83. ACM Press, New York (2003)CrossRefGoogle Scholar
  13. 13.
    Stuckey, P.J., Sulzmann, M., Wazny, J.: Improving type error diagnosis. In: Haskell 2004: Proceedings of the ACM SIGPLAN Workshop on Haskell, pp. 80–91. ACM Press, New York (2004)CrossRefGoogle Scholar
  14. 14.
    Walz, J.A., Johnson, G.F.: A maximum flow approach to anomaly isolation in unification-based incremental type inference. In: Conference Record of the 13th Annual ACM Symposium on Principles of Programming Languages, pp. 44–57, St. Petersburg, FL (January 1986)Google Scholar
  15. 15.
    Yang, J.: Explaining type errors by finding the sources of type conflicts. In: Michaelson, G., Trindler, P., Loidl, H.-W. (eds.) Trends in Functional Programming. Intellect Books, pp. 58–66 (2000)Google Scholar
  16. 16.
    Yang, J., Michaelson, G., Trinder, P.: Explaining polymorphic types. The Computer Journal 45(4), 436–452 (2002)MATHCrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2007

Authors and Affiliations

  • Jurriaan Hage
    • 1
  • Bastiaan Heeren
    • 1
  1. 1.Department of Information and Computing Sciences, Universiteit Utrecht, P.O.Box 80.089, 3508 TB UtrechtThe Netherlands

Personalised recommendations