[Haskell-cafe] GHC wish

Bulat Ziganshin bulat.ziganshin at gmail.com
Wed May 24 10:45:21 EDT 2006

Hello Christophe,

Wednesday, May 24, 2006, 3:05:53 AM, you wrote:
> I recently stumbled upon something that I think should be added to the
> GHC wishlist. Not knowing where to put it, I will put it here. As there
> is deriving(Show) for most basic data types, wouldn't it be possible to
> have something similar but then deriving(Pretty). When printing ASTs it
> could make it much easier to look at the output.

believe you or not, but that is a pretty standard technique
called generic programming. i've seen 7 tools to do it (including
DrIFT) and moreover, 3 of them are included in GHC.

one of these GHC-bundled tools is Template Haskell. you can see it's
description at

my library http://freearc.narod.ru/Streams.tar.gz contains module
Data/AltBinary/TH.hs that you can use as the starting point - it
derives instances for Binary class. File "Examples/AltBinary/DeriveBinary.hs"
contains example of it's usage. use "-ddump-splices" GHC option when
compiling example to see actual code generated

i also attached here simple module that generates "Show" instances using TH

and last - in my feeling, DrIFT is simpler to use, TH is really
head-breaking thing. on the other side, by using TH you will not rely
on any external tools and special preprocessing. on the third side ;)
TH works only with GHC while DrIFT is compatible with any Haskell
compiler. decision is up to you

anyway, please share your code - it is rather common task and i wonder
why noone still implemented this

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: derive.hs
Type: application/octet-stream
Size: 1850 bytes
Desc: not available
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20060524/4022917e/derive.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: derive-test.hs
Type: application/octet-stream
Size: 173 bytes
Desc: not available
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20060524/4022917e/derive-test.obj

More information about the Haskell-Cafe mailing list