[Haskell-cafe] TH Q Monad and fail

Gracjan Polak gracjan at acchsh.com
Tue Sep 20 04:51:34 EDT 2005


Hi all,

The Q Monad in template haskell has fail method. As I understand it, it 
throws some kind of exception. How do I catch this exception?

Some code I'm trying to create:

infoToCode :: Info -> Q Exp
infoToCode (ClassI dec) = -- ClassI Dec
     fail "ClassI not supported" -- this will be implemented
infoToCode (ClassOpI name xtype name2 fixity) = -- ClassOpI Name Type 
Name Fixity
     fail "ClassOpI not supported"
infoToCode (TyConI dec) = -- TyConI Dec
     fail "TyConI not supported"
infoToCode (PrimTyConI name int bool) = -- PrimTyConI Name Int Bool
     fail "PrimTyConI not supported"
infoToCode (DataConI name xtype name2 fixity) = -- DataConI Name Type 
Name Fixity
     fail "DataConI not supported"
infoToCode (VarI name xtype maybedec fixity) = -- VarI Name Type (Maybe 
Dec) Fixity
     fail "TVarI not supported"
infoToCode (TyVarI name xtype) = -- TyVarI Name Type
     fail "TyVarI not supported"


nameToCode1 :: Name -> Q Exp
nameToCode1 name = do
     info <- reify name
     Code <- infoToCode info
     runIO $ putStrLn $ pprint Code
     return Code

-- Here be dragons...

nameToCode name = nameToCode1 name `catch` c
     where c e = do
             runIO $ putStrLn $ show e
             fail "refailed"


-- 
Gracjan


More information about the Haskell-Cafe mailing list