4

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> 
Anupam Jain
  • 7,851
  • 2
  • 39
  • 74

1 Answers1

3

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.

Thomas M. DuBuisson
  • 64,245
  • 7
  • 109
  • 166
  • 2
    what is TYB? Temecula Youth Baseball? – John L Aug 29 '12 at 00:22
  • I added a link in the edit and was really tempted to make a quip about using {[h](http://www.haskell.org/hoogle/?hoogle=tyb),[g](https://www.google.com/search?q=haskell+tyb)}oogle. Not that it's a bad question, just that it's such a habit to point out how useful hoogle is for everything under the Haskell Sun. – Thomas M. DuBuisson Aug 29 '12 at 02:14
  • 1
    GHC feature request: http://hackage.haskell.org/trac/ghc/ticket/5016. It is unlikely to be fixed in near future. – sdcvvc Aug 29 '12 at 02:45
  • Thanks for the link. I'll admit I didn't try hoogle, but I'm guessing you didn't try google either. – John L Aug 29 '12 at 04:18
  • I did try google - for me almost the whole first page is on topic (even after removing personal results). – Thomas M. DuBuisson Aug 29 '12 at 04:42
  • Thanks, it wasn't the answer I had hoped to get, but I suppose TH is not the priority for Haskell devs right now. Looks like it'll be a great little project for someone else in the community to take up. – Anupam Jain Aug 29 '12 at 07:30