skip to main content
research-article

Diagnosing type errors with class

Published:03 June 2015Publication History
Skip Abstract Section

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.

References

  1. A. Aiken. Introduction to set constraint-based program analysis. Science of Computer Programming, 35:79–111, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. C. Barrett, R. Jacob, and M. Marathe. Formal-language-constrained path problems. SIAM Journal on Computing, 30:809–837, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. S. Chen. Accuracy of CF-typing. Private communication, 2014.Google ScholarGoogle Scholar
  5. S. Chen and M. Erwig. Counter-factual typing for debugging type errors. In POPL 41, Jan. 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. S. Chen and M. Erwig. Better type-error messages through lazy typing. Technical report, Oregon State University, 2014.Google ScholarGoogle Scholar
  7. V. Choppella and C. T. Haynes. Diagnosis of ill-typed programs. Technical report, Indiana University, December 1995.Google ScholarGoogle Scholar
  8. EasyOCaml. EasyOCaml. http://easyocaml.forge. ocamlcore.org.Google ScholarGoogle Scholar
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. J. Hage. Helium benchmark programs, (2002–2005). Private communication, 2014.Google ScholarGoogle Scholar
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. B. J. Heeren. Top Quality Type Error Messages. PhD thesis, Universiteit Utrecht, The Netherlands, Sept. 2005.Google ScholarGoogle Scholar
  15. Helium 1.8(2014). Helium (ver. 1.8). https://hackage.haskell. org/package/helium, 2014.Google ScholarGoogle Scholar
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. J. Kodumal and A. Aiken. The set constraint/CFL reachability connection in practice. In PLDI’04, pages 207–218, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  19. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. B. S. Lerner, M. Flower, D. Grossman, and C. Chambers. Searching for type-error messages. In PLDI’07, pages 425–434, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. S. Marlow and S. Peyton-Jones. The Glasgow Haskell compiler. http://www.aosabook.org/en/ghc.html, 1993.Google ScholarGoogle Scholar
  22. B. J. McAdam. On the unification of substitutions in type inference. In Implementation of Functional Languages, pages 139–154, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. B. J. McAdam. Repairing Type Errors in Functional Programs. PhD thesis, Laboratory for Foundations of Computer Science, The University of Edinburgh, 2001.Google ScholarGoogle Scholar
  24. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  25. M. Odersky, M. Sulzmann, and M. Wehr. Type inference with constrained types. Theor. Pract. Object Syst., 5(1):35–55, Jan. 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Z. Pavlinovic, T. King, and T. Wies. Finding minimum type error sources. In OOPSLA’14, pages 525–542, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  28. 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 ScholarGoogle Scholar
  29. 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 ScholarGoogle Scholar
  30. SHErrLoc. SHErrLoc (Static Holistic Error Locator) tool release (ver 1.0). http://www.cs.cornell.edu/projects/sherrloc, 2014.Google ScholarGoogle Scholar
  31. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  32. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  33. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  34. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  35. M. Wand. Finding the source of type errors. In POPL 13, 1986. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. D. Zhang and A. C. Myers. Toward general diagnosis of static errors. In POPL, pages 569–581, Jan. 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. 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 ScholarGoogle Scholar

Index Terms

  1. Diagnosing type errors with class

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      • Published in

        cover image ACM SIGPLAN Notices
        ACM SIGPLAN Notices  Volume 50, Issue 6
        PLDI '15
        June 2015
        630 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/2813885
        • Editor:
        • Andy Gill
        Issue’s Table of Contents
        • cover image ACM Conferences
          PLDI '15: Proceedings of the 36th ACM SIGPLAN Conference on Programming Language Design and Implementation
          June 2015
          630 pages
          ISBN:9781450334686
          DOI:10.1145/2737924

        Copyright © 2015 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 3 June 2015

        Check for updates

        Qualifiers

        • research-article

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!