12
12
-- | Generate example CBOR given a CDDL specification
13
13
module Codec.CBOR.Cuddle.CBOR.Gen (generateCBORTerm , generateCBORTerm' ) where
14
14
15
- import qualified Control.Monad.State.Strict as MTL
16
15
import Capability.Reader
17
16
import Capability.Sink (HasSink )
18
17
import Capability.Source (HasSource , MonadState (.. ))
@@ -34,6 +33,7 @@ import Codec.CBOR.Write qualified as CBOR
34
33
import Control.Monad (join , replicateM , (<=<) )
35
34
import Control.Monad.Reader (Reader , runReader )
36
35
import Control.Monad.State.Strict (StateT , runStateT )
36
+ import Control.Monad.State.Strict qualified as MTL
37
37
import Data.Bifunctor (second )
38
38
import Data.ByteString (ByteString )
39
39
import Data.ByteString.Base16 qualified as Base16
@@ -54,6 +54,11 @@ import System.Random.Stateful (
54
54
randomM ,
55
55
uniformByteStringM ,
56
56
)
57
+ #if MIN_VERSION_random(1,3,0)
58
+ import System.Random.Stateful (
59
+ SplitGen (.. )
60
+ )
61
+ #endif
57
62
58
63
--------------------------------------------------------------------------------
59
64
-- Generator infrastructure
@@ -81,9 +86,21 @@ instance RandomGen g => RandomGen (GenState g) where
81
86
genWord16 = withRandomSeed genWord16
82
87
genWord32 = withRandomSeed genWord32
83
88
genWord64 = withRandomSeed genWord64
84
- split s =
85
- case split (randomSeed s) of
86
- (gen', gen) -> (s {randomSeed = gen'}, s {randomSeed = gen})
89
+ #if MIN_VERSION_random(1,3,0)
90
+ split = error " Split was deprecated and should no longer used. Use `splitGen` instead"
91
+ #else
92
+ split = splitGenStateWith split
93
+ #endif
94
+
95
+ #if MIN_VERSION_random(1,3,0)
96
+ instance SplitGen g => SplitGen (GenState g ) where
97
+ splitGen = splitGenStateWith splitGen
98
+ #endif
99
+
100
+ splitGenStateWith :: (g -> (g , g )) -> GenState g -> (GenState g , GenState g )
101
+ splitGenStateWith f s =
102
+ case f (randomSeed s) of
103
+ (gen', gen) -> (s {randomSeed = gen'}, s {randomSeed = gen})
87
104
88
105
withRandomSeed :: (t -> (a , g )) -> GenState t -> (a , GenState g )
89
106
withRandomSeed f s =
0 commit comments