OutsideIn(X)Modular type inference with local assumptions
Top Cited Papers
- 16 May 2011
- journal article
- research article
- Published by Cambridge University Press (CUP) in Journal of Functional Programming
- Vol. 21 (4-5), 333-412
- https://doi.org/10.1017/s0956796811000098
Abstract
Advanced type system features, such as GADTs, type classes and type families, have proven to be invaluable language extensions for ensuring data invariants and program correctness. Unfortunately, they pose a tough problem for type inference when they are used aslocaltype assumptions. Local type assumptions often result in the lack of principal types and cast the generalisation of local let-bindings prohibitively difficult to implement and specify. User-declared axioms only make this situation worse. In this paper, we explain the problems and – perhaps controversially – argue for abandoning local let-binding generalisation. We give empirical results that local let generalisation is only sporadically used by Haskell programmers. Moving on, we present a novel constraint-based type inference approach for local type assumptions. Our system, calledOutsideIn(X), is parameterised over the particular underlying constraint domain X, in the same way as HM(X). This stratification allows us to use a common metatheory and inference algorithm.OutsideIn(X)extends the constraints of X by introducing implication constraints on top. We describe the strategy for solving these implication constraints, which, in turn, relies on a constraint solver for X. We characterise the properties of the constraint solver for X so that the resulting algorithm only accepts programs with principal types, even when the type system specification accepts programs that do not enjoy principal types. Going beyond the general framework, we give a particular constraint solver for X = type classes + GADTs + type families, a non-trivial challenge in its own right. This constraint solver has been implemented and distributed as part of GHC 7.This publication has 31 references indexed in Scilit:
- A constraint-based approach to guarded algebraic data typesACM Transactions on Programming Languages and Systems, 2007
- Practical type inference for arbitrary-rank typesJournal of Functional Programming, 2007
- Understanding functional dependencies via constraint handling rulesJournal of Functional Programming, 2007
- A theory of overloadingACM Transactions on Programming Languages and Systems, 2005
- Theory and practice of constraint handling rulesThe Journal of Logic Programming, 1998
- Simple imperative polymorphismHigher-Order and Symbolic Computation, 1995
- Type Reconstruction for Type ClassesJournal of Functional Programming, 1995
- Polymorphic type inference and abstract data typesACM Transactions on Programming Languages and Systems, 1994
- Theorem proving using equational matings and rigid E -unificationJournal of the ACM, 1992
- A theory of type polymorphism in programmingJournal of Computer and System Sciences, 1978