Type Inference, Haskell and Dependent Types

Adam Gundry

This thesis studies questions of type inference, unification and elaboration for languages that combine dependent type theory and functional programming. Languages such as modern Haskell have very expressive type systems, allowing the programmer a great deal of freedom. These require advanced type inference and unification algorithms to reconstruct details that were left implicit, and suitable representation of the evidence delivered by such algorithms.

The first part proposes an approach to unification and type inference, based on information increase in dependency-ordered contexts, and keeping careful track of variable scope. Two existing systems are reviewed: the Hindley-Milner type system, and units of measure in the style of Kennedy. Subtle issues relating to let-generalisation become clearer as a result. Using the same approach, an algorithm is described for Miller pattern unification in a full-spectrum dependent type theory, forming a foundation for the elaboration of dependently typed languages.

The second part introduces inch, a language that extends Haskell with type-level data and functions, and dependent product types. Type-level numbers and arithmetic operations are specifically considered, as a particularly useful source of applications, such as the perennial example of vectors (length-indexed lists). The increased expressivity in the source language is matched by a suitable core language of evidence, into which inch programs can be translated. This language is based on System FC, the existing core language used by GHC, and adapted to clarify the relationships between the type and term levels. It gives a coherent operational semantics to both levels, allowing shared data and dependent functions, but retaining a clear phase distinction. The contextual approach of the first part of the thesis is used to specify the elaboration of inch into the evidence language, and applications of inch based on type-level arithmetic are demonstrated.

Important note: there is an error in the pattern unification algorithm described in Chapter 4; see the errata, updated 9th August 2014

Final accepted version: Type Inference, Haskell and Dependent Types, updated 3rd December 2013

Haskell code: type-inference on GitHub, prototype implementation of inch on GitHub

Up to Adam Gundry's home page