A framework for improving error messages in dependently-typed languages

Joseph Eremondi 1 , Wouter Swierstra 2  and Jurriaan Hage 3
  • 1 University of British Columbia,, Vancouver, Canada
  • 2 Utrecht University,, Utrecht, Netherlands
  • 3 Utrecht University,, Utrecht, Netherlands

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.

If the inline PDF is not rendering correctly, you can download the PDF file here.

  • [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.59

  • [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.html

  • [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_12

  • [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/7297

  • [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.2535863

  • [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.1481862

  • [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/S095679681300018X

  • [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.004

  • [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/3121137

  • [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-86

  • [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)

  • [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.pdf

  • [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-4

  • [14] Miller D., Unification under a mixed prefix, J. Symb. Comput., 1992, 14(4), 321-358, DOI: 10.1016/0747-7171(92)90011-R

  • [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_5

  • [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.pdf

  • [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.639

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

  • [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/S0956796817000028

  • [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-304

  • [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.pdf

  • [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, 2013

  • [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/S095679681800014X

  • [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.2364535

  • [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.2063245

  • [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/2518190

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

  • [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.2738009

  • [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-X

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

  • [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.2628139

  • [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.2951917

  • [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/337692

  • [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/3158103

  • [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-4

  • [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.021

  • [37] Helium Team, Helium github repository, https://github.com/Helium4Haskell/helium, 2017

  • [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.

OPEN ACCESS

Journal + Issues

Open Computer Science is an open access, peer-reviewed journal. The journal publishes research results in the following fields: algorithms and complexity theory, artificial intelligence, bioinformatics, networking and security systems,
programming languages, system and software engineering, and theoretical foundations of computer science.

Search