A generic deriving mechanism for Haskell
- 30 September 2010
- conference paper
- conference paper
- Published by Association for Computing Machinery (ACM) in Proceedings of the third ACM Haskell symposium on Haskell - Haskell '10
Abstract
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.Keywords
This publication has 12 references indexed in Scilit:
- The architecture of the Utrecht Haskell compilerPublished by Association for Computing Machinery (ACM) ,2009
- Generic programming in 3DScience of Computer Programming, 2009
- Comparing libraries for generic programming in haskellPublished by Association for Computing Machinery (ACM) ,2008
- Type checking with open type functionsPublished by Association for Computing Machinery (ACM) ,2008
- Scrap more boilerplatePublished by Association for Computing Machinery (ACM) ,2004
- Scrap your boilerplatePublished by Association for Computing Machinery (ACM) ,2003
- Template meta-programming for HaskellPublished by Association for Computing Machinery (ACM) ,2002
- Derivable Type ClassesElectronic Notes in Theoretical Computer Science, 2001
- The ZipperJournal of Functional Programming, 1997
- PolyP---a polytypic programming language extensionPublished by Association for Computing Machinery (ACM) ,1997