Skip to content

Commit dfa86b9

Browse files
committed
Add support for random-1.3
1 parent 3129d8f commit dfa86b9

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

cuddle.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ library
8181
ordered-containers ^>=0.2.4,
8282
parser-combinators ^>=1.3,
8383
prettyprinter ^>=1.7.1,
84-
random <1.3,
84+
random >=1.2,
8585
regex-tdfa ^>=1.3.2,
8686
scientific ^>=0.3.8,
8787
text >=2.0.2 && <2.2,

src/Codec/CBOR/Cuddle/CBOR/Gen.hs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
-- | Generate example CBOR given a CDDL specification
1313
module Codec.CBOR.Cuddle.CBOR.Gen (generateCBORTerm, generateCBORTerm') where
1414

15-
import qualified Control.Monad.State.Strict as MTL
1615
import Capability.Reader
1716
import Capability.Sink (HasSink)
1817
import Capability.Source (HasSource, MonadState (..))
@@ -34,6 +33,7 @@ import Codec.CBOR.Write qualified as CBOR
3433
import Control.Monad (join, replicateM, (<=<))
3534
import Control.Monad.Reader (Reader, runReader)
3635
import Control.Monad.State.Strict (StateT, runStateT)
36+
import Control.Monad.State.Strict qualified as MTL
3737
import Data.Bifunctor (second)
3838
import Data.ByteString (ByteString)
3939
import Data.ByteString.Base16 qualified as Base16
@@ -54,6 +54,11 @@ import System.Random.Stateful (
5454
randomM,
5555
uniformByteStringM,
5656
)
57+
#if MIN_VERSION_random(1,3,0)
58+
import System.Random.Stateful (
59+
SplitGen (..)
60+
)
61+
#endif
5762

5863
--------------------------------------------------------------------------------
5964
-- Generator infrastructure
@@ -81,9 +86,21 @@ instance RandomGen g => RandomGen (GenState g) where
8186
genWord16 = withRandomSeed genWord16
8287
genWord32 = withRandomSeed genWord32
8388
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})
87104

88105
withRandomSeed :: (t -> (a, g)) -> GenState t -> (a, GenState g)
89106
withRandomSeed f s =

0 commit comments

Comments
 (0)