| 1 |
{-# LANGUAGE CPP #-} |
| 2 |
{-# LANGUAGE PolyKinds #-} |
| 3 |
{-# LANGUAGE ScopedTypeVariables #-} |
| 4 |
|
| 5 |
-- | Helper functions used in code that "Language.Haskell.TH.Lift" generates. |
| 6 |
-- |
| 7 |
-- Note: this is an internal module, and as such, the API presented here is not |
| 8 |
-- guaranteed to be stable, even between minor releases of this library. |
| 9 |
module Language.Haskell.TH.Lift.Internal where |
| 10 |
|
| 11 |
#if MIN_VERSION_template_haskell(2,16,0) |
| 12 |
import GHC.Exts (RuntimeRep, TYPE) |
| 13 |
#endif |
| 14 |
|
| 15 |
import Language.Haskell.TH.Syntax |
| 16 |
|
| 17 |
-- | A type-restricted version of 'error' that ensures 'makeLift' always |
| 18 |
-- returns a value of type @q 'Exp'@ (where @q@ is an instance of 'Quote'), |
| 19 |
-- even when used on an empty datatype. |
| 20 |
#if MIN_VERSION_template_haskell(2,17,0) |
| 21 |
errorQuoteExp :: Quote q => String -> q Exp |
| 22 |
#else |
| 23 |
errorQuoteExp :: String -> Q Exp |
| 24 |
#endif |
| 25 |
errorQuoteExp = error |
| 26 |
|
| 27 |
-- | This is a cargo-culted version of @unsafeSpliceCoerce@ from the |
| 28 |
-- @th-compat@ library, which has been copied here to avoid incurring a library |
| 29 |
-- dependency. |
| 30 |
#if MIN_VERSION_template_haskell(2,17,0) |
| 31 |
unsafeSpliceCoerce :: forall (r :: RuntimeRep) (a :: TYPE r) m. Quote m => m Exp -> Code m a |
| 32 |
unsafeSpliceCoerce = unsafeCodeCoerce |
| 33 |
#elif MIN_VERSION_template_haskell(2,16,0) |
| 34 |
unsafeSpliceCoerce :: forall (r :: RuntimeRep) (a :: TYPE r). Q Exp -> Q (TExp a) |
| 35 |
unsafeSpliceCoerce = unsafeTExpCoerce |
| 36 |
#else |
| 37 |
unsafeSpliceCoerce :: forall a. Q Exp -> Q (TExp a) |
| 38 |
unsafeSpliceCoerce = unsafeTExpCoerce |
| 39 |
#endif |