When working with derived instances in Haskell, is it possible to derive functions for arbitrary types, or are we restricted to particular functions?
When working with derived instances in Haskell, is it possible to derive functions for
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.