[Haskell] boilerplate boilerplate

Alex Jacobson alex at alexjacobson.com
Wed May 23 00:31:28 EDT 2007


I'm not sure I understand how this solves my problem.  Its possible that 
I can use Derive not to need all the newtype declarations at all, but, 
if I do need them, I'm not sure how Derive reduces the overall amount of 
boilerplate here.

Perhaps I should define a TH function that takes

      $(newtype' Name String)

And converts it to a

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



-Alex-

Neil Mitchell wrote:
> Hi
>
>>    {-# 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)
>
> First off, never use OPTIONS, use OPTIONS_GHC instead. OPTIONS is the
> old way of doing it.
>
> Secondly, if you add {-# OPTIONS_DERIVE
> --derive=Eq,Ord,Read,Show,Typeable #-} then running your code through
> with Derive should give you the magic that you require. Plus it will
> also work on Hugs, and not require your OPTIONS_GHC anyway.
>
> Derive: http://www-users.cs.york.ac.uk/~ndm/derive/
>
> Thanks
>
> Neil



More information about the Haskell mailing list