[Haskell-cafe] RE: [Haskell] boilerplate boilerplate

Claus Reinke claus.reinke at talk21.com
Fri Jun 1 07:06:53 EDT 2007


> Actually, standalone deriving doesn't really solve the boilerplate 
> boilerplate problem.  My original complaint here is that I don't want to 
> explicitly declare a deriving (Data,Typeable) for every type used 
> somewhere inside a larger type I am using.  In this particular case, I 
> am using SYB to autogenerate/autoparse XML.  The Atom/RSS datatype has a 
> lot of elements in it.  Having to do an explicit declaration of deriving 
> (Data,Typeable) for each of them is just a tremendous beat-down no 
> matter where I do it.
> 
> A simple solution to the problem is just to have the compiler 
> automatically derive Data and Typeable for all classes. 

it still sounds as if you might want to follow Neil's suggestions about using
Data.Derive, which does seem to have a derive-this-for-all feature.

but one of the nice things about just separating data and deriving is that
one can add derived instances without changing, or even having the source,
and without having to add the individual derivings by hand. as i mentioned,
we did such a scripted deriving, then based on the old DrIFT, for HaRe,
over Programatica's data types for Haskell syntax.

these days, one might use something like the two-liner sketched below.

btw, i've found that even major publishers have trouble keeping their
RSS feeds valid, not to mention the variety of standards, and the variety
of (not) using those standards for recording essential information in those
feeds. that frequently breaks strict XML processing, so if i had to do it
again, i'd try a fast&loose heuristic approach instead, extracting the 
information from whereever it has been hidden in the feed, valid or broken..

claus

    $ ghc -e ':b Language.Haskell.Syntax' | \
    > sed -n -e '/data/{s/^data\s*\([^=\r]*\).*$/deriving MyClass for ( \1 )/; p}'
    deriving MyClass for ( HsGuardedAlt  )
    deriving MyClass for ( HsGuardedAlts )
    deriving MyClass for ( HsAlt  )
    deriving MyClass for ( HsFieldUpdate  )
    deriving MyClass for ( HsStmt )
    deriving MyClass for ( HsPatField  )
    deriving MyClass for ( HsPat )
    deriving MyClass for ( HsExp )
    deriving MyClass for ( HsLiteral )
    deriving MyClass for ( HsType )
    deriving MyClass for ( HsQualType  )
    deriving MyClass for ( HsSafety  )
    deriving MyClass for ( HsGuardedRhs  )
    deriving MyClass for ( HsRhs  )
    deriving MyClass for ( HsBangType  )
    deriving MyClass for ( HsConDecl )
    deriving MyClass for ( HsMatch  )
    deriving MyClass for ( HsDecl )
    deriving MyClass for ( HsAssoc  )
    deriving MyClass for ( HsImportSpec )
    deriving MyClass for ( HsImportDecl )
    deriving MyClass for ( HsExportSpec )
    deriving MyClass for ( HsModule )
    deriving MyClass for ( HsCName  )
    deriving MyClass for ( HsOp  )
    deriving MyClass for ( HsQOp  )
    deriving MyClass for ( HsName  )
    deriving MyClass for ( HsQName )
    deriving MyClass for ( HsSpecialCon )
    deriving MyClass for ( SrcLoc )




More information about the Haskell-Cafe mailing list