How does Langage.Haskell.TH.report work?

Unfortunately, many Template Haskell functions have absolutely no documentation. One such feature is report . It takes Bool and String , and generates a compilation error with the specified string as an error message. Does anyone know what the hell Bool ? As far as I can tell, any value does the same ...

+6
source share
2 answers

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

+9
source

Looking at the source code, report calls qReport , which is a method of some class called Quasi . This method does have some damn documentation - albeit a tiny fragment. I quote:

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

So it seems that the TH splicing fails with the corresponding error message, I just need to call fail . I hope this information will be useful to everyone who is trying to understand this ...

+2
source

Source: https://habr.com/ru/post/910158/


All Articles