Generic programming for indexed datatypes

  • Authors:
  • José Pedro Magalhães;Johan Jeuring

  • Affiliations:
  • Utrecht University, Utrecht, Netherlands;Utrecht University & Open University of the Netherlands, Utrecht, Netherlands

  • Venue:
  • Proceedings of the seventh ACM SIGPLAN workshop on Generic programming
  • Year:
  • 2011

Quantified Score

Hi-index 0.00

Visualization

Abstract

An indexed datatype is a type that uses a parameter as a type-level tag; a typical example is the type of vectors, which are indexed over a type-level natural number encoding their length. Since the introduction of generalised algebraic datatypes, indexed datatypes have become commonplace in Haskell. Values of indexed datatypes are often more involved than values of plain datatypes, and programmers would benefit from having generic programs on indexed datatypes. However, no generic programming library adequately supports them, leaving programmers with the tedious task of writing repetitive code. We show how to encode indexed datatypes in a generic programming library with type families and type-level representations in Haskell. Our approach can also be used in similar libraries, and is fully backwards-compatible. We show not only how to encode indexed datatypes generically, but also how to instantiate generic functions on indexed datatypes. Furthermore, all generic representations and instances are generated automatically, making life easier for users.