[Haskell] boilerplate boilerplate

Neil Mitchell ndmitchell at gmail.com
Wed May 23 17:02:03 EDT 2007

:: Follow ups to haskell-cafe@ is probably best

Hi Alex,

{-# OPTIONS_DERIVE --derive=Ord,Eq,Read... #-}

That would apply to all definitions in the module, so you don't have
to repeat it for each type. You can attach a deriving annotation to
each type individually, but that's obviously not what you want.

> Actually independent deriving would help a lot but am not sure of the
> syntax.
> could it be something like
>    derive (Ord,Eq,Read,Show,Typeable) (BlogEntry Name Title Body Emai)

We can already do:

$( derive makeOrd ''Name )

Which doesn't require a preprocessor on GHC, using template haskell. I
guess the following may work in Template Haskell:

$( [derive typ cls | typ <- [makeOrd, makeEq, makeRead, makeShow], typ
<- [''BlogEntry, ''Name ...] )

But ask a TH expert for the details!



More information about the Haskell mailing list