Practical generic programming in OCaml

  • Authors:
  • Jeremy Yallop

  • Affiliations:
  • LFCS: University of Edinburgh, Edinburgh, United Kngdm

  • Venue:
  • ML '07 Proceedings of the 2007 workshop on Workshop on ML
  • Year:
  • 2007

Quantified Score

Hi-index 0.00

Visualization

Abstract

We describe deriving, a system of extensible generic functions for OCaml implemented as a preprocessor and supporting library. We argue that generating code from type-definitions has significant advantages over a combinator approach, taking serialisation as an example application: our generate-your-boilerplate design results in a system that is easy to use, has comprehensive coverage of types and handles cyclic values without imposing a burden on the user. Users can extend generic functions with specialised implementations at particular types; we show how this can lead to dramatically improved performance in the serialisation task without the user writing a single line of serialisation code.