Question

I have written a small utility to expand all TH splices in a Haskell module, so that I can use the haskell module even where TH is unavailable. To accomplish this, I pass the -ddump-splices option to GHC while compiling the module and capture the resulting code, and then replace the TH declarations in the module with the captured code.

However, it looks like -ddump-splices does not always generate compilable code. Specifically, it seems to use braces for layout but without adding the semicolons in the correct places!

Here is an example from my test file -

case dispatch_a3Tg pieces0_a3Tf of {
    Just f_a3U6
      -> f_a3U6
           master0_a3T9
           sub0_a3Ta
           toMaster0_a3Tb
           app4040_a3Tc
           handler4050_a3Td
           method0_a3Te
    Nothing -> app4040_a3Tc }

Here it generated opening and closing braces but not the semicolon needed between the two case alternatives. This causes the following error at compile time -

GHCi, version 7.4.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main             ( Test.hs, interpreted )

Test.hs:51:17: parse error on input `->'
Failed, modules loaded: none.
Prelude> 
Was it helpful?

Solution

No, the splice dumps are often invalid code and it takes significant time to reduce these to something that not only compiles but is human understandable. This was a source of frustration when investigating aspects of TYB.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top