The isInstance
method can do what you need.
Example in ghci:
> :set -XTemplateHaskell > import Language.Haskell.TH > $(stringE . show =<< (isInstance ''Functor . (: []) =<< [t| [] |])) "True" > $(stringE . show =<< (isInstance ''Show . (: []) =<< [t| Maybe Int |])) "True" $(stringE . show =<< (isInstance ''Show . (: []) =<< [t| (Int -> Bool) |])) "False"
Its sig type is equal to
isInstance :: Name -> [Type] -> Q Bool
Those. you give the name (obtained with ''
or using the mkName
function) for the class, then you pass the types to check against the class (the class will use the multicast type class). Then it will return True or False in monad Q.
source share