Explaining ML Type Errors by Data Flows

  • Holger Gast
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 3474)


We present a novel approach to explaining ML type errors: Since the type system inhibits data flows that would abort the program at run-time, our type checker identifies as explanations those data flows that violate the typing rules. It also detects the notorious backflows, which are artifacts of unification, and warns the user about the possibly unexpected typing. The generated explanations comprise a detailed textual description and an arrow overlay to the source code, in which each arrowrepresents one data flow. The description refers only to elementary facts about program evaluation, not to the type checking process itself. The method integrates well with unification-based type checking: Type-correct programs incur a modest overhead compared to normal type checking. If a type error occurs, a simple depth-first graph traversal yields the explanation. A proof-of-concept implementation is available.


Data Flow Type Error Normal Reason Typing Rule Type Inference 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Aiken, A., Wimmers, E.L.: Type inclusion constraints and type inference. In: Conference on Functional Programming Languages and Computer Architecture, pp. 31–41. ACM press, New York (1993)CrossRefGoogle Scholar
  2. 2.
    Baader, F., Snyder, W.: Unification theory. In: Robinson, A., Voronkov, A. (eds.) Handbook of automated reasoning, vol. I, ch. 8, pp. 445–533. Elsevier Science, Amsterdam (2001)Google Scholar
  3. 3.
    Beaven, M., Stansifer, R.: Explaining type errors in polymorphic languages. ACM Letters on Programming Languages and Systems 2(1–4), 17–30 (1993)CrossRefGoogle Scholar
  4. 4.
    Braßel, B.: TypeHope: There is hope for your type errors. In: Grelck, C., Huch, F., Michaelson, G.J., Trinder, P. (eds.) IFL 2004. LNCS, vol. 3474. Springer, Heidelberg (2005); University of Kiel. Report 0408Google Scholar
  5. 5.
    Chitil, O.: Compositional explanation of types and algorithmic debugging of type errors. In: Proceedings of the Sixth ACM SIGPLAN International Conference on Functional Programming (ICFP 2001), Florence, Italy, pp. 193–204 (2001)Google Scholar
  6. 6.
    Duggan, D., Bent, F.: Explaining type inference. Science of Computer Programming 27(1), 37–83 (1996)zbMATHCrossRefGoogle Scholar
  7. 7.
    Eifrig, J., Smith, S., Trifonov, V.: Type inference for recursively constrained types and its application to OOP. Electronic Notes in Theoretical Computer Science, vol. 1 (1995)Google Scholar
  8. 8.
    Flanagan, C., Flatt, M., Krishnamurthi, S., Weirich, S., Felleisen, M.: Catching bugs in the web of program invariants. ACM SIGPLAN Notices 31(5), 23–32 (1996)CrossRefGoogle Scholar
  9. 9.
    Gallier, J.H.: Logic for Computer Science – Foundations of Automatic Theorem Proving. Harper & Row Publishers, New York (1986)zbMATHGoogle Scholar
  10. 10.
    Haack, C., Wells, J.B.: Type error slicing in implicitly typed higher-order languages. Science of Computer Programming 50(1–3), 189–224 (2004); Special issue on 12th European symposium on programming (ESOP 2003)Google Scholar
  11. 11.
    Hansen, J., Shafarenko, A.: Type error reporting in a single-assignment language with homomorphic overloading. In: International Workshop on the Implementation of Functional Languages, Edinburgh, Schottland (September 2003)Google Scholar
  12. 12.
    Heeren, B., Hage, J., Swierstra, D.: Generalizing Hindley-Milner type-inference algorithms. Technical Report UU-CS-2002-031, Institute of Information and Computing Sciences, Utrecht University (2002)Google Scholar
  13. 13.
    Heeren, B., Hage, J., Swierstra, S.D.: Scripting the type inference process. ACM SIGPLAN Notices 38(9) (September 2003)Google Scholar
  14. 14.
    Hoang, M., Mitchell, J.C.: Lower bounds on type inference with subtypes. In: Conference Record of POPL 1995: 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, San Francisco, California, January 23-25, 1995. ACM Press, New York (1995)Google Scholar
  15. 15.
    Martelli, A., Montanari, U.: An efficient unification algorithm. ACM Transactions on Programming Languages and Systems 4(2), 258–282 (1982)zbMATHCrossRefGoogle Scholar
  16. 16.
    McAdam, B.J.: Repairing Type Errors in Functional Programs. PhD thesis, Division of Informatics, University of Edinburgh (2002)Google Scholar
  17. 17.
    Milner, R.: A theory of type polymorphism in programming. Journal of Computer and System Sciences 17, 348–375 (1978)zbMATHCrossRefMathSciNetGoogle Scholar
  18. 18.
    Mitchell, J.C.: Type inference with simple subtypes. Journal of Functional Programming 1(3), 245–285 (1991)zbMATHCrossRefMathSciNetGoogle Scholar
  19. 19.
    Neubauer, M., Thiemann, P.: Discriminative sum types locate the source of type errors. In: Proceedings of the 8th ACM SIGPLAN International Conference on Functional Programming, Uppsala, Sweden, pp. 15–26. ACM, New York (2003)CrossRefGoogle Scholar
  20. 20.
    Objective Caml 3.08 (July 2004),
  21. 21.
    Stuckey, P.J., Sulzmann, M., Wazny, J.: Improving type error diagnosis. In: Proceedings of Haskell Workshop (Haskell 2004) (May 2004) (to appear)Google Scholar
  22. 22.
    Tip, F., Dinesh, T.B.: A slicing-based approach for locating type errors. ACM Transactions on Software Engineering and Methodology 10(1), 5–55 (2001)CrossRefGoogle Scholar
  23. 23.
    Wand, M.: Finding the source of type errors. In: Proceedings of the 13th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages, pp. 38–43. ACM Press, New York (1986)CrossRefGoogle Scholar
  24. 24.
    Wand, M.: A simple algorithm and proof for type inference. Fundamenta Informaticae 10, 115–122 (1987)zbMATHMathSciNetGoogle Scholar
  25. 25.
    Wright, A.K.: Practical Soft Typing. PhD thesis, Rice University, Houston,Texas (August 1994)Google Scholar
  26. 26.
    Yang, J.: Improving polymorphic type explanations. PhD thesis, Department of Computing and Electrical Engineering, Heriot-Watt University (October 2001)Google Scholar
  27. 27.
    Yang, J., Michaelson, G., Trinder, P.: Explaining polymorphic types. The Computer Journal 45(4), 436–452 (2002)zbMATHCrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2005

Authors and Affiliations

  • Holger Gast
    • 1
  1. 1.Wilhelm-Schickard-Institut für InformatikUniversität TübingenTübingenGermany

Personalised recommendations