Instant Generics: Fast and Easy

This paper introduces a novel approach to datatype-generic programming based on type classes and type families. The approach favours simplicity as generic functions are based on Haskell’s standard construct for ad-hoc polymorphism, namely type classes — hence, it integrates well with existing classes and facilitates overriding of generic behaviour with conventional class instances. Moreover, our approach is expressive, as we demonstrate by an evaluation along the criteria of a set of standard benchmark problems for generic programming in Haskell. Beyond these benchmarks, which only cover type-indexed functions, we fully support typeindexed data types as well as a novel generic view, which we call the structural view. Finally, our approach is designed to lead to highly efficient code with no or little overhead compared to handwritten datatype-specific code. Both, support for type-indexed data types and high performance were crucial in our principal application: a self-optimising, high-performance array library for data parallel programming in Haskell.

[1]  Simon L. Peyton Jones,et al.  Scrap your boilerplate with class: extensible generic functions , 2005, ICFP '05.

[2]  Bruno C. d. S. Oliveira,et al.  Generics as a Library , 2006 .

[3]  Ralf Hinze,et al.  Polytypic values possess polykinded types , 2000, Sci. Comput. Program..

[4]  James Cheney,et al.  A lightweight implementation of generics and dynamics , 2002, Haskell '02.

[5]  Stephanie Weirich RepLib: a library for derivable type classes , 2006, Haskell '06.

[6]  Ralf Lämmel,et al.  A Strafunski Application Letter , 2003, PADL.

[7]  Paul Hudak,et al.  Parametric type classes , 1992, LFP '92.

[8]  Johan Jeuring,et al.  PolyP—a polytypic programming language extension , 1997, POPL '97.

[9]  Ralf Hinze,et al.  Type-indexed data types , 2004, Sci. Comput. Program..

[10]  Simon L. Peyton Jones,et al.  Data parallel Haskell: a status report , 2007, DAMP '07.

[11]  Bruno C. d. S. Oliveira,et al.  Comparing libraries for generic programming in haskell , 2008, Haskell '08.

[12]  Ralf Hinze Generics for the masses , 2006, J. Funct. Program..

[13]  Simon L. Peyton Jones,et al.  Harnessing the Multicores: Nested Data Parallelism in Haskell , 2008, FSTTCS.

[14]  Simon L. Peyton Jones,et al.  Type checking with open type functions , 2008, ICFP.

[15]  Simon L. Peyton Jones,et al.  Scrap more boilerplate: reflection, zips, and generalised casts , 2004, ICFP '04.

[16]  Philip Wadler,et al.  How to make ad-hoc polymorphism less ad hoc , 1989, POPL '89.

[17]  Simon L. Peyton Jones,et al.  Associated types with class , 2005, POPL '05.

[18]  Ralf Hinze,et al.  "Scrap Your Boilerplate" Revolutions , 2006, MPC.

[19]  S. Jones,et al.  A Transformation-Based Optimiser for Haskell , 1998, Sci. Comput. Program..

[20]  Simon L. Peyton Jones,et al.  Derivable Type Classes , 2001, Haskell.

[21]  Ralf Hinze,et al.  Comparing Approaches to Generic Programming in Haskell , 2006, SSDGP.

[22]  Bruno C. d. S. Oliveira,et al.  Extensible and modular generics for the masses , 2006, Trends in Functional Programming.

[23]  Johan Jeuring,et al.  Generic Views on Data Types , 2006, MPC.

[24]  Colin Runciman,et al.  Uniform boilerplate and list processing , 2007, Haskell '07.

[25]  Simon L. Peyton Jones,et al.  Template meta-programming for Haskell , 2002, Haskell '02.

[26]  Ralf Lämmel,et al.  Scrap your boilerplate: a practical approach to generic programming , 2003 .

[27]  Ralf Hinze,et al.  Generalizing generalized tries , 2000, Journal of Functional Programming.

[28]  Simon L. Peyton Jones,et al.  Associated type synonyms , 2005, ICFP '05.

[29]  Aarne Ranta,et al.  A pattern for almost compositional functions , 2008, J. Funct. Program..

[30]  Ulf Norell,et al.  Polytypic Programming in Haskell , 2003, IFL.

[31]  Simon L. Peyton Jones,et al.  Scrap Your Boilerplate , 2003, APLAS.