[Haskell-cafe] Deriving

Johan Jeuring johanj at cs.uu.nl
Wed Dec 3 01:11:18 EST 2008


> What happens when a type adds driving such as:
>
> newtype SupplyT s m a = SupplyT (StateT [s] m a)
>
>     deriving (Functor, Monad, MonadTrans, MonadIO)
>
> Two questions:
>
> How does the deriving implement the instance?
>
> Is there a way for me to add  my own classes in the deriving?  for  
> example
>
> newtype .....
>    deriving( xyz)

In general you would have to resort to generic programming techniques
to obtain your own deriving mechanism.

See the generics category on Hackage for libraries:

http://hackage.haskell.org/packages/archive/pkg-list.html

To find out what you can do with the various generic programming
techniques, you can read (shameless plugs):

Alexey Rodriguez Yakushev, Johan Jeuring, Patrik Jansson, Alex Gerdes,
Oleg Kiselyov, Bruno C. d. S. Oliviera. Comparing Libraries for Generic
Programming in Haskell. In Andy Gill, editor, Proceedings of the ACM
SIGPLAN Haskell Symposium. An extended version is available as Technical
report Utrecht University UU-CS-2008-010, 2008.

Ralf Hinze, Johan Jeuring, and Andres Löh. Comparing approaches to  
generic
programming in Haskell. In Roland Backhouse, Jeremy Gibbons, Ralf Hinze,
and Johan Jeuring, editors, Lecture notes of the Spring School on
Datatype-Generic Programming 2006, LNCS 4719, pages 72 - 149, 2007,
Springer-Verlag.

-- Johan Jeuring



More information about the Haskell-Cafe mailing list