{-# LANGUAGE CPP #-}

module Language.Haskell.TH.Compat where
import           Language.Haskell.TH.Syntax

-- | Compatibility helper to create TySynInstD
mkTySynInstD :: Name -> [Type] -> Type -> Dec
mkTySynInstD :: Name -> [Type] -> Type -> Dec
mkTySynInstD Name
tyConNm [Type]
tyArgs Type
rhs =
#if MIN_VERSION_template_haskell(2,15,0)
        TySynEqn -> Dec
TySynInstD (Maybe [TyVarBndr] -> Type -> Type -> TySynEqn
TySynEqn Maybe [TyVarBndr]
forall a. Maybe a
Nothing
                     ((Type -> Type -> Type) -> Type -> [Type] -> Type
forall (t :: Type -> Type) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl Type -> Type -> Type
AppT (Name -> Type
ConT Name
tyConNm) [Type]
tyArgs)
                     Type
rhs)
#else
        TySynInstD tyConNm
                   (TySynEqn tyArgs
                             rhs)
#endif

-- | Compatibility helper to create (total) tuple expressions
mkTupE :: [Exp] -> Exp
mkTupE :: [Exp] -> Exp
mkTupE = [Maybe Exp] -> Exp
TupE
#if MIN_VERSION_template_haskell(2,16,0)
         ([Maybe Exp] -> Exp) -> ([Exp] -> [Maybe Exp]) -> [Exp] -> Exp
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Exp -> Maybe Exp) -> [Exp] -> [Maybe Exp]
forall a b. (a -> b) -> [a] -> [b]
map Exp -> Maybe Exp
forall a. a -> Maybe a
Just
#endif

#if MIN_VERSION_template_haskell(2,16,0)
liftTypedFromUntyped :: Lift a => a -> Q (TExp a)
liftTypedFromUntyped :: a -> Q (TExp a)
liftTypedFromUntyped = Q Exp -> Q (TExp a)
forall a. Q Exp -> Q (TExp a)
unsafeTExpCoerce (Q Exp -> Q (TExp a)) -> (a -> Q Exp) -> a -> Q (TExp a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Q Exp
forall t. Lift t => t -> Q Exp
lift
#endif