Abstract
Many languages have support for automatic type inference. But when inference fails, the reported error messages can be unhelpful, highlighting a code location far from the source of the problem. Several lines of work have emerged proposing error reports derived from correcting sets: a set of program points that, when fixed, produce a well-typed program. Unfortunately, these approaches are tightly tied to specific languages; targeting a new language requires encoding a type inference algorithm for the language in a custom constraint system specific to the error reporting tool.
We show how to produce correcting set-based error reports by leveraging existing type inference implementations, easing the burden of adoption and, as type inference algorithms tend to be efficient in practice, producing error reports of comparable quality to similar error reporting tools orders of magnitude faster. Many type inference algorithms are already formulated as dual phases of type constraint generation and solving; rather than (re)implementing type inference in an error explanation tool, we isolate the solving phase and treat it as an oracle for solving typing constraints. Given any set of typing constraints, error explanation proceeds by iteratively removing conflicting constraints from the initial constraint set until discovering a subset on which the solver succeeds; the constraints removed form a correcting set. Our approach is agnostic to the semantics of any particular language or type system, instead leveraging the existing type inference engine to give meaning to constraints.
- Alexander Aiken and Edward L. Wimmers. Type inclusion constraints and type inference. In Proceedings of the Conference on Functional Programming Languages and Computer Architecture, FPCA ’93, pages 31–41, New York, NY, USA, 1993. ACM. Google Scholar
Digital Library
- R. Bruttomesso, E. Pek, and N. Sharygina. A flexible schema for generating explanations in lazy theory propagation. In Formal Methods and Models for Codesign (MEMOCODE), 2010 8th IEEE/ACM International Conference on, pages 41– 48, July 2010.Google Scholar
Digital Library
- Satish Chandra, Colin S. Gordon, Jean-Baptiste Jeannin, Cole Schlesinger, Manu Sridharan, Frank Tip, and Young-il Choi. Type inference for static compilation of JavaScript. In Proceedings of the 2016 ACM International Conference on Object Oriented Programming Systems Languages & Applications, OOPSLA ’16, New York, NY, USA, 2016. ACM. Google Scholar
Digital Library
- Sheng Chen and Martin Erwig. Counter-factual typing for debugging type errors. In Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’14, pages 583–594, New York, NY, USA, 2014. ACM. Google Scholar
Digital Library
- Wontae Choi, Satish Chandra, George C. Necula, and Koushik Sen. SJS: A type system for JavaScript with fixed object layout. In Sandrine Blazy and Thomas Jensen, editors, Static Analysis - 22nd International Symposium, SAS 2015, Saint-Malo, France, September 9-11, 2015, Proceedings, volume 9291 of Lecture Notes in Computer Science, pages 181–198. Springer, 2015.Google Scholar
- Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, Third Edition. The MIT Press, 3rd edition, 2009. Google Scholar
Digital Library
- Luis Damas and Robin Milner. Principal type-schemes for functional programs. In Proceedings of the 9th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’82, pages 207–212, New York, NY, USA, 1982. ACM. Google Scholar
Digital Library
- Manuel Fähndrich, Jakob Rehof, and Manuvir Das. Scalable context-sensitive flow analysis using instantiation constraints. In Proceedings of the ACM SIGPLAN 2000 Conference on Programming Language Design and Implementation, PLDI ’00, pages 253–263, New York, NY, USA, 2000. ACM. Google Scholar
Digital Library
- Zhaohui Fu and Sharad Malik. On solving the Partial MAXSAT problem. In Armin Biere and Carla P. Gomes, editors, Theory and Applications of Satisfiability Testing - SAT 2006, volume 4121 of Lecture Notes in Computer Science, pages 252–265. Springer Berlin Heidelberg, 2006. Google Scholar
Digital Library
- Harald Ganzinger, George Hagen, Robert Nieuwenhuis, Albert Oliveras, and Cesare Tinelli. Computer Aided Verification: 16th International Conference, CAV 2004, Boston, MA, USA, July 13-17, 2004. Proceedings, chapter DPLL(T): Fast Decision Procedures, pages 175–188. Springer Berlin Heidelberg, Berlin, Heidelberg, 2004.Google Scholar
- Christian Haack and J. B. Wells. Type error slicing in implicitly typed higher-order languages. In Proceedings of the 12th European Conference on Programming, ESOP’03, pages 284– 301, Berlin, Heidelberg, 2003. Springer-Verlag. Google Scholar
Digital Library
- Fritz Henglein. Type inference with polymorphic recursion. ACM Trans. Program. Lang. Syst., 15(2):253–289, April 1993. Google Scholar
Digital Library
- Ulrich Junker. QUICKXPLAIN: Preferred explanations and relaxations for over-constrained problems. In Proceedings of the 19th National Conference on Artifical Intelligence, AAAI’04, pages 167–172. AAAI Press, 2004. Google Scholar
Digital Library
- Richard M. Karp. Complexity of Computer Computations: Proceedings of a symposium on the Complexity of Computer Computations, chapter Reducibility among Combinatorial Problems, pages 85–103. Springer US, Boston, MA, 1972.Google Scholar
- A. J. Kfoury, J. Tiuryn, and P. Urzyczyn. An analysis of ML typability. J. ACM, 41(2):368–398, March 1994. Google Scholar
Digital Library
- Daniel Le Berre and Anne Parrain. The Sat4j library, release 2.2, system description. Journal on Satisfiability, Boolean Modeling and Computation, 7:59–64, 2010.Google Scholar
Cross Ref
- Benjamin S. Lerner, Matthew Flower, Dan Grossman, and Craig Chambers. Searching for type-error messages. In Proceedings of the 28th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI ’07, pages 425–434, New York, NY, USA, 2007. ACM. Google Scholar
Digital Library
- Martin Odersky, Martin Sulzmann, and Martin Wehr. Type inference with constrained types. Theor. Pract. Object Syst., 5(1):35–55, January 1999. Google Scholar
Digital Library
- Yutaka Oiwa and Eijiro Sumii. min-rt. https://github. com/esumii/min-caml/blob/master/min-rt.Google Scholar
- Zvonimir Pavlinovic, Tim King, and Thomas Wies. Finding minimum type error sources. In Proceedings of the 2014 ACM International Conference on Object Oriented Programming Systems Languages & Applications, OOPSLA ’14, pages 525– 542, New York, NY, USA, 2014. ACM. Google Scholar
Digital Library
- Zvonimir Pavlinovic, Tim King, and Thomas Wies. Practical SMT-based type error localization. In Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming, ICFP 2015, pages 412–423, New York, NY, USA, 2015. ACM. Google Scholar
Digital Library
- François Pottier and Didier Rémy. The essence of ML type inference. In Benjamin Pierce, editor, Advanced Types and Programming Languages. MIT Press, 2005.Google Scholar
- Didier Rémy. Extending ML type system with a sorted equational theory. Technical report, Research Report 1766, Institut National de Recherche en Informatique et Automatisme, Rocquencourt, BP 105, 78 153 Le Chesnay Cedex, France, 1992.Google Scholar
- Eric L. Seidel, Ranjit Jhala, and Westley Weimer. Dynamic witnesses for static type errors. CoRR, abs/1606.07557, 2016. Google Scholar
Digital Library
- Martin Sulzmann, Martin Müller, and Christoph Zenger. Hindley/Milner style type systems in constraint form. Technical report, 1999.Google Scholar
- Danfeng Zhang and Andrew C. Myers. Toward general diagnosis of static errors. In Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’14, pages 569–581, New York, NY, USA, 2014. ACM. Google Scholar
Digital Library
- Danfeng Zhang, Andrew C. Myers, Dimitrios Vytiniotis, and Simon Peyton-Jones. Diagnosing type errors with class. In Proceedings of the 36th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2015, pages 12–21, New York, NY, USA, 2015. ACM. Google Scholar
Digital Library
Index Terms
A practical framework for type inference error explanation
Recommendations
A practical framework for type inference error explanation
OOPSLA 2016: Proceedings of the 2016 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and ApplicationsMany languages have support for automatic type inference. But when inference fails, the reported error messages can be unhelpful, highlighting a code location far from the source of the problem. Several lines of work have emerged proposing error ...
Kinded type inference for parameteric overloading
AbstractParameteric overloading refers to the combination of parameteric polymorphism and overloading of polymorphic operators. The formal basis for parametric overloading, proposed by Kaes and extended by Wadler and Blott, is based on type predicates. In ...
Polymorphic type inference and abstract data types
Many statically typed programming languages provide an abstract data type construct, such as the module in Modula-2. However, in most of these languages, implementations of abstract data types are not first-class values. Thus, they cannot be assigned to ...







Comments