A generic deriving mechanism for Haskell

Haskell's deriving mechanism supports the automatic generation of instances for a number of functions. The Haskell 98 Report only specifies how to generate instances for the Eq, Ord, Enum, Bounded, Show, and Read classes. The description of how to generate instances is largely informal. The generation of instances imposes restrictions on the shape of datatypes, depending on the particular class to derive. As a consequence, the portability of instances across different compilers is not guaranteed. We propose a new approach to Haskell's deriving mechanism, which allows users to specify how to derive arbitrary class instances using standard datatype-generic programming techniques. Generic functions, including the methods from six standard Haskell 98 derivable classes, can be specified entirely within Haskell 98 plus multi-parameter type classes, making them lightweight and portable. We can also express Functor, Typeable, and many other derivable classes with our technique. We implemented our deriving mechanism together with many new derivable classes in the Utrecht Haskell Compiler.

[1]  Alexander A. Stepanov,et al.  Generic Programming , 1988, ISSAC.

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

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

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

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

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

[7]  Andres Löh,et al.  Exploring generic Haskell , 2004 .

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

[9]  Marinus J. Plasmeijer,et al.  A Generic Programming Extension for Clean , 2001, IFL.

[10]  Manuel M. T. Chakravarty,et al.  Instant Generics: Fast and Easy , 2009 .

[11]  Johan Jeuring,et al.  Optimizing generics is easy! , 2010, PEPM '10.

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

[13]  Roland Carl Backhouse,et al.  Generic Programming: An Introduction , 1998, Advanced Functional Programming.

[14]  Peyton Jones,et al.  Haskell 98 language and libraries : the revised report , 2003 .

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

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

[17]  S. Doaitse Swierstra,et al.  The architecture of the Utrecht Haskell compiler , 2009, Haskell.

[18]  Mark P. Jones,et al.  Type Classes with Functional Dependencies , 2000, ESOP.

[19]  Gérard P. Huet,et al.  The Zipper , 1997, Journal of Functional Programming.

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