    {-# 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 b a. (b -> a -> b) -> b -> [a] -> b
    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,17,0)
    liftTypedFromUntyped :: (Lift a, Quote m) => a -> Code m a
    liftTypedFromUntyped :: forall a (m :: Type -> Type). (Lift a, Quote m) => a -> Code m a
    liftTypedFromUntyped = m Exp -> Code m a
    forall a (m :: Type -> Type). Quote m => m Exp -> Code m a
    unsafeCodeCoerce (m Exp -> Code m a) -> (a -> m Exp) -> a -> Code m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> m Exp
    forall t (m :: Type -> Type). (Lift t, Quote m) => t -> m Exp
    forall (m :: Type -> Type). Quote m => a -> m Exp
    lift
    #elif MIN_VERSION_template_haskell(2,16,0)
    liftTypedFromUntyped :: Lift a => a -> Q (TExp a)
    liftTypedFromUntyped = unsafeTExpCoerce . lift
    #endif