This module provides functions useful for implementing new MonadRandom
and RandomSource
instances for state-abstractions containing PureMT
values (the pure pseudorandom generator provided by the
mersenne-random-pure64 package), as well as instances for some common
cases.
- getRandomPrimFromMTRef :: (Monad m, ModifyRef sr m PureMT) => sr -> Prim a -> m a
- getRandomPrimFromMTState :: MonadState PureMT m => Prim a -> m a
Documentation
getRandomPrimFromMTRef :: (Monad m, ModifyRef sr m PureMT) => sr -> Prim a -> m aSource
Given a mutable reference to a PureMT
generator, we can implement
RandomSource
for in any monad in which the reference can be modified.
getRandomPrimFromMTState :: MonadState PureMT m => Prim a -> m aSource
Similarly, getRandomPrimFromMTState x
can be used in any "state"
monad in the mtl sense whose state is a PureMT
generator.
Additionally, the standard mtl state monads have MonadRandom
instances
which do precisely that, allowing an easy conversion of RVar
s and
other Distribution
instances to "pure" random variables (e.g., by
runState . sample :: Distribution d t => d t -> PureMT -> (t, PureMT)
.
PureMT
in the type there can be replaced by StdGen
or anything else
satisfying MonadRandom (State s) => s
).