[Haskell] boilerplate boilerplate

Alex Jacobson alex at alexjacobson.com
Tue May 22 19:07:26 EDT 2007


Consider this module for a blog entry that I will want to put in various 
generic collections that require Ord

   {-# OPTIONS -fglasgow-exts #-}
   module Blog.Types where
   import Data.Typeable
   import Data.Generics

   data BlogEntry = Entry EpochSeconds Name Email Title Body 
                    deriving (Eq,Ord,Read,Show,Typeable)

   newtype Name = Name String deriving (Eq,Ord,Read,Show,Typeable)
   newtype Title = Title String deriving (Eq,Ord,Read,Show,Typeable)
   newtype Body = Body String deriving (Eq,Ord,Read,Show,Typeable)


It seems really unnecessarily verbose.  Having to add the OPTION header 
AND import Data.Typeable and Data.Generics just to derive Typeable is a 
beat-down.  It is even more of a beat-down to have to add a deriving 
clause for every newtype to make this all work nicely.  Is there a way 
to make all types automatically derive everything unless there is an 
explicit instance declaration otherwise?

   {-# OPTIONS -fglasgow-exts -fgenerics -fderiving#-}
   module Blog.Types where

   data BlogEntry = Entry EpochSeconds Name Email Title Body  

   newtype Name = Name String 
   newtype Title = Title String 
   newtype Body = Body String 

Isn't that much nicer?

-Alex-




More information about the Haskell mailing list