Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emitting warnings from Template Haskell splices

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
like image 343
hammar Avatar asked Apr 25 '11 00:04

hammar


Video Answer


1 Answers

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.

like image 102
hammar Avatar answered Sep 28 '22 18:09

hammar