Abstract
Type inference engines often give terrible error messages, and the more sophisticated the type system the worse the problem. We show that even with the highly expressive type system implemented by the Glasgow Haskell Compiler (GHC)--including type classes, GADTs, and type families--it is possible to identify the most likely source of the type error, rather than the first source that the inference engine trips over. To determine which are the likely error sources, we apply a simple Bayesian model to a graph representation of the typing constraints; the satisfiability or unsatisfiability of paths within the graph provides evidence for or against possible explanations. While we build on prior work on error diagnosis for simpler type systems, inference in the richer type system of Haskell requires extending the graph with new nodes. The augmentation of the graph creates challenges both for Bayesian reasoning and for ensuring termination. Using a large corpus of Haskell programs, we show that this error localization technique is practical and significantly improves accuracy over the state of the art.
- A. Aiken. Introduction to set constraint-based program analysis. Science of Computer Programming, 35:79–111, 1999. Google Scholar
Digital Library
- A. Aiken and E. L. Wimmers. Type inclusion constraints and type inference. In Conf. Functional Programming Languages and Computer Architecture, pages 31–41, 1993. Google Scholar
Digital Library
- C. Barrett, R. Jacob, and M. Marathe. Formal-language-constrained path problems. SIAM Journal on Computing, 30:809–837, 2000. Google Scholar
Digital Library
- S. Chen. Accuracy of CF-typing. Private communication, 2014.Google Scholar
- S. Chen and M. Erwig. Counter-factual typing for debugging type errors. In POPL 41, Jan. 2014. Google Scholar
Digital Library
- S. Chen and M. Erwig. Better type-error messages through lazy typing. Technical report, Oregon State University, 2014.Google Scholar
- V. Choppella and C. T. Haynes. Diagnosis of ill-typed programs. Technical report, Indiana University, December 1995.Google Scholar
- EasyOCaml. EasyOCaml. http://easyocaml.forge. ocamlcore.org.Google Scholar
- J. S. Foster, R. Johnson, J. Kodumal, and A. Aiken. Flow-insensitive type qualifiers. ACM Trans. Prog. Lang. Syst., 28(6):1035–1087, Nov. 2006. Google Scholar
Digital Library
- C. Haack and J. B. Wells. Type error slicing in implicitly typed higherorder languages. Science of Computer Programming, 50(1–3):189– 224, 2004. Google Scholar
Digital Library
- J. Hage. Helium benchmark programs, (2002–2005). Private communication, 2014.Google Scholar
- J. Hage and B. Heeren. Heuristics for type error discovery and recovery. In Z. Horváth, V. Zs´ok, and A. Butterfield, editors, Implementation and Application of Functional Languages, volume 4449 of Lecture Notes in Computer Science, pages 199–216. Springer, 2007. Google Scholar
Digital Library
- B. Heeren, D. Leijen, and A. van IJzendoorn. Helium, for learning Haskell. In Proc. 2003 ACM SIGPLAN Workshop on Haskell, pages 62–71, 2003. Google Scholar
Digital Library
- B. J. Heeren. Top Quality Type Error Messages. PhD thesis, Universiteit Utrecht, The Netherlands, Sept. 2005.Google Scholar
- Helium 1.8(2014). Helium (ver. 1.8). https://hackage.haskell. org/package/helium, 2014.Google Scholar
- G. F. Johnson and J. A. Walz. A maximum flow approach to anomaly isolation in unification-based incremental type inference. In POPL 13, pages 44–57, 1986. Google Scholar
Digital Library
- J. Kodumal and A. Aiken. The set constraint/CFL reachability connection in practice. In PLDI’04, pages 207–218, 2004. Google Scholar
Digital Library
- O. Lee and K. Yi. Proofs about a folklore let-polymorphic type inference algorithm. ACM Trans. Program. Lang. Syst., 20(4):707– 723, July 1998. Google Scholar
Digital Library
- O. Lee and K. Yi. Proofs about a folklore let-polymorphic type inference algorithm. ACM Trans. Prog. Lang. Syst., 20(4):707–723, 1998. Google Scholar
Digital Library
- B. S. Lerner, M. Flower, D. Grossman, and C. Chambers. Searching for type-error messages. In PLDI’07, pages 425–434, 2007. Google Scholar
Digital Library
- S. Marlow and S. Peyton-Jones. The Glasgow Haskell compiler. http://www.aosabook.org/en/ghc.html, 1993.Google Scholar
- B. J. McAdam. On the unification of substitutions in type inference. In Implementation of Functional Languages, pages 139–154, 1998. Google Scholar
Digital Library
- B. J. McAdam. Repairing Type Errors in Functional Programs. PhD thesis, Laboratory for Foundations of Computer Science, The University of Edinburgh, 2001.Google Scholar
- D. Melski and T. Reps. Interconvertibility of a class of set constraints and context-free language reachability. Theoretical Computer Science, 248(1–2):29–98, 2000. Google Scholar
Digital Library
- M. Odersky, M. Sulzmann, and M. Wehr. Type inference with constrained types. Theor. Pract. Object Syst., 5(1):35–55, Jan. 1999. Google Scholar
Digital Library
- Z. Pavlinovic, T. King, and T. Wies. Finding minimum type error sources. In OOPSLA’14, pages 525–542, 2014. Google Scholar
Digital Library
- S. Peyton Jones, D. Vytiniotis, S. Weirich, and M. Shields. Practical type inference for arbitrary-rank types. J. Funct. Program., 17(1):1– 82, Jan. 2007. Google Scholar
Digital Library
- F. Pottier and D. Rémy. The essence of ML type inference. In B. C. Pierce, editor, Advanced topics in types and programming languages, pages 389–489. MIT Press, 2005.Google Scholar
- V. Rahli, J. B. Wells, and F. Kamareddine. A constraint system for a SML type error slicer. Technical Report HW-MACS-TR-0079, Heriot-Watt university, 2010.Google Scholar
- SHErrLoc. SHErrLoc (Static Holistic Error Locator) tool release (ver 1.0). http://www.cs.cornell.edu/projects/sherrloc, 2014.Google Scholar
- P. J. Stuckey, M. Sulzmann, and J. Wazny. Interactive type debugging in Haskell. In Proc. 2003 ACM SIGPLAN Workshop on Haskell, Haskell ’03, pages 72–83, 2003. Google Scholar
Digital Library
- F. Tip and T. B. Dinesh. A slicing-based approach for locating type errors. ACM Trans. on Software Engineering and Methodology, 10(1): 5–55, 2001. Google Scholar
Digital Library
- D. Vytiniotis, S. Peyton Jones, and T. Schrijvers. Let should not be generalized. In Proc. 5th ACM SIGPLAN Workshop on Types in Language Design and Implementation, pages 39–50, New York, NY, USA, 2010. ACM. Google Scholar
Digital Library
- D. Vytiniotis, S. P. Jones, T. Schrijvers, and M. Sulzmann. Outsidein(X): Modular type inference with local assumptions. Journal of Functional Programming, September 2011. Google Scholar
Digital Library
- M. Wand. Finding the source of type errors. In POPL 13, 1986. Google Scholar
Digital Library
- D. Zhang and A. C. Myers. Toward general diagnosis of static errors. In POPL, pages 569–581, Jan. 2014. Google Scholar
Digital Library
- D. Zhang, A. C. Myers, D. Vytiniotis, and S. Peyton-Jones. Diagnosing Haskell type errors. Technical Report http://hdl.handle.net/1813/39907, Cornell University, Apr. 2015.Google Scholar
Index Terms
Diagnosing type errors with class
Recommendations
Diagnosing type errors with class
PLDI '15: Proceedings of the 36th ACM SIGPLAN Conference on Programming Language Design and ImplementationType inference engines often give terrible error messages, and the more sophisticated the type system the worse the problem. We show that even with the highly expressive type system implemented by the Glasgow Haskell Compiler (GHC)--including type ...
SHErrLoc: A Static Holistic Error Locator
We introduce a general way to locate programmer mistakes that are detected by static analyses. The program analysis is expressed in a general constraint language that is powerful enough to model type checking, information flow analysis, dataflow ...
Delta Debugging Type Errors with a Blackbox Compiler
IFL '18: Proceedings of the 30th Symposium on Implementation and Application of Functional LanguagesDebugging type errors is a necessary process that programmers, both novices and experts alike, face when using statically typed functional programming languages. All compilers often report the location of a type error inaccurately. This problem has been ...






Comments