automatic instance derivation

How do you automatically derive an instance for a data type defined in an imported module? -- automatic instance derivation directly after type declaration data Val1 = V1 Int deriving Show -- manual instance derivation can be in separate file data Val2 = V2 Int instance Show Val2 where show (V2 i) = show i -- Is something like this possible? data Val1 = V1 Int ... derive Show Val2 Thanks, Greg

Hello Greg, Saturday, August 19, 2006, 3:42:45 AM, you wrote:
-- Is something like this possible? derive Show Val2
yes, in proposal :) well, the best practical way i know is to use Template Haskell / DrIFT. I can give your a TH module which generates Show instances. So, using it will as easy as import THShow .... $(deriveShow Val2) of course, TH is GHC-only solution. you can prefer DrIFT what is a general preprocessor and afair it contains a lot of prewritten instance-generation modules -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

well, the best practical way i know is to use Template Haskell / DrIFT
That's too bad. I was hoping we could trivially solve Tim Newsham's XML problem by importing HaXml, automatically deriving Data and Typeable for HaXml's 'Content' data type, and then use 'everywhereM' from Data.Generics.Schemeshttp://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Generics-Sch... to do his stateful XML transformation. -Greg
participants (2)
-
Bulat Ziganshin
-
Greg Fitzgerald