Departmental Papers (CIS)

Generic Programming with Dependent Types

Stephanie Weirich, University of Pennsylvania
Chris Casinghino, University of Pennsylvania

Document Type Journal Article

Stephanie Weirich and Chris Casignhino. Generic Programming with Dependent Types. In Jeremy Gibbons, editor, Generic and Indexed Programming, number 7470 in Lecture Notes in Computer Science, pages 217-258. Springer-Verlag Berlin Heidelberg, 2012.

J. Gibbons (Ed.): Generic and Indexed Programming, LNCS 7470, pp. 217–258, 2012. ©Springer-Verlag Berlin Heidelberg 2012


Some programs are doubly generic. For example, map is datatype-generic in that many different data structures support a mapping operation. A generic programming language like Generic Haskell can use a single definition to generate map for each type. However, map is also arity-generic because it belongs to a family of related operations that differ in the number of arguments. For lists, this family includes familiar functions from the Haskell standard library (such as repeat, map, and zipWith). This tutorial explores these forms of genericity individually and together. These two axes are not orthogonal: datatype-generic versions of repeat, map and zipWith have different arities of kind-indexed types. We explore these forms of genericity in the context of the Agda programming language, using the expressiveness of dependent types to capture both forms of genericity in a common framework. Therefore, this tutorial serves as an introduction to dependently typed languages as well as generic programming. The target audience of this work is someone who is familiar with functional programming languages, such as Haskell or ML, but would like to learn about dependently typed languages. We do not assume prior experience with Agda, type- or arity-generic programming.


Date Posted: 24 July 2012