Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Langage.Haskell.TH.report work?

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...

like image 220
MathematicalOrchid Avatar asked Mar 07 '12 11:03

MathematicalOrchid


2 Answers

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."

like image 96
dflemstr Avatar answered Sep 21 '22 02:09

dflemstr


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...

like image 42
MathematicalOrchid Avatar answered Sep 19 '22 02:09

MathematicalOrchid