[Haskell-cafe] Use Template Haskell recover inside the IO monad

Federico Mastellone fmaste at gmail.com
Tue Feb 28 21:59:39 CET 2012

I'm new to Template Haskell and just started playing with it.
I have Haskell platform 2011.4.0 and I get this error when I try to run this simple code.

main = do
	code <- runQ $ recover (return []) th
	putStrLn (pprint code)
	putStrLn (show code)

th :: Q [Dec]
th = [d| 
	sum a b = a + b 

Template Haskell error: Can't do `recover' in the IO monad
POC.hs: user error (Template Haskell failure)

How can I get declarations with the "recover" function so I can print a custom error message using "location"?
If I can't do it inside the IO monad, how can I do a program to pretty print Haskell code?


More information about the Haskell-Cafe mailing list