|
6 | 6 | #if __GLASGOW_HASKELL__ >= 708
|
7 | 7 | {-# LANGUAGE TypeFamilies #-}
|
8 | 8 | #endif
|
| 9 | +-- Using TemplateHaskell in text unconditionally is unacceptable, as |
| 10 | +-- it's a GHC boot library. TemplateHaskellQuotes was added in 8.0, so |
| 11 | +-- this would seem to be a problem. However, GHC's policy of only |
| 12 | +-- needing to be able to compile itself from the last few releases |
| 13 | +-- allows us to use full-fat TH on older versions, while using THQ for |
| 14 | +-- GHC versions that may be used for bootstrapping. |
| 15 | +#if __GLASGOW_HASKELL__ >= 800 |
| 16 | +{-# LANGUAGE TemplateHaskellQuotes #-} |
| 17 | +#else |
| 18 | +{-# LANGUAGE TemplateHaskell #-} |
| 19 | +#endif |
9 | 20 |
|
10 | 21 | -- |
|
11 | 22 | -- Module : Data.Text
|
@@ -244,6 +255,8 @@ import GHC.Base (eqInt, neInt, gtInt, geInt, ltInt, leInt)
|
244 | 255 | #if __GLASGOW_HASKELL__ >= 708
|
245 | 256 | import qualified GHC.Exts as Exts
|
246 | 257 | #endif
|
| 258 | +import qualified Language.Haskell.TH.Lib as TH |
| 259 | +import Language.Haskell.TH.Syntax (Lift, lift) |
247 | 260 | #if MIN_VERSION_base(4,7,0)
|
248 | 261 | import Text.Printf (PrintfArg, formatArg, formatString)
|
249 | 262 | #endif
|
@@ -413,6 +426,13 @@ instance Data Text where
|
413 | 426 | _ -> P.error "gunfold"
|
414 | 427 | dataTypeOf _ = textDataType
|
415 | 428 |
|
| 429 | +-- | This instance has similar considerations to the 'Data' instance: |
| 430 | +-- it preserves abstraction at the cost of inefficiency. |
| 431 | +-- |
| 432 | +-- @since 1.2.4.0 |
| 433 | +instance Lift Text where |
| 434 | + lift = TH.appE (TH.varE 'pack) . TH.stringE . unpack |
| 435 | + |
416 | 436 | #if MIN_VERSION_base(4,7,0)
|
417 | 437 | -- | Only defined for @base-4.7.0.0@ and later
|
418 | 438 | --
|
|
0 commit comments