Algebraic Specialization of Generic Functions for Recursive Types

  • Authors:
  • Alcino Cunha;Hugo Pacheco

  • Affiliations:
  • Dep. de Informática (Centro de Ciências e Tecnologias da Computação), Universidade do Minho, Campus de Gualtar, P-4710-057, Braga, Portugal;Dep. de Informática (Centro de Ciências e Tecnologias da Computação), Universidade do Minho, Campus de Gualtar, P-4710-057, Braga, Portugal

  • Venue:
  • Electronic Notes in Theoretical Computer Science (ENTCS)
  • Year:
  • 2011

Quantified Score

Hi-index 0.01

Visualization

Abstract

Defining functions over large, possibly recursive, data structures usually involves a lot of boilerplate. This code simply traverses non-interesting parts of the data, and rapidly becomes a maintainability problem. Many generic programming libraries have been proposed to address this issue. Most of them allow the user to specify the behavior just for the interesting bits of the structure, and provide traversal combinators to ''scrap the boilerplate''. The expressive power of these libraries usually comes at the cost of efficiency, since runtime checks are used to detect where to apply the type-specific behavior. In previous work we have developed an effective rewrite system for specialization and optimization of generic programs. In this paper we extend it to also cover recursive data types. The key idea is to specialize traversal combinators using well-known recursion patterns, such as folds or paramorphisms. These are ruled by a rich set of algebraic laws that enable aggressive optimizations. We present a type-safe encoding of this rewrite system in Haskell, based on recent language extensions such as type-indexed type families.