Skip to content

Commit

Permalink
Implement modifyGen and ThawedGen for random-1.3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Nov 24, 2023
1 parent 03214a9 commit 7573784
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion System/Random/MWC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,17 @@ instance (s ~ PrimState m, PrimMonad m) => Random.StatefulGen (Gen s) m where
-- | @since 0.15.0.0
instance PrimMonad m => Random.FrozenGen Seed m where
type MutableGen Seed m = Gen (PrimState m)
thawGen = restore
freezeGen = save
#if MIN_VERSION_random(1,3,0)
modifyGen gen@(Gen mv) f = do
seed <- save gen
case f seed of
(a, Seed v) -> a <$ G.copy mv v
overwriteGen (Gen mv) (Seed v) = G.copy mv v

instance PrimMonad m => Random.ThawedGen Seed m where
#endif
thawGen = restore

-- | Convert vector to 'Seed'. It acts similarly to 'initialize' and
-- will accept any vector. If you want to pass seed immediately to
Expand Down

0 comments on commit 7573784

Please sign in to comment.