Scrap more boilerplate: reflection, zips, and generalised casts

  • Authors:
  • Ralf Lämmel;Simon Peyton Jones

  • Affiliations:
  • Vrije Universiteit & CWI, Amsterdam;Microsoft Research, Cambridge

  • Venue:
  • Proceedings of the ninth ACM SIGPLAN international conference on Functional programming
  • Year:
  • 2004

Quantified Score

Hi-index 0.00

Visualization

Abstract

Writing boilerplate code is a royal pain. Generic programming promises to alleviate this pain by allowing the programmer to write a generic "recipe" for boilerplate code, and use that recipe in many places. In earlier work we introduced the "Scrap your boilerplate" approach to generic programming, which exploits Haskell's existing type-class mechanism to support generic transformations and queries.This paper completes the picture. We add a few extra "introspective" or "reflective" facilities, that together support a rich variety of serialisation and de-serialisation. We also show how to perform generic "zips", which at first appear to be somewhat tricky in our framework. Lastly, we generalise the ability to over-ride a generic function with a type-specific one.All of this can be supported in Haskell with independently-useful extensions: higher-rank types and type-safe cast. The GHC implementation of Haskell readily derives the required type classes for user-defined data types.