Abstract
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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Similar content being viewed by others
References
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)
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)
Beaven, M., Stansifer, R.: Explaining type errors in polymorphic languages. ACM Letters on Programming Languages and Systems 2(1–4), 17–30 (1993)
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 0408
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)
Duggan, D., Bent, F.: Explaining type inference. Science of Computer Programming 27(1), 37–83 (1996)
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)
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)
Gallier, J.H.: Logic for Computer Science – Foundations of Automatic Theorem Proving. Harper & Row Publishers, New York (1986)
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)
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)
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)
Heeren, B., Hage, J., Swierstra, S.D.: Scripting the type inference process. ACM SIGPLAN Notices 38(9) (September 2003)
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)
Martelli, A., Montanari, U.: An efficient unification algorithm. ACM Transactions on Programming Languages and Systems 4(2), 258–282 (1982)
McAdam, B.J.: Repairing Type Errors in Functional Programs. PhD thesis, Division of Informatics, University of Edinburgh (2002)
Milner, R.: A theory of type polymorphism in programming. Journal of Computer and System Sciences 17, 348–375 (1978)
Mitchell, J.C.: Type inference with simple subtypes. Journal of Functional Programming 1(3), 245–285 (1991)
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)
Objective Caml 3.08 (July 2004), http://caml.inria.fr
Stuckey, P.J., Sulzmann, M., Wazny, J.: Improving type error diagnosis. In: Proceedings of Haskell Workshop (Haskell 2004) (May 2004) (to appear)
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)
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)
Wand, M.: A simple algorithm and proof for type inference. Fundamenta Informaticae 10, 115–122 (1987)
Wright, A.K.: Practical Soft Typing. PhD thesis, Rice University, Houston,Texas (August 1994)
Yang, J.: Improving polymorphic type explanations. PhD thesis, Department of Computing and Electrical Engineering, Heriot-Watt University (October 2001)
Yang, J., Michaelson, G., Trinder, P.: Explaining polymorphic types. The Computer Journal 45(4), 436–452 (2002)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2005 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Gast, H. (2005). Explaining ML Type Errors by Data Flows. In: Grelck, C., Huch, F., Michaelson, G.J., Trinder, P. (eds) Implementation and Application of Functional Languages. IFL 2004. Lecture Notes in Computer Science, vol 3474. Springer, Berlin, Heidelberg. https://doi.org/10.1007/11431664_5
Download citation
DOI: https://doi.org/10.1007/11431664_5
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-26094-3
Online ISBN: 978-3-540-32038-8
eBook Packages: Computer ScienceComputer Science (R0)