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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
References
Beaven, M., Stansifer, R.: Explaining type errors in polymorphic languages. ACM Lett. Program. Lang. Syst. 2, 17–30 (1994)
Bernstein, K.L., Stark, E.W.: Debugging Type Errors. State University of New York at Stony Brook, Technical report (1995)
Braßel, B.: Typehope: there is hope for your type errors. In: International Workshop on Implementation of Functional Languages (2004)
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)
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
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)
Chen, S., Erwig, M., Walkingshaw, E.: Extending type inference to variational programs. ACM Trans. Program. Lang. Syst. 36(1), 1:1–1:54 (2014)
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
Chitil, O.: Compositional explanation of types and algorithmic debugging of type errors. In: ACM International Conference on Functional Programming, pp. 193–204, September 2001
Choppella, V.: Unification source-tracking with application to diagnosis of type inference. Ph.D. thesis, Indiana University (2002)
Duggan, D., Bent, F.: Explaining type inference. Sci. Comput. Program. 27, 37–83 (1995)
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
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
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
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
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
Heeren, B.J.: Top quality type error messages. Ph.D. thesis, Universiteit Utrecht, The Netherlands (2005)
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)
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
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
Jones, M.P.: Typing Haskell in Haskell. In: Haskell Workshop (1999)
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
Lee, O., Yi, K.: Proofs about a folklore let-polymorphic type inference algorithm. ACM Trans. Program. Lang. Syst. 20(4), 707–723 (1998)
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)
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)
McAdam, B.J.: Repairing type errors in functional programs. Ph.D. thesis, University of Edinburgh. College of Science and Engineering. School of Informatics (2002)
Neubauer, M., Thiemann, P.: Discriminative sum types locate the source of type errors. In: ACM International Conference on Functional Programming, pp. 15–26 (2003)
Odersky, M., Sulzmann, M., Wehr, M.: Type inference with constrained types. Theor. Pract. Object Syst. 5(1), 35–55 (1999)
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
Pavlinovic, Z., King, T., Wies, T.: Practical SMT-based type error localization. In: ACM SIGPLAN International Conference on Functional Programming, pp. 412–423 (2015)
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
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
Stuckey, P.J., Sulzmann, M., Wazny, J.: Interactive type debugging in Haskell. In: ACM SIGPLAN Workshop on Haskell, pp. 72–83 (2003)
Stuckey, P.J., Sulzmann, M., Wazny, J.: Improving type error diagnosis. In: ACM SIGPLAN Workshop on Haskell, pp. 80–91 (2004)
Tip, F., Dinesh, T.B.: A slicing-based approach for locating type errors. ACM Trans. Softw. Eng. Methodol. 10(1), 5–55 (2001)
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
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/
Wand, M.: Finding the source of type errors. In: ACM Symposium on Principles of Programming Languages, pp. 38–43 (1986)
Wazny, J.R.: Type inference and type error diagnosis for Hindley/Milner with extensions. Ph.D. thesis, The University of Melbourne (2006)
Yang, J.: Explaining type errors by finding the source of a type conflict. In: Trends in Functional Programming, pp. 58–66. Intellect Books (2000)
Yang, J.: Improving Polymorphic Type Explanations. Ph.D. thesis, Heriot-Watt University (2001)
Zhang, D., Myers, A.C.: Toward general diagnosis of static errors. In: ACM Symposium on Principles of Programming Languages, pp. 569–581 (2014)
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)
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2022 Springer Nature Switzerland AG
About this paper
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)