[Haskell-cafe] Scraping boilerplate deriving?

Jonas Almström Duregård jonas.duregard at chalmers.se
Wed Sep 15 02:25:15 EDT 2010


> #define defObj(t)   newtype t = t Obj deriving (A,B,C,D)

Blasphemy! :)

On 14 September 2010 23:01, John Meacham <john at repetae.net> wrote:

> On Tue, Sep 14, 2010 at 01:24:16AM -0700, Kevin Jardine wrote:
> > I have a set of wrapper newtypes that are always of the same format:
> >
> > newtype MyType = MyType Obj deriving (A,B,C,D)
> >
> > where Obj, A, B, C, and D are always the same. Only MyType varies.
> >
> > A, B, C, and D are automagically derived by GHC using the
> >
> > {-# LANGUAGE GeneralizedNewtypeDeriving #-}
> >
> > feature.
> >
> > I would like to use some macro system (perhaps Template Haskell?) to
> > reduce this to something like
> >
> > defObj MyType
>
> How about the straightforward?
>
> > {-# LANGUAGE CPP #-}
> > #define defObj(t)   newtype t = t Obj deriving (A,B,C,D)
> >
> > defObj(Foo)
> > defObj(Bar)
> > ....
>
> It has the advantage of being (de facto) portable.
>
>        John
>
>
> --
> John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100915/8244a69f/attachment.html


More information about the Haskell-Cafe mailing list