8 Jul
2007
8 Jul
'07
9:54 p.m.
On Sun, Jul 08, 2007 at 05:01:21PM +0100, Hugo Pacheco wrote:
module Main where
myprint :: a -> String myprint = show
main = do putStr $ myprint 1 putStr $ myprint '2'
My ideia would be to stage the computation of *myprint* until it is called, where the *Show* instance can be satisfied.
Do you mean that you want to have myprint :: Integer -> String myprint = show generated when GHC notices that myprint is called with an Integer type? Is so, then no, TH, can't do that. What you can do is to write a function mkMyPrint :: Type -> Q [Dec] which you could then call like so: $( mkMyPrint ''Integer ) but you have to do so by hand. Thanks Ian