2

I defined a function using Template Haskell which generates a function definition given some type. The type is basically

makeFunc :: Name -> Q [Dec]

Right now, I use the -ddump-splices switch with GHC to see the generated splices. How can I automate this to verify that different types yield the expected splices?

A basic approach might be to just redirect the generated splice to a file and then compare that, but the generated code may well be different since it involves various identifiers constructed via newName.

Frerich Raabe
  • 90,689
  • 19
  • 115
  • 207
  • Is it enough to just use `runQ :: Q a -> IO a`? Then you can write any (decidable) predicate on `a` that you like, including alpha-equivalence to a known-good result from a previous run. – Daniel Wagner Jun 04 '15 at 23:54
  • Maybe you could write a really obnoxious `equalModuloNames :: Dec -> Dec -> Bool` function that ignores names, and then do some unit tests with your generated code. Together that seems like it would provide decent coverage. – jberryman Jun 05 '15 at 21:34

0 Answers0