on master help sign in
Add instance Lift UUID
de0700fOleg Grenrus
uuid-bench/uuid-bench.cabal+13−12
@@ -32,18 +32,19 @@ source-repository head
32
32
33library
33library
34 build-depends:
34 build-depends:
35− base >=4.9 && <5
35+ base >=4.9 && <5
36− , binary >=0.5.1.0 && <0.9
36+ , binary >=0.5.1.0 && <0.9
37− , bytestring >=0.9.2.1 && <0.12
37+ , bytestring >=0.9.2.1 && <0.12
38− , cryptohash-md5 >=0.11.100 && <0.12
38+ , cryptohash-md5 >=0.11.100 && <0.12
39− , cryptohash-sha1 >=0.11.100 && <0.12
39+ , cryptohash-sha1 >=0.11.100 && <0.12
40− , deepseq >=1.3.0.0 && <1.5
40+ , deepseq >=1.3.0.0 && <1.5
41− , entropy >=0.3.7 && <0.5
41+ , entropy >=0.3.7 && <0.5
42− , hashable >=1.2.7.0 && <1.4
42+ , hashable >=1.2.7.0 && <1.4
43− , network-info >=0.2 && <0.3
43+ , network-info >=0.2 && <0.3
44− , random >=1.1 && <1.3
44+ , random >=1.1 && <1.3
45+ , template-haskell >=2.7.0.0 && <2.18
45− , text >=1.2.3.0 && <1.3
46+ , text >=1.2.3.0 && <1.3
46− , time >=1.4 && <1.12
47+ , time >=1.4 && <1.12
47
48
48 -- uuid modules
49 -- uuid modules
49 exposed-modules:
50 exposed-modules:
uuid-types/ChangeLog.md+4
@@ -1,3 +1,7 @@
1+## 1.0.5 (2021-05-03)
2+
3+- Add (Template Haskell) `Lift UUID` instance
4+
1## 1.0.4.0
5## 1.0.4.0
2
6
3- Declare `Data.UUID.Types` module "`Trustworthy`" with respect to SafeHaskell.
7- Declare `Data.UUID.Types` module "`Trustworthy`" with respect to SafeHaskell.
uuid-types/src/Data/UUID/Types/Internal.hs+27
@@ -5,6 +5,10 @@
5#if __GLASGOW_HASKELL__ >= 704
5#if __GLASGOW_HASKELL__ >= 704
6{-# LANGUAGE Unsafe #-}
6{-# LANGUAGE Unsafe #-}
7#endif
7#endif
8+#if __GLASGOW_HASKELL__ >=800
9+{-# LANGUAGE DeriveLift #-}
10+{-# LANGUAGE StandaloneDeriving #-}
11+#endif
8
12
9{-# OPTIONS_HADDOCK hide #-}
13{-# OPTIONS_HADDOCK hide #-}
10
14
@@ -79,6 +83,12 @@ import System.Random.Stateful (Uniform (..), uniformWord64)
79import System.Random (Random (..), next)
83import System.Random (Random (..), next)
80#endif
84#endif
81
85
86+#if __GLASGOW_HASKELL__ >=800
87+import Language.Haskell.TH.Syntax (Lift)
88+#else
89+import Language.Haskell.TH (appE, varE)
90+import Language.Haskell.TH.Syntax (Lift (..), mkNameG_v, Lit (IntegerL), Exp (LitE))
91+#endif
82
92
83-- | Type representing <https://en.wikipedia.org/wiki/UUID Universally Unique Identifiers (UUID)> as specified in
93-- | Type representing <https://en.wikipedia.org/wiki/UUID Universally Unique Identifiers (UUID)> as specified in
84-- <http://tools.ietf.org/html/rfc4122 RFC 4122>.
94-- <http://tools.ietf.org/html/rfc4122 RFC 4122>.
@@ -619,3 +629,20 @@ unsafeShiftR = shiftR
619{-# INLINE unsafeShiftL #-}
629{-# INLINE unsafeShiftL #-}
620unsafeShiftL = shiftL
630unsafeShiftL = shiftL
621#endif
631#endif
632+
633+#if __GLASGOW_HASKELL__ >=800
634+deriving instance Lift UUID
635+#else
636+instance Lift UUID where
637+ lift (UUID w1 w2) = varE fromWords64Name `appE` liftW64 w1 `appE` liftW64 w2
638+ where
639+ fromWords64Name = mkNameG_v currentPackageKey "Data.UUID.Types.Internal" "fromWords64"
640+ liftW64 x = return (LitE (IntegerL (fromIntegral x)))
641+
642+currentPackageKey :: String
643+#ifdef CURRENT_PACKAGE_KEY
644+currentPackageKey = CURRENT_PACKAGE_KEY
645+#else
646+currentPackageKey = "uuid-types-1.0.5"
647+#endif
648+#endif
uuid-types/tests/TestUUID.hs+7
@@ -1,4 +1,5 @@
1{-# LANGUAGE ViewPatterns #-}
1{-# LANGUAGE ViewPatterns #-}
2+{-# LANGUAGE TemplateHaskell #-}
2
3
3{-# OPTIONS_GHC -fno-warn-orphans #-}
4{-# OPTIONS_GHC -fno-warn-orphans #-}
4
5
@@ -40,6 +41,11 @@ test_nil = testGroup "nil" [
40 testCase "nil bytes" $ U.toByteString U.nil @?= BL.pack (replicate 16 0)
41 testCase "nil bytes" $ U.toByteString U.nil @?= BL.pack (replicate 16 0)
41 ]
42 ]
42
43
44+test_lift :: Test
45+test_lift = testCase "TH.Lift" $ do
46+ let uuid = U.fromWords64 123456789 987654321
47+ uuid @?= $( [| uuid |] )
48+
43test_conv :: Test
49test_conv :: Test
44test_conv = testGroup "conversions" [
50test_conv = testGroup "conversions" [
45 testCase "conv bytes to string" $
51 testCase "conv bytes to string" $
@@ -176,6 +182,7 @@ main = do
176 [ [
182 [ [
177 test_null,
183 test_null,
178 test_nil,
184 test_nil,
185+ test_lift,
179 test_conv,
186 test_conv,
180 test_fromByteString,
187 test_fromByteString,
181 test_fromWords,
188 test_fromWords,
uuid-types/uuid-types.cabal+10−8
@@ -1,6 +1,6 @@
1cabal-version: 1.12
1cabal-version: 1.12
2name: uuid-types
2name: uuid-types
3−version: 1.0.4
3+version: 1.0.5
4copyright:
4copyright:
5 (c) 2017-2018 Herbert Valerio Riedel
5 (c) 2017-2018 Herbert Valerio Riedel
6 (c) 2008-2014 Antoine Latter
6 (c) 2008-2014 Antoine Latter
@@ -45,13 +45,14 @@ source-repository head
45
45
46library
46library
47 build-depends:
47 build-depends:
48− base >=4.5 && <5
48+ base >=4.5 && <5
49− , binary >=0.5.1.0 && <0.9
49+ , binary >=0.5.1.0 && <0.9
50− , bytestring >=0.9.2.1 && <0.12
50+ , bytestring >=0.9.2.1 && <0.12
51− , deepseq >=1.3.0.0 && <1.5
51+ , deepseq >=1.3.0.0 && <1.5
52− , hashable >=1.2.7.0 && <1.4
52+ , hashable >=1.2.7.0 && <1.4
53− , random >=1.1 && <1.3
53+ , random >=1.1 && <1.3
54+ , template-haskell >=2.7.0.0 && <2.18
54− , text >=1.2.3.0 && <1.3
55+ , text >=1.2.3.0 && <1.3
55
56
56 exposed-modules: Data.UUID.Types
57 exposed-modules: Data.UUID.Types
57
58
@@ -82,6 +83,7 @@ test-suite testuuid
82 , binary
83 , binary
83 , bytestring
84 , bytestring
84 , uuid-types
85 , uuid-types
86+ , template-haskell
85
87
86 -- deps w/o inherited constraints
88 -- deps w/o inherited constraints
87 build-depends:
89 build-depends:
uuid/CHANGES.md+4
@@ -1,3 +1,7 @@
1+1.3.15
2+
3+- Add (Template Haskell) `Lift UUID` instance
4+
11.3.14
51.3.14
2
6
3- Use more compact heap object representation which saves 16 bytes on 64bit platforms.
7- Use more compact heap object representation which saves 16 bytes on 64bit platforms.
uuid/uuid.cabal+2−2
@@ -1,6 +1,6 @@
1cabal-version: 1.12
1cabal-version: 1.12
2name: uuid
2name: uuid
3−version: 1.3.14
3+version: 1.3.15
4copyright: (c) 2008-2014 Antoine Latter
4copyright: (c) 2008-2014 Antoine Latter
5author: Antoine Latter
5author: Antoine Latter
6maintainer: Oleg Grenrus <oleg.grenrus@iki.fi>
6maintainer: Oleg Grenrus <oleg.grenrus@iki.fi>
@@ -54,7 +54,7 @@ library
54 -- strict dependency on uuid-types,
54 -- strict dependency on uuid-types,
55 -- as we re-rexport datatype, thus leak instances etc.
55 -- as we re-rexport datatype, thus leak instances etc.
56 build-depends:
56 build-depends:
57− uuid-types >=1.0.4 && <1.0.5
57+ uuid-types >=1.0.5 && <1.0.6
58
58
59 exposed-modules:
59 exposed-modules:
60 Data.UUID
60 Data.UUID