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:[EMAIL PROTECTED]
derive.hs
Description: Binary data
derive-test.hs
Description: Binary data
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
