Skip to content

Commit aae5f26

Browse files
Add Lift instances for Text.
These use the existing `Data` instances, and have similar trade-offs.
1 parent 44ec2ce commit aae5f26

File tree

6 files changed

+34
-4
lines changed

6 files changed

+34
-4
lines changed

Data/Text.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ import GHC.Base (eqInt, neInt, gtInt, geInt, ltInt, leInt)
244244
#if __GLASGOW_HASKELL__ >= 708
245245
import qualified GHC.Exts as Exts
246246
#endif
247+
import Language.Haskell.TH.Quote (dataToExpQ)
248+
import Language.Haskell.TH.Syntax (Lift, lift)
247249
#if MIN_VERSION_base(4,7,0)
248250
import Text.Printf (PrintfArg, formatArg, formatString)
249251
#endif
@@ -413,6 +415,16 @@ instance Data Text where
413415
_ -> P.error "gunfold"
414416
dataTypeOf _ = textDataType
415417

418+
-- | This instance has similar considerations to the 'Data' instance:
419+
-- it preserves abstraction at the cost of inefficiency.
420+
--
421+
-- @since 1.2.4.0
422+
instance Lift Text where
423+
-- Note: since we have to work on GHC 7.0, we've got to define this
424+
-- explicitly, rather than relying on the nice modern 'liftData'
425+
-- default.
426+
lift = dataToExpQ (\ _ -> Nothing)
427+
416428
#if MIN_VERSION_base(4,7,0)
417429
-- | Only defined for @base-4.7.0.0@ and later
418430
--

Data/Text/Lazy.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ import qualified GHC.Base as GHC
239239
import qualified GHC.Exts as Exts
240240
#endif
241241
import GHC.Prim (Addr#)
242+
import Language.Haskell.TH.Quote (dataToExpQ)
243+
import Language.Haskell.TH.Syntax (Lift, lift)
242244
#if MIN_VERSION_base(4,7,0)
243245
import Text.Printf (PrintfArg, formatArg, formatString)
244246
#endif
@@ -399,6 +401,16 @@ instance Data Text where
399401
_ -> error "Data.Text.Lazy.Text.gunfold"
400402
dataTypeOf _ = textDataType
401403

404+
-- | This instance has similar considerations to the 'Data' instance:
405+
-- it preserves abstraction at the cost of inefficiency.
406+
--
407+
-- @since 1.2.4.0
408+
instance Lift Text where
409+
-- Note: since we have to work on GHC 7.0, we've got to define this
410+
-- explicitly, rather than relying on the nice modern 'liftData'
411+
-- default.
412+
lift = dataToExpQ (\ _ -> Nothing)
413+
402414
#if MIN_VERSION_base(4,7,0)
403415
-- | Only defined for @base-4.7.0.0@ and later
404416
--

benchmarks/text-benchmarks.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ executable text-benchmarks
4242
ghc-prim,
4343
integer-gmp,
4444
stringsearch,
45+
template-haskell,
4546
transformers,
4647
utf8-string,
4748
vector

changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### 1.2.3.1
1+
### 1.2.4.0
22

33
* Make `decodeUtf8With` fail explicitly for unsupported non-BMP
44
replacement characters instead silent undefined behaviour (gh-213)
@@ -12,6 +12,8 @@
1212
* A bug in the case-mapping functions resulting in unreasonably large
1313
allocations with large arguments has been fixed (gh-221)
1414

15+
* `Lift` instances `Data.Text.Text` and `Data.Text.Lazy.Text`.
16+
1517
### 1.2.3.0
1618

1719
* Spec compliance: `toCaseFold` now follows the Unicode 9.0 spec

tests/text-tests.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ library
147147
binary,
148148
deepseq,
149149
ghc-prim,
150-
integer-gmp
150+
integer-gmp,
151+
template-haskell
151152

152153
if flag(bytestring-builder)
153154
build-depends: bytestring >= 0.9 && < 0.10.4,

text.cabal

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: >= 1.8
22
name: text
3-
version: 1.2.3.1
3+
version: 1.2.4.0
44

55
homepage: https://github.com/haskell/text
66
bug-reports: https://github.com/haskell/text/issues
@@ -147,7 +147,8 @@ library
147147
base >= 4.2 && < 5,
148148
binary,
149149
deepseq >= 1.1.0.0,
150-
ghc-prim >= 0.2
150+
ghc-prim >= 0.2,
151+
template-haskell
151152

152153
if flag(bytestring-builder)
153154
build-depends: bytestring >= 0.9 && < 0.10.4,
@@ -255,6 +256,7 @@ test-suite tests
255256
ghc-prim,
256257
quickcheck-unicode >= 1.0.1.0,
257258
random,
259+
template-haskell,
258260
test-framework >= 0.4,
259261
test-framework-hunit >= 0.2,
260262
test-framework-quickcheck2 >= 0.2

0 commit comments

Comments
 (0)