Skip to content
BY 4.0 license Open Access Published by De Gruyter Open Access January 24, 2019

A framework for improving error messages in dependently-typed languages

Joseph Eremondi EMAIL logo , Wouter Swierstra and Jurriaan Hage
From the journal Open Computer Science

Abstract

Dependently-typed programming languages provide a powerful tool for establishing code correctness. However, it can be hard for newcomers to learn how to employ the advanced type system of such languages effectively. For simply-typed languages, several techniques have been devised to generate helpful error messages and suggestions for the programmer. We adapt these techniques to dependently-typed languages, to facilitate their more widespread adoption. In particular, we modify a higher-order unification algorithm that is used to resolve and type-check implicit arguments. We augment this algorithm with replay graphs, allowing for a global heuristic analysis of a unification problem-set, error-tolerant typing, which allows type-checking to continue after errors are found, and counter-factual unification, which makes error messages less affected by the order in which types are checked. A formalization of our algorithm is presented with an outline of its correctness. We implement replay graphs, and compare the generated error messages to those from existing languages, highlighting the improvements we achieved.

References

[1] Barik T., Smith J., Lubick K., Holmes E., Feng J., Murphy-Hill E., Parnin C., Do developers read compiler error messages?, In: Proceedings of the 39th International Conference on Software Engineering (ICSE ’17), IEEE Press Piscataway, NJ, USA, 2017, 575-585, DOI: 10.1109/ICSE.2017.5910.1109/ICSE.2017.59Search in Google Scholar

[2] Heeren B., Hage J., Swierstra S. D., Constraint based type inferencing in Helium, Immediate Applications of Constraint Programming (ACP), 2003, 57, http://www.open.ou.nl/bhr/ConstraintBasedTI.htmlSearch in Google Scholar

[3] Hage J., Heeren B., Heuristics for type error discovery and recovery, In: Proceedings of the 18th International Conference on Implementation and Application of Functional Languages (IFL’06), Springer-Verlag, Berlin, Heidelberg, 2007, 199-216, DOI:10.1007/978-3-540-74130-5_1210.1007/978-3-540-74130-5_12Search in Google Scholar

[4] Heeren B. J., Top quality type error messages, Ph.D. thesis, Utrecht University, Utrecht, Netherlands, 2005, IPA Dissertation Series, https://dspace.library.uu.nl/handle/1874/7297Search in Google Scholar

[5] Chen S., Erwig M., Counter-factual typing for debugging type errors, In: Proceedings of the 41st ACM SIGPLANSIGACT Symposium on Principles of Programming Languages (POPL ’14), ACM, New York, NY, USA, 2014, 583-594, DOI: 10.1145/2535838.253586310.1145/2535838.2535863Search in Google Scholar

[6] Norell U., Dependently typed programming in Agda, In: Proceedings of the 4th International Workshop on Types in Language Design and Implementation (TLDI ’09), ACM, New York, NY, USA, 2009, 1-2, DOI: 10.1145/1481861.148186210.1145/1481861.1481862Search in Google Scholar

[7] Brady E., Idris, a general-purpose dependently typed programming language: design and implementation, Journal of Functional Programming, 2013, 23(5), 552-593, DOI: 10.1017/S095679681300018X10.1017/S095679681300018XSearch in Google Scholar

[8] Haack C., Wells J. B., Type error slicing in implicitly typed higher-order languages, Science of Computer Programming, Special Issue: 12th European Symposium on Programming (ESOP 2003), 2004, 50(1-3), 189-224, DOI: 10.1016/j.scico.2004.01.00410.1016/j.scico.2004.01.004Search in Google Scholar

[9] Zhang D., Myers A. C., Vytiniotis D., Peyton-Jones S., SHErrLoc: a static holistic error locator, ACM Trans. Program. Lang. Syst., 2017, 39(4), Article 18, DOI: 10.1145/312113710.1145/3121137Search in Google Scholar

[10] Yang J., Michaelson G., Trinder P., Wells J. B., Improved type error reporting, In: Proceedings of 12th International Workshop on Implementation of Functional Languages, 2000, 71-86Search in Google Scholar

[11] /u/GNULinuxProgrammer, /r/agda: R x → x == y → r y, 2016, https://www.reddit.com/r/agda/comments/7lq44q/r_x_x_y_r_y/ (Accessed: 2018-06-14)Search in Google Scholar

[12] Watkins K., Cervesato I., Pfenning F., Walker D., A concurrent logical framework I: Judgments and properties, Technical Report CMU-CS-02-101, 2003, https://www.cs.cmu.edu/~fp/papers/CMU-CS-02-101.pdf10.21236/ADA418517Search in Google Scholar

[13] Martin-Löf P., About models for intuitionistic type theories and the notion of definitional equality, in: Proceedings of the Third Scandinavian Logic Symposium, Studies in Logic and the Foundations of Mathematics, North-Holland Publishing Company, Amsterdam, Netherlands, Elsevier, New York, USA, 1975, 82, 81-109, DOI: 10.1016/S0049-237X(08)70727-410.1016/S0049-237X(08)70727-4Search in Google Scholar

[14] Miller D., Unification under a mixed prefix, J. Symb. Comput., 1992, 14(4), 321-358, DOI: 10.1016/0747-7171(92)90011-R10.1016/0747-7171(92)90011-Search in Google Scholar

[15] Abel A., Pientka B., Higher-order dynamic pattern unification for dependent types and records, Typed Lambda Calculi and Applications, 10th International Conference (Novi Sad, Serbia), Springer Berlin Heidelberg, Berlin, Heidelberg, 2011, 10-26, DOI: 10.1007/978-3-642-21691-6_510.1007/978-3-642-21691-6_5Search in Google Scholar

[16] Norell U., Towards a practical programming language based on dependent type theory, Ph.D. thesis, Chalmers University of Technology, Gothenburg, Sweden, 2007, http://www.cse.chalmers.se/~ulfn/papers/thesis.pdfSearch in Google Scholar

[17] Cervesato I., Pfenning F., A linear spine calculus, Journal of Logic and Computation, 2003, 13(5), 639-688, DOI: 10.1093/logcom/ 13.5.63910.1093/logcom/13.5.639Search in Google Scholar

[18] Harper R., Honsell F., Plotkin G., A framework for defining logics, J. ACM, 1993, 40(1), 143-184, DOI: 10.1145/138027.13806010.1145/138027.138060Search in Google Scholar

[19] Ziliani B., Sozeau M., A comprehensible guide to a new unifier for CIC including universe polymorphism and overloading, Journal of Functional Programming, 2017, 27, e10, DOI: 10.1017/S095679681700002810.1017/S0956796817000028Search in Google Scholar

[20] Löh A., McBride C., Swierstra W., A tutorial implementation of a dependently typed lambda calculus, Fundamenta Informaticae, Special Issue on Dependently Typed Programming, 2010, 102(2), 177-207, DOI: 10.3233/FI-2010-30410.3233/FI-2010-304Search in Google Scholar

[21] Gundry A. M., Type inference, Haskell and dependent types, Ph.D. thesis, University of Strathclyde, Glasgow, Scotland, United Kingdom, 2013, http://adam.gundry.co.uk/pub/thesis/thesis-2013-12-03.pdfSearch in Google Scholar

[22] Gundry A., McBride C., A tutorial implementation of dynamic pattern unification, Unpublished draft, http://adam.gundry.co.uk/pub/pattern-unify/pattern-unification-2012-07-10.pdf, 2013Search in Google Scholar

[23] Cockx J., Devriese D., Proof-relevant unification: Dependent pattern matching with only the axioms of your type theory, Journal of Functional Programming, 2018, 28, e12, DOI: 10.1017/S095679681800014X10.1017/S095679681800014XSearch in Google Scholar

[24] Chen S., Erwig M., Walkingshaw E., An error-tolerant type system for variational lambda calculus, in: Proceedings of the 17th ACM SIGPLAN International Conference on Functional Programming (ICFP ’12), ACM, New York, NY, USA, 2012, 29-40, DOI: 10.1145/2364527.236453510.1145/2364527.2364535Search in Google Scholar

[25] Erwig M.,WalkingshawE., The choice calculus: A representation for software variation, ACM Trans. Softw. Eng. Methodol., 2011, 21(1), Article 6, DOI: 10.1145/2063239.206324510.1145/2063239.2063245Search in Google Scholar

[26] Chen S., Erwig M., Walkingshaw E., Extending type inference to variational programs, ACM Trans. Program. Lang. Syst., 2014, 36(1), Article 1, DOI: 10.1145/251819010.1145/2518190Search in Google Scholar

[27] Eremondi J., Github repository: lambda-pi-constraint, tag thesis-final, 2016, https://github.com/JoeyEremondi/lambdapi-constraintSearch in Google Scholar

[28] Zhang D.,Myers A. C., Vytiniotis D., Peyton-Jones S., Diagnosing type errors with class, In: Proceedings of the 36th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 2015), ACM, New York, NY, USA, 2015, 12-21, DOI: 10.1145/2737924.273800910.1145/2737924.2738009Search in Google Scholar

[29] Huet G. P., The undecidability of unification in third order logic, Information and Control, 1973, 22(3), 257-267, DOI: 10.1016/S0019-9958(73)90301-X10.1016/S0019-9958(73)90301-XSearch in Google Scholar

[30] Huet G., A unification algorithm for typed λ-calculus, Theoretical Computer Science, 1975, 1(1), 27-57, DOI: 10.1016/0304-3975(75)90011-010.1016/0304-3975(75)90011-0Search in Google Scholar

[31] Cockx J., Devriese D., Piessens F., Pattern matching without K, In: Proceedings of the 19th ACM SIGPLAN International Conference on Functional Programming (ICFP ’14), ACM, New York, NY, USA, 2014, 257-268, DOI: 10.1145/2628136.262813910.1145/2628136.2628139Search in Google Scholar

[32] Cockx J., Devriese D., Piessens F., Unifiers as equivalences: Proof-relevant unification of dependently typed data, In: Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming (ICFP 2016), ACM, New York, NY, USA, 2016, 270-283, DOI: 10.1145/2951913.295191710.1145/2951913.2951917Search in Google Scholar

[33] Eremondi J., Improving error messages for dependent types with constraint-based unification, Master’s thesis, Utrecht University, Utrecht, Netherlands, 2016, https://dspace.library.uu.nl/handle/1874/337692Search in Google Scholar

[34] Campora J. P., Chen S., Erwig M., Walkingshaw E., Migrating gradual types, Proceedings of the ACM on Programming Languages, 2018, 2(POPL), Article 15, DOI: 10.1145/315810310.1145/3158103Search in Google Scholar

[35] Milner R., A theory of type polymorphism in programming, Journal of Computer and System Sciences, 1978, 17(3), 348-375, DOI: 10.1016/0022-0000(78)90014-410.1016/0022-0000(78)90014-4Search in Google Scholar

[36] Hage J., Heeren B., Strategies for solving constraints in type and effect systems, Electronic Notes in Theoretical Computer Science, 2009, 236, 163-183, DOI:10.1016/j.entcs.2009.03.02110.1016/j.entcs.2009.03.021Search in Google Scholar

[37] Helium Team, Helium github repository, https://github.com/Helium4Haskell/helium, 2017Search in Google Scholar

[38] Pavlinovic Z., King T., Wies T., Practical SMT-based type error localization, In: Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming (ICFP’15), ACM, New York, NY, USA, 2015, 412-423, DOI: 10.1145/2784731.2784765.10.1145/2784731.2784765Search in Google Scholar

Received: 2018-06-29
Accepted: 2018-10-31
Published Online: 2019-01-24

© 2019 Joseph Eremondi et al., published by De Gruyter Open

This work is licensed under the Creative Commons Attribution 4.0 Public License.

Downloaded on 10.12.2022 from https://www.degruyter.com/document/doi/10.1515/comp-2019-0001/html
Scroll Up Arrow