Copyright | (c) Brent Yorgey 2016 |
---|---|
License | BSD3 (see LICENSE) |
Maintainer | byorgey@gmail.com |
Stability | experimental |
Portability | non-portable (multi-param classes, functional dependencies, undecidable instances) |
Safe Haskell | Safe |
Language | Haskell2010 |
Random monads that are lazy in the generator state. For a strict version, see Control.Monad.Random.Strict, which has the same interface.
Synopsis
- type Rand g = RandT g Identity
- liftRand :: (g -> (a, g)) -> Rand g a
- runRand :: Rand g a -> g -> (a, g)
- evalRand :: Rand g a -> g -> a
- execRand :: Rand g a -> g -> g
- mapRand :: ((a, g) -> (b, g)) -> Rand g a -> Rand g b
- withRand :: (g -> g) -> Rand g a -> Rand g a
- evalRandIO :: Rand StdGen a -> IO a
- data RandT g m a
- liftRandT :: (g -> m (a, g)) -> RandT g m a
- runRandT :: RandT g m a -> g -> m (a, g)
- evalRandT :: Monad m => RandT g m a -> g -> m a
- execRandT :: Monad m => RandT g m a -> g -> m g
- mapRandT :: (m (a, g) -> n (b, g)) -> RandT g m a -> RandT g n b
- withRandT :: (g -> g) -> RandT g m a -> RandT g m a
- evalRandTIO :: MonadIO m => RandT StdGen m a -> m a
- module System.Random
- module Control.Monad.Random.Class
- module Control.Monad
- module Control.Monad.Fix
- module Control.Monad.Trans
The Rand monad
:: (g -> (a, g)) | pure random transformer |
-> Rand g a | equivalent generator-passing computation |
Construct a random monad computation from a function.
(The inverse of runRand
.)
:: Rand g a | generator-passing computation to execute |
-> g | initial generator |
-> (a, g) | return value and final generator |
Unwrap a random monad computation as a function.
(The inverse of liftRand
.)
:: Rand g a | generator-passing computation to execute |
-> g | initial generator |
-> a | return value of the random computation |
:: Rand g a | generator-passing computation to execute |
-> g | initial generator |
-> g | final generator |
evalRandIO :: Rand StdGen a -> IO a Source #
Evaluate a random computation in the IO
monad, splitting the global
standard generator to get a new one for the computation.
The RandT monad transformer
A random transformer monad parameterized by:
g
- The generator.m
- The inner monad.
The return
function leaves the generator unchanged, while >>=
uses the
final generator of the first computation as the initial generator of the
second.
Instances
:: (g -> m (a, g)) | impure random transformer |
-> RandT g m a | equivalent generator-passing computation |
Construct a random monad computation from an impure function.
(The inverse of runRandT
.)
:: RandT g m a | generator-passing computation to execute |
-> g | initial generator |
-> m (a, g) | return value and final generator |
Unwrap a random monad computation as an impure function.
(The inverse of liftRandT
.)
evalRandTIO :: MonadIO m => RandT StdGen m a -> m a Source #
Evaluate a random computation that is embedded in the IO
monad,
splitting the global standard generator to get a new one for the
computation.
Some convenience re-exports
module System.Random
module Control.Monad.Random.Class
module Control.Monad
module Control.Monad.Fix
module Control.Monad.Trans