
Dear all, 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. With regards, Christophe -- Christophe Poucet Ph.D. Student Phone:+32 16 28 87 20 E-mail: Christophe (dot) Poucet (at) imec (dot) be Website: http://notvincenz.com/ IMEC vzw – Register of Legal Entities Leuven VAT BE 0425.260.668 – Kapeldreef 75, B-3001 Leuven, Belgium – www.imec.be *****DISCLAIMER***** This e-mail and/or its attachments may contain confidential information. It is intended solely for the intended addressee(s). Any use of the information contained herein by other persons is prohibited. IMEC vzw does not accept any liability for the contents of this e-mail and/or its attachments. **********

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 http://haskell.org/hawiki/TemplateHaskell http://haskell.org/hawiki/TemplateHaskellTutorial http://freearc.narod.ru/th.htm http://freearc.narod.ru/thdoc.htm 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@gmail.com
participants (2)
-
Bulat Ziganshin
-
Christophe Poucet