From 14ce716cbd268d505aa2a4f228ff66dcb33596e1 Mon Sep 17 00:00:00 2001 From: Alexey Kuleshevich Date: Mon, 20 Nov 2023 12:54:22 +0100 Subject: [PATCH] Rename splitFrozenGen to splitGen --- CHANGELOG.md | 2 +- src/System/Random/Internal.hs | 17 ++++------------- src/System/Random/Stateful.hs | 2 +- test/Spec/Stateful.hs | 10 +++++----- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 684f9475..bc2cda35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ * Move `thawGen` from `FreezeGen` into the new `ThawGen` type class. Fixes an issue with an unlawful instance of `StateGen` for `FreezeGen`. * Add `modifyGen` and `overwriteGen` to the `FrozenGen` type class -* Add `splitFrozenGen` and `splitMutableGen` +* Add `splitGen` and `splitMutableGen` * Switch `randomM` and `randomRM` to use `FrozenGen` instead of `RandomGenM` * Deprecate `RandomGenM` in favor of a more powerful `FrozenGen` * Add `isInRange` to `UniformRange`: [#78](https://github.com/haskell/random/pull/78) diff --git a/src/System/Random/Internal.hs b/src/System/Random/Internal.hs index 28031c92..39ba464f 100644 --- a/src/System/Random/Internal.hs +++ b/src/System/Random/Internal.hs @@ -31,7 +31,7 @@ module System.Random.Internal , StatefulGen(..) , FrozenGen(..) , ThawedGen(..) - , splitFrozenGen + , splitGen , splitMutableGen -- ** Standard pseudo-random number generator @@ -43,7 +43,6 @@ module System.Random.Internal -- ** Pure adapter , StateGen(..) , StateGenM(..) - , splitGen , runStateGen , runStateGen_ , runStateGenT @@ -372,15 +371,15 @@ class FrozenGen f m => ThawedGen f m where -- wrapper with one of the resulting generators and returns the other. -- -- @since 1.3.0 -splitFrozenGen :: (RandomGen f, FrozenGen f m) => MutableGen f m -> m f -splitFrozenGen = flip modifyGen split +splitGen :: (RandomGen f, FrozenGen f m) => MutableGen f m -> m f +splitGen = flip modifyGen split -- | Splits a pseudo-random number generator into two. Overwrites the mutable wrapper with -- one of the resulting generators and returns the other as a new mutable generator. -- -- @since 1.3.0 splitMutableGen :: (RandomGen f, ThawedGen f m) => MutableGen f m -> m (MutableGen f m) -splitMutableGen = splitFrozenGen >=> thawGen +splitMutableGen = splitGen >=> thawGen data MBA = MBA (MutableByteArray# RealWorld) @@ -533,14 +532,6 @@ instance (RandomGen g, MonadState g m) => FrozenGen (StateGen g) m where overwriteGen _ f = put (coerce f) {-# INLINE overwriteGen #-} --- | Splits a pseudo-random number generator into two. Updates the state with --- one of the resulting generators and returns the other. --- --- @since 1.2.0 -splitGen :: (MonadState g m, RandomGen g) => m g -splitGen = state split -{-# INLINE splitGen #-} - -- | Runs a monadic generating action in the `State` monad using a pure -- pseudo-random number generator. -- diff --git a/src/System/Random/Stateful.hs b/src/System/Random/Stateful.hs index 0b3c2a11..3adc53b6 100644 --- a/src/System/Random/Stateful.hs +++ b/src/System/Random/Stateful.hs @@ -35,7 +35,7 @@ module System.Random.Stateful , withMutableGen_ , randomM , randomRM - , splitFrozenGen + , splitGen , splitMutableGen -- ** Deprecated diff --git a/test/Spec/Stateful.hs b/test/Spec/Stateful.hs index 7a6c2aa8..bacd72c6 100644 --- a/test/Spec/Stateful.hs +++ b/test/Spec/Stateful.hs @@ -107,7 +107,7 @@ splitMutableGenSpec :: -> Property IO splitMutableGenSpec toIO frozen = monadic $ toIO $ do - (sfg1, fg1) <- withMutableGen frozen splitFrozenGen + (sfg1, fg1) <- withMutableGen frozen splitGen (smg2, fg2) <- withMutableGen frozen splitMutableGen sfg3 <- freezeGen smg2 pure $ fg1 == fg2 && sfg1 == sfg3 @@ -128,7 +128,7 @@ frozenGenSpecFor toIO px = forAll $ \(fs :: [f]) -> indepMutableGenSpec toIO fs , testProperty "immutable frozen generators" $ forAll $ \(f :: f) -> immutableFrozenGenSpec toIO f - , testProperty "splitFrozen" $ + , testProperty "splitGen" $ forAll $ \(f :: f) -> splitMutableGenSpec toIO f ] @@ -171,14 +171,14 @@ statefulSpecFor fromStdGen toStdGen runStatefulGen = statefulSpec :: TestTree statefulSpec = testGroup - "Stateful" - [ testGroup "FrozenGen" + "StatefulGen" + [ testGroup "ThawedGen" [ frozenGenSpecFor id (Proxy :: Proxy (IOGen StdGen)) , frozenGenSpecFor id (Proxy :: Proxy (AtomicGen StdGen)) , frozenGenSpecFor stToIO (Proxy :: Proxy (STGen StdGen)) , frozenGenSpecFor atomically (Proxy :: Proxy (TGen StdGen)) ] - , testGroup "StatefulGen" + , testGroup "FrozenGen" [ statefulSpecFor StateGen unStateGen runStateGenT , statefulSpecFor IOGen unIOGen $ \g action -> do mg <- newIOGenM (unIOGen g)