Chapter

Functional and Logic Programming

Volume 8475 of the series Lecture Notes in Computer Science pp 136-151

Generic Programming with Multiple Parameters

  • José Pedro MagalhãesAffiliated withDepartment of Computer Science, University of Oxford

* Final gross prices may vary according to local VAT.

Get Access

Abstract

Generic programming, a form of abstraction in programming languages that serves to reduce code duplication by exploiting the regular structure of algebraic datatypes, has been present in the Haskell language in different forms for many years. Lately, a library for generic deriving has been given native support in the compiler, allowing programmers to write functions such as fmap that abstract over one datatype parameter generically. The power of this approach is limited to dealing with one parameter per datatype, however. In this paper, we lift this restriction by providing a generalisation of generic deriving that supports multiple parameters, making essential use of datatype promotion and kind polymorphism. We show example encodings of datatypes, and how to define a map function that operates on multiple parameters simultaneously.