-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Random-number generation monad.
--
@package MonadRandom
@version 0.4
-- | A type class for random number generation monads. See
-- http://www.haskell.org/haskellwiki/NewMonads/MonadRandom for
-- the original version of this code.
--
-- Instances of this type class include Rand and monads created
-- using RandT.
module Control.Monad.Random.Class
-- | An interface to random number generation monads.
class Monad m => MonadRandom m
getRandom :: (MonadRandom m, Random a) => m a
getRandoms :: (MonadRandom m, Random a) => m [a]
getRandomR :: (MonadRandom m, Random a) => (a, a) -> m a
getRandomRs :: (MonadRandom m, 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 | m -> s
getSplit :: MonadSplit s m => m s
-- | A random number generation monad. See
-- http://www.haskell.org/haskellwiki/NewMonads/MonadRandom for
-- the original version of this code.
--
-- The actual interface is defined by MonadRandom.
--
--
-- - Computation type: Computations which consume random
-- values.
-- - Binding strategy: The computation proceeds in the same
-- fashion as the identity monad, but it carries a random number
-- generator that may be queried to generate random values.
-- - Useful for: Monte Carlo algorithms and simulating random
-- processes.
--
module Control.Monad.Random
-- | 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.
evalRandT :: Monad m => RandT g m a -> g -> m a
-- | Run a RandT computation using the generator g, returning the
-- result and the updated generator.
runRandT :: Monad m => RandT g m a -> g -> m (a, 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 updated version of g.
evalRand :: Rand g a -> g -> a
-- | Run a random computation using the generator g, returning the
-- result and the updated generator.
runRand :: Rand g a -> g -> (a, g)
-- | Evaluate a random computation in the IO monad, splitting the global
-- standard generator to get a new one for the computation.
evalRandIO :: Rand StdGen a -> IO a
-- | Sample a random value from a weighted list. The total weight of all
-- elements must not be 0.
fromList :: MonadRandom m => [(a, Rational)] -> m a
-- | Sample a value from a uniform distribution of a list of elements.
uniform :: MonadRandom m => [a] -> m a
-- | A basic random monad.
type Rand g = RandT g Identity
-- | A monad transformer which adds a random number generator to an
-- existing monad.
data RandT g m a
-- | Lift arbitrary action to Rand
liftRand :: (g -> (a, g)) -> Rand g a
-- | Lift arbitrary action to RandT
liftRandT :: Monad m => (g -> m (a, g)) -> RandT g m a
instance Functor m => Functor (RandT g m)
instance Monad m => Monad (RandT g m)
instance MonadTrans (RandT g)
instance MonadIO m => MonadIO (RandT g m)
instance MonadFix m => MonadFix (RandT g m)
instance MonadReader r m => MonadReader r (RandT g m)
instance MonadWriter w m => MonadWriter w (RandT g m)
instance MonadSplit StdGen IO
instance MonadRandom IO
instance MonadState s m => MonadState s (RandT g m)
instance MonadSplit g m => MonadSplit g (ContT r m)
instance MonadSplit g m => MonadSplit g (MaybeT m)
instance (Error e, MonadSplit g m) => MonadSplit g (ErrorT e m)
instance MonadSplit g m => MonadSplit g (ExceptT e m)
instance (MonadSplit g m, Monoid w) => MonadSplit g (RWST r w s m)
instance (MonadSplit g m, Monoid w) => MonadSplit g (RWST r w s m)
instance MonadSplit g m => MonadSplit g (ReaderT r m)
instance (MonadSplit g m, Monoid w) => MonadSplit g (WriterT w m)
instance (MonadSplit g m, Monoid w) => MonadSplit g (WriterT w m)
instance MonadSplit g m => MonadSplit g (StateT s m)
instance MonadSplit g m => MonadSplit g (StateT s m)
instance MonadSplit g m => MonadSplit g (IdentityT m)
instance MonadRandom m => MonadRandom (ContT r m)
instance MonadRandom m => MonadRandom (MaybeT m)
instance (Error e, MonadRandom m) => MonadRandom (ErrorT e m)
instance MonadRandom m => MonadRandom (ExceptT e m)
instance (MonadRandom m, Monoid w) => MonadRandom (RWST r w s m)
instance (MonadRandom m, Monoid w) => MonadRandom (RWST r w s m)
instance MonadRandom m => MonadRandom (ReaderT r m)
instance (MonadRandom m, Monoid w) => MonadRandom (WriterT w m)
instance (MonadRandom m, Monoid w) => MonadRandom (WriterT w m)
instance MonadRandom m => MonadRandom (StateT s m)
instance MonadRandom m => MonadRandom (StateT s m)
instance MonadRandom m => MonadRandom (IdentityT m)
instance (Monad m, RandomGen g) => MonadSplit g (RandT g m)
instance (Monad m, RandomGen g) => MonadRandom (RandT g m)
instance (Functor m, Monad m) => Applicative (RandT g m)