Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deriving arbitrary functions in Haskell

When working with derived instances in Haskell, is it possible to derive functions for arbitrary types, or are we restricted to particular functions?

like image 733
Casebash Avatar asked Mar 13 '10 01:03

Casebash


1 Answers

You can derive instances of the following classes in haskell 98: Eq, Ord, Enum, Ix, Bounded, Read, and Show.

Using ghc extensions you can also derive instances of the following classes: Typeable, Data, Functor, Foldable and Traversable. There's also a ghc extension that allows a newtype to derive instances from its implementation type.

You can not derive instances of arbitrary classes for the simple reason that haskell would not know how to generate the necessary functions without special knowledge about the class in question.

like image 106
sepp2k Avatar answered Oct 25 '22 04:10

sepp2k