A generic deriving mechanism for Haskell
A generic deriving mechanism for Haskell
复制标题
Haskell 的通用派生机制
DOI:
10.1145/1863523.1863529
复制
发表时间:
2010
影响因子:
2.3
通讯作者:
Andres Löh
中科院分区:
文献类型:
--
作者:
José Pedro Magalhães;A. Dijkstra;J. Jeuring;Andres Löh
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.