Abstract
We present a new method for GADT type inference that improves the precision of previous approaches. In particular, our approach accepts more type-correct programs than previous approaches when they do not employ type annotations. A side benefit of our approach is that it can detect a wide range of runtime errors that are missed by previous approaches. Our method is based on the idea to represent type refinements in pattern-matching branches by choice types, which facilitate a separation of the typing and reconciliation phases and thus support case expressions. This idea is formalized in a type system, which is both sound and a conservative extension of the classical Hindley-Milner system. We present the results of an empirical evaluation that compares our algorithm with previous approaches.
- M. Blume, U. A. Acar, and W. Chae. Extensible programming with first-class cases. In ACM SIGPLAN International Conference on Functional Programming, pages 239–250, 2006. Google Scholar
Digital Library
- S. Chen and M. Erwig. Counter-factual typing for debugging type errors. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 583–594, 2014. Google Scholar
Digital Library
- S. Chen and M. Erwig. Guided type debugging. In Functional and Logic Programming, LNCS 8475, pages 35–51. 2014.Google Scholar
- S. Chen, M. Erwig, and E. Walkingshaw. An error-tolerant type system for variational lambda calculus. In ACM SIGPLAN International Conference on Functional Programming, pages 29–40, 2012. Google Scholar
Digital Library
- S. Chen, M. Erwig, and E. Walkingshaw. Extending type inference to variational programs. ACM Trans. Program. Lang. Syst., 36(1):1:1– 1:54, Mar. 2014. Google Scholar
Digital Library
- J. Cheney and R. Hinze. A lightweight implementation of generics and dynamics. In ACM SIGPLAN Workshop on Haskell, pages 90– 104, 2002. Google Scholar
Digital Library
- L. Damas and R. Milner. Principal Type-Schemes for Functional Programs. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 207–212, 1982. Google Scholar
Digital Library
- M. Felleisen, R. B. Findler, M. Flatt, and S. Krishnamurthi. How to design programs. MIT Press Cambridge, 2001.Google Scholar
- J. Garrigue and J. L. Normand. Adding gadts to ocaml: the direct approach. In Workshop on ML, 2011.Google Scholar
- J. Garrigue and D. Rémy. Ambivalent types for principal type inference with GADTs. In Programming Languages and Systems, LNCS 8301, pages 257–272. 2013. Google Scholar
Digital Library
- F. Henglein. Type inference with polymorphic recursion. ACM Trans. Program. Lang. Syst., 15(2):253–289, Apr. 1993. Google Scholar
Digital Library
- G. Karachalias, T. Schrijvers, D. Vytiniotis, and S. P. Jones. Gadts meet their match: Pattern-matching warnings that account for gadts, guards, and laziness. In ACM SIGPLAN International Conference on Functional Programming, pages 424–436, 2015. Google Scholar
Digital Library
- C. Kästner, P. G. Giarrusso, T. Rendel, S. Erdweg, K. Ostermann, and T. Berger. Variability-Aware Parsing in the Presence of Lexical Macros and Conditional Compilation. In ACM SIGPLAN Int. Conf. on Object-Oriented Programming, Systems, Languages, and Applications, pages 805–824, 2011. Google Scholar
Digital Library
- A. J. Kfoury, J. Tiuryn, and P. Urzyczyn. Type reconstruction in the presence of polymorphic recursion. ACM Trans. Program. Lang. Syst., 15(2):290–311, Apr. 1993. Google Scholar
Digital Library
- J. Liebig, A. von Rhein, C. Kästner, S. Apel, J. Dörre, and C. Lengauer. Scalable analysis of variable software. In Foundations of Software Engineering, pages 81–91, 2013. Google Scholar
Digital Library
- C.-k. Lin. Programming monads operationally with unimo. In ACM SIGPLAN International Conference on Functional Programming, pages 274–285, 2006. Google Scholar
Digital Library
- C.-k. Lin. Practical Type Inference for the GADT Type System. PhD thesis, Portland State University, 2010. Google Scholar
Digital Library
- C.-k. Lin and T. Sheard. Pointwise generalized algebraic data types. In ACM SIGPLAN Workshop on Types in Language Design and Implementation, pages 51–62, 2010. Google Scholar
Digital Library
- A. Mycroft. Polymorphic type schemes and recursive definitions. In International Symposium on Programming, LNCS 167, pages 217– 228, 1984. Google Scholar
Digital Library
- M. Odersky, M. Sulzmann, and M. Wehr. Type Inference with Constrained Types. Theory and Practice of Object Systems, 5(1):35–55, 1999. Google Scholar
Digital Library
- S. Peyton Jones, D. Vytiniotis, S. Weirich, and G. Washburn. Simple unification-based type inference for GADTs. In ACM SIGPLAN International Conference on Functional Programming, pages 50–61, 2006. Google Scholar
Digital Library
- S. Peyton Jones, G. Washburn, and S. Weirich. Wobbly types: type inference for generalised algebraic data types. Technical Report MSCIS-05-26, University of Pennsylvania, July 2004.Google Scholar
- B. C. Pierce. Programming with intersection types, union types, and polymorphism. Technical Report CMU-CS-91-106, School of Computer Science, Carnegie Mellon University, 1991.Google Scholar
- B. C. Pierce. Types and Programming Languages. MIT Press, 2002. Google Scholar
Digital Library
- F. Pottier and Y. Régis-Gianas. Stratified type inference for generalized algebraic data types. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 232–244, 2006. Google Scholar
Digital Library
- N. Ramsey. On teaching *how to design programs*: Observations from a newcomer. In ACM SIGPLAN International Conference on Functional Programming, pages 153–166, 2014. Google Scholar
Digital Library
- T. Schrijvers, S. Peyton Jones, M. Sulzmann, and D. Vytiniotis. Complete and decidable type inference for GADTs. In ACM SIGPLAN International Conference on Functional Programming, pages 341–352, 2009. Google Scholar
Digital Library
- T. Sheard. Generic programming in Omega. In Datatype-Generic Programming, LNCS 4719, pages 258–284, 2006.Google Scholar
- T. Sheard and N. Linger. Programming in Omega. In CEFP, LNCS 5161, pages 158–227, 2007.Google Scholar
- V. Simonet and F. Pottier. A constraint-based approach to guarded algebraic data types. ACM Trans. on Programming Languages and Systems, 29(1):1–38, 2007. Google Scholar
Digital Library
- P. J. Stuckey and M. Sulzmann. Type inference for guarded recursive data types. CoRR, abs/cs/0507037:1–15, 2005.Google Scholar
- M. Sulzmann, T. Schrijvers, and P. J. Stuckey. Type inference for GADTs via Herbrand constraint abduction. Technical Report CW507, University of Leuven, January 2008.Google Scholar
- S. Vorobyov. An improved lower bound for the elementary theories of trees. In International Conference on Automated Deduction, LNCS 1104, pages 275–287. 1996. Google Scholar
Digital Library
- D. Vytiniotis, S. Peyton Jones, T. Schrijvers, and M. Sulzmann. Outsidein(x) modular type inference with local assumptions. Journal of Functional Programming, 21(4-5):333–412, Sept. 2011. Google Scholar
Digital Library
- S. Weirich. Depending on types. In ACM SIGPLAN International Conference on Functional Programming, pages 241–241, 2014. Google Scholar
Digital Library
- H. Xi, C. Chen, and G. Chen. Guarded recursive datatype constructors. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 224–235, 2003. Google Scholar
Digital Library
Index Terms
Principal type inference for GADTs
Recommendations
Principal type inference for GADTs
POPL '16: Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming LanguagesWe present a new method for GADT type inference that improves the precision of previous approaches. In particular, our approach accepts more type-correct programs than previous approaches when they do not employ type annotations. A side benefit of our ...
Simple unification-based type inference for GADTs
Proceedings of the 2006 ICFP conferenceGeneralized algebraic data types (GADTs), sometimes known as "guarded recursive data types" or "first-class phantom types", are a simple but powerful generalization of the data types of Haskell and ML. Recent works have given compelling examples of the ...
Complete and decidable type inference for GADTs
ICFP '09GADTs have proven to be an invaluable language extension, for ensuring data invariants and program correctness among others. Unfortunately, they pose a tough problem for type inference: we lose the principal-type property, which is necessary for modular ...






Comments