6

Unfortunately, many Template Haskell functions have absolutely no documentation at all. One such function is report. It takes a Bool and a String, and produces a compilation error with the specified string as the error message. Does anybody have any clue what the hell the Bool is for? As best as I can tell, either value does exactly the same thing...

MathematicalOrchid
  • 61,854
  • 19
  • 123
  • 220

2 Answers2

9

If the Bool is True, an error is reported; if it is False, a "warning" is reported, meaning that the template code will continue to run to collect more "warnings."

dflemstr
  • 25,947
  • 5
  • 70
  • 105
  • I had a feeling it would be something like that, but I wasn't sure which one was error and which one was warning. Regardless, it seems that compilation continues either way. (!) I would have expected reporting an error to halt compilation, but it doesn't appear to do so... – MathematicalOrchid Mar 07 '12 at 11:18
  • From the internal documentation: `Report an error (True) or warning (False) ...but carry on; use 'fail' to stop`. So, you have to take care of the "fail" step yourself, apparently; I find this to be a strange design decision. – dflemstr Mar 07 '12 at 11:21
  • Oh, you beat me to it. :-) Yes, strange indeed. From my testing, it seems that just calling `fail` is enough to halt compilation, giving the string as the error message, and the splice location as the source of the problem. Which is pretty much what I wanted... – MathematicalOrchid Mar 07 '12 at 11:23
2

Looking at the source code, report calls qReport, which is a method of some class called Quasi. This method actually has some damned documentation - though only a tiny snippet. I quote:

Report an error (True) or warning (False) ...but carry on; use fail to stop

So it seems to make my TH splice crash with an appropriate error message, I just need to call fail instead. Hopefully this information will be useful to anyone else trying to figure that out...

MathematicalOrchid
  • 61,854
  • 19
  • 123
  • 220