module Data.Derive.TopDown.IsInstance
( isInstance'
) where
import Data.Derive.TopDown.Lib
import Data.Generics
import GHC.Exts
import Language.Haskell.TH
replace_poly_type :: Type -> Type
replace_poly_type :: Type -> Type
replace_poly_type (VarT ClassName
_) = ClassName -> Type
ConT ''Any
replace_poly_type Type
x = Type
x
replace_poly_type_trans :: Data a => a -> a
replace_poly_type_trans :: forall a. Data a => a -> a
replace_poly_type_trans = (forall a. Data a => a -> a) -> forall a. Data a => a -> a
everywhere ((Type -> Type) -> a -> a
forall a b. (Typeable a, Typeable b) => (b -> b) -> a -> a
mkT Type -> Type
replace_poly_type)
remove_explicit_forall :: Type -> Type
remove_explicit_forall :: Type -> Type
remove_explicit_forall (ForallT [TyVarBndr Specificity]
_ Cxt
_ Type
t) = Type
t
remove_explicit_forall Type
t = Type
t
remove_explicit_forall_trans :: Type -> Type
remove_explicit_forall_trans :: Type -> Type
remove_explicit_forall_trans = (forall a. Data a => a -> a) -> forall a. Data a => a -> a
everywhere ((Type -> Type) -> a -> a
forall a b. (Typeable a, Typeable b) => (b -> b) -> a -> a
mkT Type -> Type
remove_explicit_forall)
isInstance' :: ClassName -> [Type] -> Q Bool
isInstance' :: ClassName -> Cxt -> Q Bool
isInstance' ClassName
cls Cxt
tys = if ClassName
cls ClassName -> ClassName -> Bool
forall a. Eq a => a -> a -> Bool
== ''Typeable
then Bool -> Q Bool
forall a. a -> Q a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
else
let trans :: Type -> Type
trans = Type -> Type
remove_explicit_forall_trans (Type -> Type) -> (Type -> Type) -> Type -> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> Type
forall a. Data a => a -> a
replace_poly_type_trans
in ClassName -> Cxt -> Q Bool
isInstance ClassName
cls ((Type -> Type) -> Cxt -> Cxt
forall a b. (a -> b) -> [a] -> [b]
map Type -> Type
trans Cxt
tys)