MonadRandom 0.1.1 → 0.1.2
raw patch · 3 files changed
+28/−4 lines, 3 filesnew-uploaderPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Control.Monad.Random: instance (Monad m, RandomGen g) => MonadSplit g (RandT g m)
+ Control.Monad.Random: instance (MonadSplit g m) => MonadSplit g (ReaderT r m)
+ Control.Monad.Random: instance (MonadSplit g m) => MonadSplit g (StateT s m)
+ Control.Monad.Random: instance (MonadSplit g m, Monoid w) => MonadSplit g (WriterT w m)
+ Control.Monad.Random: instance (RandomGen g) => MonadSplit g (Rand g)
+ Control.Monad.Random: instance MonadSplit StdGen IO
+ Control.Monad.Random.Class: class (Monad m) => MonadSplit s m
+ Control.Monad.Random.Class: getSplit :: (MonadSplit s m) => m s
Files
- Control/Monad/Random.hs +18/−3
- Control/Monad/Random/Class.hs +9/−0
- MonadRandom.cabal +1/−1
Control/Monad/Random.hs view
@@ -67,6 +67,9 @@ getRandomRs (x,y) = RandT . liftState $ first (randomRs (x,y)) . split +instance (Monad m, RandomGen g) => MonadSplit g (RandT g m) where+ getSplit = RandT . liftState $ split+ -- | Evaluate a RandT computation using the generator @g@. Note that the -- generator @g@ is not returned, so there's no way to recover the -- updated version of @g@.@@ -80,7 +83,7 @@ -- | A basic random monad. newtype Rand g a = Rand (RandT g Identity a)- deriving (Functor, Monad, MonadRandom)+ deriving (Functor, Monad, MonadRandom, MonadSplit g) -- | Evaluate a random computation using the generator @g@. Note that the -- generator @g@ is not returned, so there's no way to recover the@@ -116,7 +119,7 @@ getRandomR = lift . getRandomR getRandoms = lift getRandoms getRandomRs = lift . getRandomRs- + instance (MonadRandom m, Monoid w) => MonadRandom (WriterT w m) where getRandom = lift getRandom getRandomR = lift . getRandomR@@ -128,7 +131,16 @@ getRandomR = lift . getRandomR getRandoms = lift getRandoms getRandomRs = lift . getRandomRs- ++instance (MonadSplit g m) => MonadSplit g (StateT s m) where+ getSplit = lift getSplit++instance (MonadSplit g m, Monoid w) => MonadSplit g (WriterT w m) where+ getSplit = lift getSplit++instance (MonadSplit g m) => MonadSplit g (ReaderT r m) where+ getSplit = lift getSplit+ instance (MonadState s m, RandomGen g) => MonadState s (RandT g m) where get = lift get put = lift . put@@ -147,6 +159,9 @@ getRandomR = randomRIO getRandoms = fmap randoms newStdGen getRandomRs b = fmap (randomRs b) newStdGen++instance MonadSplit StdGen IO where+ getSplit = newStdGen {- $RandExample
Control/Monad/Random/Class.hs view
@@ -21,6 +21,8 @@ getRandomR, getRandoms, getRandomRs,+ MonadSplit,+ getSplit ) where import System.Random@@ -39,3 +41,10 @@ -- | Return an infinite stream of randomly-selected value of type @a@ -- in the range /(lo,hi)/. See 'System.Random.randomRs' for details. getRandomRs :: (Random a) => (a,a) -> m [a]++-- | An interface to monads with splittable state (as most random number generation monads will have).+-- The intention is that the 'getSplit' action splits the state, returning one half of the result, and+-- setting the new state to the other.+class (Monad m) => MonadSplit s m where+ getSplit :: m s+
MonadRandom.cabal view
@@ -1,6 +1,6 @@ Name: MonadRandom Build-type: Simple-Version: 0.1.1+Version: 0.1.2 Synopsis: Random-number generation monad. Description: Support for computations which consume random values. License: OtherLicense