on master help sign in
Merge pull request #62 from haskell-hvr/lift-instance

Add instance Lift UUID

commite8dc7126582ba4d3abc5e0f26dc1d8477caab01e authorOleg Grenrus <oleg.grenrus@iki.fi> dateMon 3 May 2021, 10:40 (5 years ago) parentca5026ede0700f
7 files changed+67−22
uuid-bench/uuid-bench.cabal+13−12 uuid-types/ChangeLog.md+4 uuid-types/src/Data/UUID/Types/Internal.hs+27 uuid-types/tests/TestUUID.hs+7 uuid-types/uuid-types.cabal+10−8 uuid/CHANGES.md+4 uuid/uuid.cabal+2−2
uuid-bench/uuid-bench.cabal+13−12
@@ -32,18 +32,19 @@ source-repository head
3232
3333library
3434 build-depends:
35− base >=4.9 && <5
36− , binary >=0.5.1.0 && <0.9
37− , bytestring >=0.9.2.1 && <0.12
38− , cryptohash-md5 >=0.11.100 && <0.12
39− , cryptohash-sha1 >=0.11.100 && <0.12
40− , deepseq >=1.3.0.0 && <1.5
41− , entropy >=0.3.7 && <0.5
42− , hashable >=1.2.7.0 && <1.4
43− , network-info >=0.2 && <0.3
44− , random >=1.1 && <1.3
45− , text >=1.2.3.0 && <1.3
46− , time >=1.4 && <1.12
35+ base >=4.9 && <5
36+ , binary >=0.5.1.0 && <0.9
37+ , bytestring >=0.9.2.1 && <0.12
38+ , cryptohash-md5 >=0.11.100 && <0.12
39+ , cryptohash-sha1 >=0.11.100 && <0.12
40+ , deepseq >=1.3.0.0 && <1.5
41+ , entropy >=0.3.7 && <0.5
42+ , hashable >=1.2.7.0 && <1.4
43+ , network-info >=0.2 && <0.3
44+ , random >=1.1 && <1.3
45+ , template-haskell >=2.7.0.0 && <2.18
46+ , text >=1.2.3.0 && <1.3
47+ , time >=1.4 && <1.12
4748
4849 -- uuid modules
4950 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+
15## 1.0.4.0
26
37- Declare `Data.UUID.Types` module "`Trustworthy`" with respect to SafeHaskell.
uuid-types/src/Data/UUID/Types/Internal.hs+27
@@ -5,6 +5,10 @@
55#if __GLASGOW_HASKELL__ >= 704
66{-# LANGUAGE Unsafe #-}
77#endif
8+#if __GLASGOW_HASKELL__ >=800
9+{-# LANGUAGE DeriveLift #-}
10+{-# LANGUAGE StandaloneDeriving #-}
11+#endif
812
913{-# OPTIONS_HADDOCK hide #-}
1014
@@ -79,6 +83,12 @@ import System.Random.Stateful (Uniform (..), uniformWord64)
7983import System.Random (Random (..), next)
8084#endif
8185
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
8292
8393-- | Type representing <https://en.wikipedia.org/wiki/UUID Universally Unique Identifiers (UUID)> as specified in
8494-- <http://tools.ietf.org/html/rfc4122 RFC 4122>.
@@ -619,3 +629,20 @@ unsafeShiftR = shiftR
619629{-# INLINE unsafeShiftL #-}
620630unsafeShiftL = shiftL
621631#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 @@
11{-# LANGUAGE ViewPatterns #-}
2+{-# LANGUAGE TemplateHaskell #-}
23
34{-# OPTIONS_GHC -fno-warn-orphans #-}
45
@@ -40,6 +41,11 @@ test_nil = testGroup "nil" [
4041 testCase "nil bytes" $ U.toByteString U.nil @?= BL.pack (replicate 16 0)
4142 ]
4243
44+test_lift :: Test
45+test_lift = testCase "TH.Lift" $ do
46+ let uuid = U.fromWords64 123456789 987654321
47+ uuid @?= $( [| uuid |] )
48+
4349test_conv :: Test
4450test_conv = testGroup "conversions" [
4551 testCase "conv bytes to string" $
@@ -176,6 +182,7 @@ main = do
176182 [ [
177183 test_null,
178184 test_nil,
185+ test_lift,
179186 test_conv,
180187 test_fromByteString,
181188 test_fromWords,
uuid-types/uuid-types.cabal+10−8
@@ -1,6 +1,6 @@
11cabal-version: 1.12
22name: uuid-types
3−version: 1.0.4
3+version: 1.0.5
44copyright:
55 (c) 2017-2018 Herbert Valerio Riedel
66 (c) 2008-2014 Antoine Latter
@@ -45,13 +45,14 @@ source-repository head
4545
4646library
4747 build-depends:
48− base >=4.5 && <5
49− , binary >=0.5.1.0 && <0.9
50− , bytestring >=0.9.2.1 && <0.12
51− , deepseq >=1.3.0.0 && <1.5
52− , hashable >=1.2.7.0 && <1.4
53− , random >=1.1 && <1.3
54− , text >=1.2.3.0 && <1.3
48+ base >=4.5 && <5
49+ , binary >=0.5.1.0 && <0.9
50+ , bytestring >=0.9.2.1 && <0.12
51+ , deepseq >=1.3.0.0 && <1.5
52+ , hashable >=1.2.7.0 && <1.4
53+ , random >=1.1 && <1.3
54+ , template-haskell >=2.7.0.0 && <2.18
55+ , text >=1.2.3.0 && <1.3
5556
5657 exposed-modules: Data.UUID.Types
5758
@@ -82,6 +83,7 @@ test-suite testuuid
8283 , binary
8384 , bytestring
8485 , uuid-types
86+ , template-haskell
8587
8688 -- deps w/o inherited constraints
8789 build-depends:
uuid/CHANGES.md+4
@@ -1,3 +1,7 @@
1+1.3.15
2+
3+- Add (Template Haskell) `Lift UUID` instance
4+
151.3.14
26
37- Use more compact heap object representation which saves 16 bytes on 64bit platforms.
uuid/uuid.cabal+2−2
@@ -1,6 +1,6 @@
11cabal-version: 1.12
22name: uuid
3−version: 1.3.14
3+version: 1.3.15
44copyright: (c) 2008-2014 Antoine Latter
55author: Antoine Latter
66maintainer: Oleg Grenrus <oleg.grenrus@iki.fi>
@@ -54,7 +54,7 @@ library
5454 -- strict dependency on uuid-types,
5555 -- as we re-rexport datatype, thus leak instances etc.
5656 build-depends:
57− uuid-types >=1.0.4 && <1.0.5
57+ uuid-types >=1.0.5 && <1.0.6
5858
5959 exposed-modules:
6060 Data.UUID