From 411c7e1dff70625251b234c45dafbea8bcf0d5de Mon Sep 17 00:00:00 2001 From: Alexey Kuleshevich Date: Fri, 24 Nov 2023 19:56:44 +0100 Subject: [PATCH] Add reference to a recent `FrozenGen` PR #149 in the changelog Also fixup example with `FrozenGen` instance in haddock --- CHANGELOG.md | 13 +++++++------ src/System/Random/Stateful.hs | 8 +++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc2cda35..5b89e41b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,12 @@ # 1.3.0 -* 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 `splitGen` and `splitMutableGen` -* Switch `randomM` and `randomRM` to use `FrozenGen` instead of `RandomGenM` -* Deprecate `RandomGenM` in favor of a more powerful `FrozenGen` +* Improve `FrozenGen` interface: [#149](https://github.com/haskell/random/pull/149) + * 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 `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) * Add default implementation for `uniformRM` using `Generics`: [#92](https://github.com/haskell/random/pull/92) diff --git a/src/System/Random/Stateful.hs b/src/System/Random/Stateful.hs index 0e42cc3c..963b38dd 100644 --- a/src/System/Random/Stateful.hs +++ b/src/System/Random/Stateful.hs @@ -795,6 +795,9 @@ applyTGen f (TGenM tvar) = do -- Here is an example instance for the monadic pseudo-random number generator -- from the @mwc-random@ package: -- +-- > import qualified System.Random.MWC as MWC +-- > import qualified Data.Vector.Generic as G +-- -- > instance (s ~ PrimState m, PrimMonad m) => StatefulGen (MWC.Gen s) m where -- > uniformWord8 = MWC.uniform -- > uniformWord16 = MWC.uniform @@ -804,8 +807,11 @@ applyTGen f (TGenM tvar) = do -- -- > instance PrimMonad m => FrozenGen MWC.Seed m where -- > type MutableGen MWC.Seed m = MWC.Gen (PrimState m) --- > thawGen = MWC.restore -- > freezeGen = MWC.save +-- > overwriteGen (Gen mv) (Seed v) = G.copy mv v +-- +-- > instance PrimMonad m => ThawedGen MWC.Seed m where +-- > thawGen = MWC.restore -- -- === @FrozenGen@ --