Principal type inference for GADTs

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.

[1]  B. Pierce Programming with intersection types, union types, and polymorphism , 1991 .

[2]  Simon L. Peyton Jones,et al.  Complete and decidable type inference for GADTs , 2009, ICFP.

[3]  Norman Ramsey,et al.  On teaching *how to design programs*: observations from a newcomer , 2014, ICFP 2014.

[4]  Stephanie Weirich Depending on types , 2014, ICFP.

[5]  James Cheney,et al.  A lightweight implementation of generics and dynamics , 2002, Haskell '02.

[6]  François Pottier,et al.  A constraint-based approach to guarded algebraic data types , 2007, TOPL.

[7]  Nathan Mishra-Linger,et al.  Programming in Omega , 2008, CEFP.

[8]  Tim Sheard,et al.  Generic Programming in Ωmega , 2006, SSDGP.

[9]  Benjamin C. Pierce,et al.  Types and programming languages: the next generation , 2003, 18th Annual IEEE Symposium of Logic in Computer Science, 2003. Proceedings..

[10]  Sebastian Erdweg,et al.  Variability-aware parsing in the presence of lexical macros and conditional compilation , 2011, OOPSLA '11.

[11]  Martin Erwig,et al.  Guided Type Debugging , 2014, FLOPS.

[12]  Umut A. Acar,et al.  Extensible programming with first-class cases , 2006, ICFP '06.

[13]  Matthias Felleisen,et al.  How to Design Programs , 2001 .

[14]  Alan Mycroft,et al.  Polymorphic Type Schemes and Recursive Definitions , 1984, Symposium on Programming.

[15]  Jerzy Tiuryn,et al.  Type reconstruction in the presence of polymorphic recursion , 1993, TOPL.

[16]  Gang Chen,et al.  Guarded recursive datatype constructors , 2003, POPL '03.

[17]  Tim Sheard,et al.  Pointwise generalized algebraic data types , 2010, TLDI '10.

[18]  Tim Sheard,et al.  Practical type inference for the gadt type system , 2010 .

[19]  Simon Peyton Jones,et al.  Wobbly types: type inference for generalised algebraic data types∗ , 2004 .

[20]  Peter J. Stuckey,et al.  Type inference for GADTs via Herbrand constraint abduction , 2008 .

[21]  Robin Milner,et al.  Principal type-schemes for functional programs , 1982, POPL '82.

[22]  Didier Rémy,et al.  Ambivalent Types for Principal Type Inference with GADTs , 2013, APLAS.

[23]  Yann Régis-Gianas,et al.  Stratified type inference for generalized algebraic data types , 2006, POPL '06.

[24]  Simon L. Peyton Jones,et al.  OutsideIn(X) Modular type inference with local assumptions , 2011, J. Funct. Program..

[25]  Martin Erwig,et al.  Counter-factual typing for debugging type errors , 2014, POPL.

[26]  Simon L. Peyton Jones,et al.  Simple unification-based type inference for GADTs , 2006, ICFP '06.

[27]  Martin Odersky,et al.  Type Inference with Constrained Types , 1999, Theory Pract. Object Syst..

[28]  Martin Erwig,et al.  Extending Type Inference to Variational Programs , 2014, ACM Trans. Program. Lang. Syst..

[29]  Sven Apel,et al.  Scalable analysis of variable software , 2013, ESEC/FSE 2013.

[30]  Sergei G. Vorobyov An Improved Lower Bound for the Elementary Theories of Trees , 1996, CADE.

[31]  Simon L. Peyton Jones,et al.  GADTs meet their match: pattern-matching warnings that account for GADTs, guards, and laziness , 2015, ICFP.

[32]  Fritz Henglein,et al.  Type inference with polymorphic recursion , 1993, TOPL.

[33]  Peter J. Stuckey,et al.  Type Inference for Guarded Recursive Data Types , 2005, ArXiv.

[34]  Martin Erwig,et al.  An error-tolerant type system for variational lambda calculus , 2012, ICFP.

[35]  Chuan-Kai Lin,et al.  Programming monads operationally with Unimo , 2006, ICFP '06.