I know that I can cause a compile-time error by calling fail
from a splice, but is it possible to only generate a warning? In particular I would like it to be possible to turn this warning into an error when compiling with -Werror
.
Essentially what I'm trying to do is this:
todo :: Q Exp
todo = do
-- emit warning somehow
loc <- location
let message = ... -- generate message based on loc
[| error $(litE (stringL message)) |]
The idea is to use this instead of undefined
while coding, but make sure it doesn't sneak its way into production code by compiling with -Werror
.
myFunc x | isSimpleCase x = 42
| otherwise = $todo
Turns out the function I was after was the Template Haskell function report
. Its type signature was in the documentation, but I had to read the source code to figure out what it did. The TH documentation sure could use some improvements.
Anyway, my todo
placeholder is now working perfectly, and I'll put something up on Hackage soon if anyone is interested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With