Data representation, maybe reflection, laziness

John Meacham john at
Fri Oct 31 14:31:11 EST 2003

On Fri, Oct 31, 2003 at 03:06:57PM -0500, Mark Carroll wrote:
> Ralf Hinze and Simon Peyton-Jones wrote an interesting paper on generic
> programming and derivable type classes. It looked like maybe programmers
> would be able to write their own "deriving xml" stuff and whatever, which
> looked great because, if there's not already one out there, I'd love to
> derive some read/show analogue automatically for data in some encoding
> that's very efficient to write and parse (i.e. not XML (-:).
> I was also wondering how the ability to write "deriving" stuff related to
> what one might think of as being reflection - that is, for example, could
> a definition of deepSeq be derived that automatically knows how to recurse
> into and traverse data structures and make sure everything's evaluated?

DrIFT can do this. add {-! derive: NFData !-} to your types and run the
program through DrIFT then 'rnf' will reduce it to to normal form.

template haskell also (among other things) lets you do your own
'deriving' clauses. Something I have been meaning to work on is having
DrIFT understand the same data types as TH, so code can be shared
between them much more easily...

here is a list of derivables DrIFT currently supports. more are always
welcome :).

   Binary            efficient binary encoding of terms
   Observable        HOOD observable
   NFData            provides 'rnf' to reduce to normal form (deepSeq)
   Typeable          derive Typeable for Dynamic
   HFoldable         Strafunski hfoldr
   Term              Strafunski representation via Dynamic
   ATermConvertible  encode terms in the ATerm format
   Haskell2Xml       encode terms as XML
   has               hasfoo for record types
   is                provides isFoo for each constructor
   test              output raw data for testing
   un                provides unFoo for unary constructors
   update            for label 'foo' provides 'foo_u' to update it

John Meacham - California Institute of Technology, Alum. - john at

More information about the Haskell-Cafe mailing list