Skip to content

Commit 2176eb3

Browse files
RyanGlScotthvr
authored andcommitted
Implement liftTyped in the Lift Text instances
`template-haskell-2.16.0.0` adds a `liftTyped` method to `Lift`, which is like `lift` but returning `Q (TExp t)` instead of `Q Exp`. `liftTyped` does not have a default implementation in terms of `lift`, so it must be implemented explicitly in the `Lift Text` instances that `text` defines. The implementations I chose are based off of the general approach taken by `Language.Haskell.TH.Syntax`, such as in this example: https://gitlab.haskell.org/ghc/ghc/blob/4898df1cc25132dc9e2599d4fa4e1bbc9423cda5/libraries/template-haskell/Language/Haskell/TH/Syntax.hs#L716
1 parent d23cfad commit 2176eb3

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Data/Text.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ import GHC.Base (eqInt, neInt, gtInt, geInt, ltInt, leInt)
254254
import qualified GHC.Exts as Exts
255255
#endif
256256
import qualified Language.Haskell.TH.Lib as TH
257-
import Language.Haskell.TH.Syntax (Lift, lift)
257+
import qualified Language.Haskell.TH.Syntax as TH
258258
#if MIN_VERSION_base(4,7,0)
259259
import Text.Printf (PrintfArg, formatArg, formatString)
260260
#endif
@@ -428,8 +428,11 @@ instance Data Text where
428428
-- it preserves abstraction at the cost of inefficiency.
429429
--
430430
-- @since 1.2.4.0
431-
instance Lift Text where
431+
instance TH.Lift Text where
432432
lift = TH.appE (TH.varE 'pack) . TH.stringE . unpack
433+
#if MIN_VERSION_template_haskell(2,16,0)
434+
liftTyped = TH.unsafeTExpCoerce . TH.lift
435+
#endif
433436

434437
#if MIN_VERSION_base(4,7,0)
435438
-- | Only defined for @base-4.7.0.0@ and later

Data/Text/Lazy.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ import qualified GHC.Exts as Exts
248248
#endif
249249
import GHC.Prim (Addr#)
250250
import qualified Language.Haskell.TH.Lib as TH
251-
import Language.Haskell.TH.Syntax (Lift, lift)
251+
import qualified Language.Haskell.TH.Syntax as TH
252252
#if MIN_VERSION_base(4,7,0)
253253
import Text.Printf (PrintfArg, formatArg, formatString)
254254
#endif
@@ -413,8 +413,11 @@ instance Data Text where
413413
-- it preserves abstraction at the cost of inefficiency.
414414
--
415415
-- @since 1.2.4.0
416-
instance Lift Text where
416+
instance TH.Lift Text where
417417
lift = TH.appE (TH.varE 'pack) . TH.stringE . unpack
418+
#if MIN_VERSION_template_haskell(2,16,0)
419+
liftTyped = TH.unsafeTExpCoerce . TH.lift
420+
#endif
418421

419422
#if MIN_VERSION_base(4,7,0)
420423
-- | Only defined for @base-4.7.0.0@ and later

0 commit comments

Comments
 (0)