Derivable type classes
September 2000Derivable type classesDerivable type classes
This paper presents an approach for introducing generic programming to the Haskell language. Since Haskell’s first specification, it has always been possible to let the compiler automatically generate “obvious” instances — however, this feature known as stock deriving supported only a handful of pre-defined classes. This new idea would allow users who write their own typeclasses to also specify implicit implementations that work for any datatype.
The main contribution generic functions, a new sort of default class method that can describe very generally how to handle sum and product datatypes. The paper’s first example shows how Eq
deriving could be defined by writing (==)
as a generic function:
This feature first appears in GHC 5.00.
Authors: Ralf Hinze and Simon Peyton Jones