derivable type classes

Can a user define a derivable type class of her own? If yes, how? Cheers, -- Ozgur Akgun

Ozgur Akgun
Can a user define a derivable type class of her own? No.
The derivable classes are defined in the Haskell Report; GHC does allow some others to be derived with extensions however. There is one exception to this: using the GeneralizedNewtypeDeriving extension, if type Foo instantiates a typeclass Baz, then you can derive Baz for newtype Bar = Bar Foo. -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

No. A solution for this (depending on the type class you want to derive) is Generic Programming. Using Generic Programming, you can define functions that work on the structure of the type. For example, take a look at the regular package [1]. It provides all the functionality to write your own generic functions. -chris [1]: http://hackage.haskell.org/package/regular On 23 mrt 2010, at 11:52, Ozgur Akgun wrote:
Can a user define a derivable type class of her own? If yes, how?
Cheers,
-- Ozgur Akgun _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Tue, Mar 23, 2010 at 11:52 AM, Ozgur Akgun
Can a user define a derivable type class of her own? If yes, how?
GHC has a feature which lets you define classes such that making an instance of them is as easy as deriving. It's called Generic classes. See GHC's documentation for the details: http://www.haskell.org/ghc/docs/latest/html/users_guide/generic-classes.html Hth, Josef

Thanks for the pointers again - you are of great help every time!
On 23 March 2010 17:44, Josef Svenningsson
On Tue, Mar 23, 2010 at 11:52 AM, Ozgur Akgun
wrote: Can a user define a derivable type class of her own? If yes, how?
GHC has a feature which lets you define classes such that making an instance of them is as easy as deriving. It's called Generic classes. See GHC's documentation for the details:
http://www.haskell.org/ghc/docs/latest/html/users_guide/generic-classes.html
Hth,
Josef
-- Ozgur Akgun
participants (4)
-
Chris Eidhof
-
Ivan Lazar Miljenovic
-
Josef Svenningsson
-
Ozgur Akgun