Skip to main content

Improving Type Error Reporting for Type Classes

  • Conference paper
  • First Online:
Functional and Logic Programming (FLOPS 2022)

Part of the book series: Lecture Notes in Computer Science ((LNCS,volume 13215))

Included in the following conference series:

  • 434 Accesses

Abstract

Debugging type errors when type inference fails is a challenging problem since there are many different ways to remove the type error, and it’s unclear which way is intended. While numerous approaches have been proposed to more precisely locate the real error causes, most of them do not deal with popular type system extensions, such as type classes. A second problem is that most approaches do not provide enough information for removing the type error or do so for a few error causes only.

In this work, we develop an approach called TEC to address both problems. Given an ill-typed expression that may involve type classes, TEC finds comprehensive error causes and generates for each cause an error fix with detailed information for removing the type error. TEC computes all error fixes, ranks them, and iteratively presents the most likely error fix to the user until a fix is accepted. TEC reduces the problem of finding all error fixes to variational typing, which systematically reuses typing results. Our main technical innovation is a variational context reduction algorithm that simplifies type class constraints containing variations. We have evaluated the precision of TEC and found that it outperforms existing approaches in locating type errors arising from type class uses.

This work is supported by the National Science Foundation under the grant CCF-1750886.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 54.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 69.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

References

  1. Beaven, M., Stansifer, R.: Explaining type errors in polymorphic languages. ACM Lett. Program. Lang. Syst. 2, 17–30 (1994)

    Article  Google Scholar 

  2. Bernstein, K.L., Stark, E.W.: Debugging Type Errors. State University of New York at Stony Brook, Technical report (1995)

    Google Scholar 

  3. Braßel, B.: Typehope: there is hope for your type errors. In: International Workshop on Implementation of Functional Languages (2004)

    Google Scholar 

  4. Chen, S., Erwig, M.: Counter-factual typing for debugging type errors. In: ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 583–594 (2014)

    Google Scholar 

  5. Chen, S., Erwig, M.: Guided type debugging. In: Codish, M., Sumii, E. (eds.) FLOPS 2014. LNCS, vol. 8475, pp. 35–51. Springer, Cham (2014). https://doi.org/10.1007/978-3-319-07151-0_3

    Chapter  Google Scholar 

  6. Chen, S., Erwig, M., Walkingshaw, E.: An error-tolerant type system for variational lambda calculus. In: ACM International Conference on Functional Programming, pp. 29–40 (2012)

    Google Scholar 

  7. Chen, S., Erwig, M., Walkingshaw, E.: Extending type inference to variational programs. ACM Trans. Program. Lang. Syst. 36(1), 1:1–1:54 (2014)

    Google Scholar 

  8. Chen, S., Noor, R.: Improving Type Error Reporting for Type Classes. Technical report, UL Lafayette (2022). https://people.cmix.louisiana.edu/schen/ws/techreport/longtec.pdf

  9. Chitil, O.: Compositional explanation of types and algorithmic debugging of type errors. In: ACM International Conference on Functional Programming, pp. 193–204, September 2001

    Google Scholar 

  10. Choppella, V.: Unification source-tracking with application to diagnosis of type inference. Ph.D. thesis, Indiana University (2002)

    Google Scholar 

  11. Duggan, D., Bent, F.: Explaining type inference. Sci. Comput. Program. 27, 37–83 (1995)

    Article  Google Scholar 

  12. Eo, H., Lee, O., Yi, K.: Proofs of a set of hybrid let-polymorphic type inference algorithms. New Gener. Comput. 22(1), 1–36 (2004). https://doi.org/10.1007/BF03037279

    Article  MATH  Google Scholar 

  13. Haack, C., Wells, J.B.: Type error slicing in implicitly typed higher-order languages. In: Degano, P. (ed.) ESOP 2003. LNCS, vol. 2618, pp. 284–301. Springer, Heidelberg (2003). https://doi.org/10.1007/3-540-36575-3_20

    Chapter  MATH  Google Scholar 

  14. Hage, J., Heeren, B.: Heuristics for type error discovery and recovery. In: Horváth, Z., Zsók, V., Butterfield, A. (eds.) IFL 2006. LNCS, vol. 4449, pp. 199–216. Springer, Heidelberg (2007). https://doi.org/10.1007/978-3-540-74130-5_12

    Chapter  Google Scholar 

  15. Heeren, B., Hage, J.: Type class directives. In: Hermenegildo, M.V., Cabeza, D. (eds.) PADL 2005. LNCS, vol. 3350, pp. 253–267. Springer, Heidelberg (2005). https://doi.org/10.1007/978-3-540-30557-6_19

    Chapter  Google Scholar 

  16. Heeren, B., Hage, J., Swierstra, S.D.: Scripting the type inference process. In: Proceedings of the Eighth ACM SIGPLAN International Conference on Functional Programming, ICFP 2003, pp. 3–13. ACM, New York (2003). https://doi.org/10.1145/944705.944707

  17. Heeren, B.J.: Top quality type error messages. Ph.D. thesis, Universiteit Utrecht, The Netherlands (2005)

    Google Scholar 

  18. Johnson, G.F., Walz, J.A.: A maximum-flow approach to anomaly isolation in unification-based incremental type inference. In: ACM Symposium on Principles of Programming Languages, pp. 44–57 (1986)

    Google Scholar 

  19. Jones, M.P.: A theory of qualified types. In: Krieg-Brückner, B. (ed.) ESOP 1992. LNCS, vol. 582, pp. 287–306. Springer, Heidelberg (1992). https://doi.org/10.1007/3-540-55253-7_17

    Chapter  Google Scholar 

  20. Jones, M.P.: Simplifying and improving qualified types. In: Proceedings of the Seventh International Conference on Functional Programming Languages and Computer Architecture, FPCA 1995, pp. 160–169. ACM, New York (1995). https://doi.org/10.1145/224164.224198

  21. Jones, M.P.: Typing Haskell in Haskell. In: Haskell Workshop (1999)

    Google Scholar 

  22. Jones, M.P.: Type classes with functional dependencies. In: Smolka, G. (ed.) ESOP 2000. LNCS, vol. 1782, pp. 230–244. Springer, Heidelberg (2000). https://doi.org/10.1007/3-540-46425-5_15

    Chapter  Google Scholar 

  23. Lee, O., Yi, K.: Proofs about a folklore let-polymorphic type inference algorithm. ACM Trans. Program. Lang. Syst. 20(4), 707–723 (1998)

    Article  Google Scholar 

  24. Lee, O., Yi, K.: A generalized let-polymorphic type inference algorithm. Technical report, Technical Memorandum ROPAS-2000-5, Research on Program Analysis System, Korea Advanced Institute of Science and Technology (2000)

    Google Scholar 

  25. Lerner, B., Flower, M., Grossman, D., Chambers, C.: Searching for type-error messages. In: ACM International Conference on Programming Language Design and Implementation, pp. 425–434 (2007)

    Google Scholar 

  26. McAdam, B.J.: Repairing type errors in functional programs. Ph.D. thesis, University of Edinburgh. College of Science and Engineering. School of Informatics (2002)

    Google Scholar 

  27. Neubauer, M., Thiemann, P.: Discriminative sum types locate the source of type errors. In: ACM International Conference on Functional Programming, pp. 15–26 (2003)

    Google Scholar 

  28. Odersky, M., Sulzmann, M., Wehr, M.: Type inference with constrained types. Theor. Pract. Object Syst. 5(1), 35–55 (1999)

    Article  Google Scholar 

  29. Pavlinovic, Z., King, T., Wies, T.: Finding minimum type error sources. In: ACM International Conference on Object Oriented Programming Systems Languages and Applications, OOPSLA 2014, pp. 525–542. ACM, New York (2014). https://doi.org/10.1145/2660193.2660230

  30. Pavlinovic, Z., King, T., Wies, T.: Practical SMT-based type error localization. In: ACM SIGPLAN International Conference on Functional Programming, pp. 412–423 (2015)

    Google Scholar 

  31. Schilling, Thomas: Constraint-free type error slicing. In: Peña, R., Page, R. (eds.) TFP 2011. LNCS, vol. 7193, pp. 1–16. Springer, Heidelberg (2012). https://doi.org/10.1007/978-3-642-32037-8_1

    Chapter  Google Scholar 

  32. Seidel, E.L., Jhala, R., Weimer, W.: Dynamic witnesses for static type errors (or, ill-typed programs usually go wrong). In: Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming, ICFP 2016, pp. 228–242. ACM, New York (2016). https://doi.org/10.1145/2951913.2951915

  33. Stuckey, P.J., Sulzmann, M., Wazny, J.: Interactive type debugging in Haskell. In: ACM SIGPLAN Workshop on Haskell, pp. 72–83 (2003)

    Google Scholar 

  34. Stuckey, P.J., Sulzmann, M., Wazny, J.: Improving type error diagnosis. In: ACM SIGPLAN Workshop on Haskell, pp. 80–91 (2004)

    Google Scholar 

  35. Tip, F., Dinesh, T.B.: A slicing-based approach for locating type errors. ACM Trans. Softw. Eng. Methodol. 10(1), 5–55 (2001)

    Article  Google Scholar 

  36. Tirronen, V., Uusi-Mäkelä, S., Isomöttönen, V.: Understanding beginners’ mistakes with Haskell. J. Funct. Program. 25, e11 (2015). https://doi.org/10.1017/S0956796815000179

  37. Tsushima, K., Chitil, O., Sharrad, J.: Type debugging with counter-factual type error messages using an existing type checker. In: IFL 2019: Proceedings of the 31st Symposium on Implementation and Application of Functional Languages, ICPS. ACM, New York (2020). https://kar.kent.ac.uk/81976/

  38. Wand, M.: Finding the source of type errors. In: ACM Symposium on Principles of Programming Languages, pp. 38–43 (1986)

    Google Scholar 

  39. Wazny, J.R.: Type inference and type error diagnosis for Hindley/Milner with extensions. Ph.D. thesis, The University of Melbourne (2006)

    Google Scholar 

  40. Yang, J.: Explaining type errors by finding the source of a type conflict. In: Trends in Functional Programming, pp. 58–66. Intellect Books (2000)

    Google Scholar 

  41. Yang, J.: Improving Polymorphic Type Explanations. Ph.D. thesis, Heriot-Watt University (2001)

    Google Scholar 

  42. Zhang, D., Myers, A.C.: Toward general diagnosis of static errors. In: ACM Symposium on Principles of Programming Languages, pp. 569–581 (2014)

    Google Scholar 

  43. Zhang, D., Myers, A.C., Vytiniotis, D., Peyton-Jones, S.: Diagnosing type errors with class. In: ACM SIGPLAN Conference on Programming Language Design and Implementation, pp. 12–21 (2015)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Sheng Chen .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2022 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Chen, S., Noor, M.R. (2022). Improving Type Error Reporting for Type Classes. In: Hanus, M., Igarashi, A. (eds) Functional and Logic Programming. FLOPS 2022. Lecture Notes in Computer Science, vol 13215. Springer, Cham. https://doi.org/10.1007/978-3-030-99461-7_2

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-99461-7_2

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-99460-0

  • Online ISBN: 978-3-030-99461-7

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics