{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Control.Monad.Trans.Random.Lazy
(
Rand,
liftRand,
runRand,
evalRand,
execRand,
mapRand,
withRand,
evalRandIO,
RandT,
liftRandT,
runRandT,
evalRandT,
execRandT,
mapRandT,
withRandT,
liftCallCC,
liftCallCC',
liftCatch,
liftListen,
liftPass,
evalRandTIO,
RandGen(..),
withRandGen,
withRandGen_,
) where
import Control.Applicative ( Alternative )
import Control.Arrow (first)
import Control.Monad ( liftM, MonadPlus )
import Control.Monad.Cont.Class (MonadCont(..))
import Control.Monad.Error.Class ( MonadError(..) )
import qualified Control.Monad.Fail as Fail
import Control.Monad.Fix ( MonadFix )
import Control.Monad.IO.Class ( MonadIO(..) )
import Control.Monad.Primitive ( PrimMonad(..) )
import Control.Monad.Random.Class ( MonadInterleave(..), MonadSplit(..), MonadRandom(..) )
import Control.Monad.RWS.Class ( MonadState(..), MonadRWS, MonadReader, MonadWriter )
import Control.Monad.Signatures ( Listen, Pass, CallCC, Catch )
import Control.Monad.Trans.Class ( MonadTrans(..) )
import qualified Control.Monad.Trans.State.Lazy as LazyState
import Control.Monad.Trans.Random.Strict (RandGen(..))
import Data.Functor.Identity ( Identity(runIdentity) )
#if MIN_VERSION_random(1,2,0)
import System.Random.Stateful
#else
import System.Random
#endif
type Rand g = RandT g Identity
liftRand
:: (g -> (a, g))
-> Rand g a
liftRand :: forall g a. (g -> (a, g)) -> Rand g a
liftRand = forall g (m :: * -> *) a. StateT g m a -> RandT g m a
RandT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state
runRand
:: Rand g a
-> g
-> (a, g)
runRand :: forall g a. Rand g a -> g -> (a, g)
runRand Rand g a
t = forall a. Identity a -> a
runIdentity forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall g (m :: * -> *) a. RandT g m a -> g -> m (a, g)
runRandT Rand g a
t
evalRand
:: Rand g a
-> g
-> a
evalRand :: forall g a. Rand g a -> g -> a
evalRand Rand g a
t = forall a. Identity a -> a
runIdentity forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) g a. Monad m => RandT g m a -> g -> m a
evalRandT Rand g a
t
execRand
:: Rand g a
-> g
-> g
execRand :: forall g a. Rand g a -> g -> g
execRand Rand g a
t = forall a. Identity a -> a
runIdentity forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) g a. Monad m => RandT g m a -> g -> m g
execRandT Rand g a
t
mapRand :: ((a, g) -> (b, g)) -> Rand g a -> Rand g b
mapRand :: forall a g b. ((a, g) -> (b, g)) -> Rand g a -> Rand g b
mapRand (a, g) -> (b, g)
f = forall (m :: * -> *) a g (n :: * -> *) b.
(m (a, g) -> n (b, g)) -> RandT g m a -> RandT g n b
mapRandT (forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (a, g) -> (b, g)
f)
withRand :: (g -> g) -> Rand g a -> Rand g a
withRand :: forall g a. (g -> g) -> Rand g a -> Rand g a
withRand = forall g (m :: * -> *) a. (g -> g) -> RandT g m a -> RandT g m a
withRandT
newtype RandT g m a = RandT { forall g (m :: * -> *) a. RandT g m a -> StateT g m a
unRandT :: LazyState.StateT g m a }
deriving (forall a b. a -> RandT g m b -> RandT g m a
forall a b. (a -> b) -> RandT g m a -> RandT g m b
forall g (m :: * -> *) a b.
Functor m =>
a -> RandT g m b -> RandT g m a
forall g (m :: * -> *) a b.
Functor m =>
(a -> b) -> RandT g m a -> RandT g m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> RandT g m b -> RandT g m a
$c<$ :: forall g (m :: * -> *) a b.
Functor m =>
a -> RandT g m b -> RandT g m a
fmap :: forall a b. (a -> b) -> RandT g m a -> RandT g m b
$cfmap :: forall g (m :: * -> *) a b.
Functor m =>
(a -> b) -> RandT g m a -> RandT g m b
Functor, forall a. a -> RandT g m a
forall a b. RandT g m a -> RandT g m b -> RandT g m a
forall a b. RandT g m a -> RandT g m b -> RandT g m b
forall a b. RandT g m (a -> b) -> RandT g m a -> RandT g m b
forall a b c.
(a -> b -> c) -> RandT g m a -> RandT g m b -> RandT g m c
forall {g} {m :: * -> *}. Monad m => Functor (RandT g m)
forall g (m :: * -> *) a. Monad m => a -> RandT g m a
forall g (m :: * -> *) a b.
Monad m =>
RandT g m a -> RandT g m b -> RandT g m a
forall g (m :: * -> *) a b.
Monad m =>
RandT g m a -> RandT g m b -> RandT g m b
forall g (m :: * -> *) a b.
Monad m =>
RandT g m (a -> b) -> RandT g m a -> RandT g m b
forall g (m :: * -> *) a b c.
Monad m =>
(a -> b -> c) -> RandT g m a -> RandT g m b -> RandT g m c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: forall a b. RandT g m a -> RandT g m b -> RandT g m a
$c<* :: forall g (m :: * -> *) a b.
Monad m =>
RandT g m a -> RandT g m b -> RandT g m a
*> :: forall a b. RandT g m a -> RandT g m b -> RandT g m b
$c*> :: forall g (m :: * -> *) a b.
Monad m =>
RandT g m a -> RandT g m b -> RandT g m b
liftA2 :: forall a b c.
(a -> b -> c) -> RandT g m a -> RandT g m b -> RandT g m c
$cliftA2 :: forall g (m :: * -> *) a b c.
Monad m =>
(a -> b -> c) -> RandT g m a -> RandT g m b -> RandT g m c
<*> :: forall a b. RandT g m (a -> b) -> RandT g m a -> RandT g m b
$c<*> :: forall g (m :: * -> *) a b.
Monad m =>
RandT g m (a -> b) -> RandT g m a -> RandT g m b
pure :: forall a. a -> RandT g m a
$cpure :: forall g (m :: * -> *) a. Monad m => a -> RandT g m a
Applicative, forall a. RandT g m a
forall a. RandT g m a -> RandT g m [a]
forall a. RandT g m a -> RandT g m a -> RandT g m a
forall {g} {m :: * -> *}. MonadPlus m => Applicative (RandT g m)
forall g (m :: * -> *) a. MonadPlus m => RandT g m a
forall g (m :: * -> *) a.
MonadPlus m =>
RandT g m a -> RandT g m [a]
forall g (m :: * -> *) a.
MonadPlus m =>
RandT g m a -> RandT g m a -> RandT g m a
forall (f :: * -> *).
Applicative f
-> (forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
many :: forall a. RandT g m a -> RandT g m [a]
$cmany :: forall g (m :: * -> *) a.
MonadPlus m =>
RandT g m a -> RandT g m [a]
some :: forall a. RandT g m a -> RandT g m [a]
$csome :: forall g (m :: * -> *) a.
MonadPlus m =>
RandT g m a -> RandT g m [a]
<|> :: forall a. RandT g m a -> RandT g m a -> RandT g m a
$c<|> :: forall g (m :: * -> *) a.
MonadPlus m =>
RandT g m a -> RandT g m a -> RandT g m a
empty :: forall a. RandT g m a
$cempty :: forall g (m :: * -> *) a. MonadPlus m => RandT g m a
Alternative, forall a. a -> RandT g m a
forall a b. RandT g m a -> RandT g m b -> RandT g m b
forall a b. RandT g m a -> (a -> RandT g m b) -> RandT g m b
forall g (m :: * -> *). Monad m => Applicative (RandT g m)
forall g (m :: * -> *) a. Monad m => a -> RandT g m a
forall g (m :: * -> *) a b.
Monad m =>
RandT g m a -> RandT g m b -> RandT g m b
forall g (m :: * -> *) a b.
Monad m =>
RandT g m a -> (a -> RandT g m b) -> RandT g m b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: forall a. a -> RandT g m a
$creturn :: forall g (m :: * -> *) a. Monad m => a -> RandT g m a
>> :: forall a b. RandT g m a -> RandT g m b -> RandT g m b
$c>> :: forall g (m :: * -> *) a b.
Monad m =>
RandT g m a -> RandT g m b -> RandT g m b
>>= :: forall a b. RandT g m a -> (a -> RandT g m b) -> RandT g m b
$c>>= :: forall g (m :: * -> *) a b.
Monad m =>
RandT g m a -> (a -> RandT g m b) -> RandT g m b
Monad, forall a. RandT g m a
forall a. RandT g m a -> RandT g m a -> RandT g m a
forall {g} {m :: * -> *}. MonadPlus m => Monad (RandT g m)
forall g (m :: * -> *). MonadPlus m => Alternative (RandT g m)
forall g (m :: * -> *) a. MonadPlus m => RandT g m a
forall g (m :: * -> *) a.
MonadPlus m =>
RandT g m a -> RandT g m a -> RandT g m a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
mplus :: forall a. RandT g m a -> RandT g m a -> RandT g m a
$cmplus :: forall g (m :: * -> *) a.
MonadPlus m =>
RandT g m a -> RandT g m a -> RandT g m a
mzero :: forall a. RandT g m a
$cmzero :: forall g (m :: * -> *) a. MonadPlus m => RandT g m a
MonadPlus, forall g (m :: * -> *) a. Monad m => m a -> RandT g m a
forall (m :: * -> *) a. Monad m => m a -> RandT g m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: forall (m :: * -> *) a. Monad m => m a -> RandT g m a
$clift :: forall g (m :: * -> *) a. Monad m => m a -> RandT g m a
MonadTrans, forall a. IO a -> RandT g m a
forall {g} {m :: * -> *}. MonadIO m => Monad (RandT g m)
forall g (m :: * -> *) a. MonadIO m => IO a -> RandT g m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: forall a. IO a -> RandT g m a
$cliftIO :: forall g (m :: * -> *) a. MonadIO m => IO a -> RandT g m a
MonadIO, forall a. (a -> RandT g m a) -> RandT g m a
forall {g} {m :: * -> *}. MonadFix m => Monad (RandT g m)
forall g (m :: * -> *) a.
MonadFix m =>
(a -> RandT g m a) -> RandT g m a
forall (m :: * -> *).
Monad m -> (forall a. (a -> m a) -> m a) -> MonadFix m
mfix :: forall a. (a -> RandT g m a) -> RandT g m a
$cmfix :: forall g (m :: * -> *) a.
MonadFix m =>
(a -> RandT g m a) -> RandT g m a
MonadFix, MonadReader r, MonadWriter w)
liftRandT
:: (g -> m (a, g))
-> RandT g m a
liftRandT :: forall g (m :: * -> *) a. (g -> m (a, g)) -> RandT g m a
liftRandT = forall g (m :: * -> *) a. StateT g m a -> RandT g m a
RandT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
LazyState.StateT
runRandT
:: RandT g m a
-> g
-> m (a, g)
runRandT :: forall g (m :: * -> *) a. RandT g m a -> g -> m (a, g)
runRandT = forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
LazyState.runStateT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall g (m :: * -> *) a. RandT g m a -> StateT g m a
unRandT
evalRandT :: (Monad m) => RandT g m a -> g -> m a
evalRandT :: forall (m :: * -> *) g a. Monad m => RandT g m a -> g -> m a
evalRandT = forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
LazyState.evalStateT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall g (m :: * -> *) a. RandT g m a -> StateT g m a
unRandT
execRandT :: (Monad m) => RandT g m a -> g -> m g
execRandT :: forall (m :: * -> *) g a. Monad m => RandT g m a -> g -> m g
execRandT = forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m s
LazyState.execStateT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall g (m :: * -> *) a. RandT g m a -> StateT g m a
unRandT
mapRandT :: (m (a, g) -> n (b, g)) -> RandT g m a -> RandT g n b
mapRandT :: forall (m :: * -> *) a g (n :: * -> *) b.
(m (a, g) -> n (b, g)) -> RandT g m a -> RandT g n b
mapRandT m (a, g) -> n (b, g)
f = forall g (m :: * -> *) a. StateT g m a -> RandT g m a
RandT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a s (n :: * -> *) b.
(m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b
LazyState.mapStateT m (a, g) -> n (b, g)
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall g (m :: * -> *) a. RandT g m a -> StateT g m a
unRandT
withRandT :: (g -> g) -> RandT g m a -> RandT g m a
withRandT :: forall g (m :: * -> *) a. (g -> g) -> RandT g m a -> RandT g m a
withRandT g -> g
f = forall g (m :: * -> *) a. StateT g m a -> RandT g m a
RandT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. (s -> s) -> StateT s m a -> StateT s m a
LazyState.withStateT g -> g
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall g (m :: * -> *) a. RandT g m a -> StateT g m a
unRandT
instance (MonadCont m) => MonadCont (RandT g m) where
callCC :: forall a b. ((a -> RandT g m b) -> RandT g m a) -> RandT g m a
callCC = forall (m :: * -> *) a g b.
CallCC m (a, g) (b, g) -> CallCC (RandT g m) a b
liftCallCC' forall (m :: * -> *) a b. MonadCont m => ((a -> m b) -> m a) -> m a
callCC
instance (MonadError e m) => MonadError e (RandT g m) where
throwError :: forall a. e -> RandT g m a
throwError = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError
catchError :: forall a. RandT g m a -> (e -> RandT g m a) -> RandT g m a
catchError = forall e (m :: * -> *) a g.
Catch e m (a, g) -> Catch e (RandT g m) a
liftCatch forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
catchError
instance (MonadReader r m, MonadWriter w m, MonadState s m) => MonadRWS r w s (RandT g m)
instance (RandomGen g, Monad m) => MonadRandom (RandT g m) where
getRandomR :: forall a. Random a => (a, a) -> RandT g m a
getRandomR (a, a)
lohi = forall g (m :: * -> *) a. StateT g m a -> RandT g m a
RandT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state forall a b. (a -> b) -> a -> b
$ forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (a, a)
lohi
getRandom :: forall a. Random a => RandT g m a
getRandom = forall g (m :: * -> *) a. StateT g m a -> RandT g m a
RandT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state forall a b. (a -> b) -> a -> b
$ forall a g. (Random a, RandomGen g) => g -> (a, g)
random
getRandomRs :: forall a. Random a => (a, a) -> RandT g m [a]
getRandomRs (a, a)
lohi = forall g (m :: * -> *) a. StateT g m a -> RandT g m a
RandT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state forall a b. (a -> b) -> a -> b
$ forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (forall a g. (Random a, RandomGen g) => (a, a) -> g -> [a]
randomRs (a, a)
lohi) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall g. RandomGen g => g -> (g, g)
split
getRandoms :: forall a. Random a => RandT g m [a]
getRandoms = forall g (m :: * -> *) a. StateT g m a -> RandT g m a
RandT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state forall a b. (a -> b) -> a -> b
$ forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first forall a g. (Random a, RandomGen g) => g -> [a]
randoms forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall g. RandomGen g => g -> (g, g)
split
instance (RandomGen g, Monad m) => MonadSplit g (RandT g m) where
getSplit :: RandT g m g
getSplit = forall g (m :: * -> *) a. StateT g m a -> RandT g m a
RandT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state forall a b. (a -> b) -> a -> b
$ forall g. RandomGen g => g -> (g, g)
split
instance (Monad m, RandomGen g) => MonadInterleave (RandT g m) where
interleave :: forall a. RandT g m a -> RandT g m a
interleave (RandT StateT g m a
m) = forall g (m :: * -> *) a. (g -> m (a, g)) -> RandT g m a
liftRandT forall a b. (a -> b) -> a -> b
$ \g
g -> case forall g. RandomGen g => g -> (g, g)
split g
g of
(g
gl, g
gr) -> forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\(a, g)
p -> (forall a b. (a, b) -> a
fst (a, g)
p, g
gr)) forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
LazyState.runStateT StateT g m a
m g
gl
instance (MonadState s m) => MonadState s (RandT g m) where
get :: RandT g m s
get = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall s (m :: * -> *). MonadState s m => m s
get
put :: s -> RandT g m ()
put = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *). MonadState s m => s -> m ()
put
instance PrimMonad m => PrimMonad (RandT s m) where
type PrimState (RandT s m) = PrimState m
primitive :: forall a.
(State# (PrimState (RandT s m))
-> (# State# (PrimState (RandT s m)), a #))
-> RandT s m a
primitive = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive
instance Fail.MonadFail m => Fail.MonadFail (RandT g m) where
fail :: forall a. String -> RandT g m a
fail = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadFail m => String -> m a
Fail.fail
liftCallCC :: CallCC m (a, g) (b, g) -> CallCC (RandT g m) a b
liftCallCC :: forall (m :: * -> *) a g b.
CallCC m (a, g) (b, g) -> CallCC (RandT g m) a b
liftCallCC CallCC m (a, g) (b, g)
callCC_ (a -> RandT g m b) -> RandT g m a
f = forall g (m :: * -> *) a. StateT g m a -> RandT g m a
RandT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a s b.
CallCC m (a, s) (b, s) -> CallCC (StateT s m) a b
LazyState.liftCallCC CallCC m (a, g) (b, g)
callCC_ forall a b. (a -> b) -> a -> b
$ \a -> StateT g m b
c -> forall g (m :: * -> *) a. RandT g m a -> StateT g m a
unRandT ((a -> RandT g m b) -> RandT g m a
f (forall g (m :: * -> *) a. StateT g m a -> RandT g m a
RandT forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> StateT g m b
c))
liftCallCC' :: CallCC m (a, g) (b, g) -> CallCC (RandT g m) a b
liftCallCC' :: forall (m :: * -> *) a g b.
CallCC m (a, g) (b, g) -> CallCC (RandT g m) a b
liftCallCC' CallCC m (a, g) (b, g)
callCC_ (a -> RandT g m b) -> RandT g m a
f = forall g (m :: * -> *) a. StateT g m a -> RandT g m a
RandT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a s b.
CallCC m (a, s) (b, s) -> CallCC (StateT s m) a b
LazyState.liftCallCC' CallCC m (a, g) (b, g)
callCC_ forall a b. (a -> b) -> a -> b
$ \a -> StateT g m b
c -> forall g (m :: * -> *) a. RandT g m a -> StateT g m a
unRandT ((a -> RandT g m b) -> RandT g m a
f (forall g (m :: * -> *) a. StateT g m a -> RandT g m a
RandT forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> StateT g m b
c))
liftCatch :: Catch e m (a, g) -> Catch e (RandT g m) a
liftCatch :: forall e (m :: * -> *) a g.
Catch e m (a, g) -> Catch e (RandT g m) a
liftCatch Catch e m (a, g)
catchE_ RandT g m a
m e -> RandT g m a
f = forall g (m :: * -> *) a. StateT g m a -> RandT g m a
RandT forall a b. (a -> b) -> a -> b
$ forall e (m :: * -> *) a s.
Catch e m (a, s) -> Catch e (StateT s m) a
LazyState.liftCatch Catch e m (a, g)
catchE_ (forall g (m :: * -> *) a. RandT g m a -> StateT g m a
unRandT RandT g m a
m) (forall g (m :: * -> *) a. RandT g m a -> StateT g m a
unRandT forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> RandT g m a
f)
liftListen :: (Monad m) => Listen w m (a, g) -> Listen w (RandT g m) a
liftListen :: forall (m :: * -> *) w a g.
Monad m =>
Listen w m (a, g) -> Listen w (RandT g m) a
liftListen Listen w m (a, g)
listen_ RandT g m a
m = forall g (m :: * -> *) a. StateT g m a -> RandT g m a
RandT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) w a s.
Monad m =>
Listen w m (a, s) -> Listen w (StateT s m) a
LazyState.liftListen Listen w m (a, g)
listen_ (forall g (m :: * -> *) a. RandT g m a -> StateT g m a
unRandT RandT g m a
m)
liftPass :: (Monad m) => Pass w m (a, g) -> Pass w (RandT g m) a
liftPass :: forall (m :: * -> *) w a g.
Monad m =>
Pass w m (a, g) -> Pass w (RandT g m) a
liftPass Pass w m (a, g)
pass_ RandT g m (a, w -> w)
m = forall g (m :: * -> *) a. StateT g m a -> RandT g m a
RandT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) w a s.
Monad m =>
Pass w m (a, s) -> Pass w (StateT s m) a
LazyState.liftPass Pass w m (a, g)
pass_ (forall g (m :: * -> *) a. RandT g m a -> StateT g m a
unRandT RandT g m (a, w -> w)
m)
evalRandIO :: Rand StdGen a -> IO a
evalRandIO :: forall a. Rand StdGen a -> IO a
evalRandIO Rand StdGen a
t = forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (forall g a. Rand g a -> g -> a
evalRand Rand StdGen a
t) forall (m :: * -> *). MonadIO m => m StdGen
newStdGen
evalRandTIO :: (MonadIO m) => RandT StdGen m a -> m a
evalRandTIO :: forall (m :: * -> *) a. MonadIO m => RandT StdGen m a -> m a
evalRandTIO RandT StdGen m a
t = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall (m :: * -> *). MonadIO m => m StdGen
newStdGen forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) g a. Monad m => RandT g m a -> g -> m a
evalRandT RandT StdGen m a
t
#if MIN_VERSION_random(1,2,0)
instance (Monad m, RandomGen g) => StatefulGen (RandGen g) (RandT g m) where
uniformWord32R :: Word32 -> RandGen g -> RandT g m Word32
uniformWord32R Word32
r = forall (m :: * -> *) g a.
Applicative m =>
(g -> (a, g)) -> RandGen g -> RandT g m a
applyRandT (forall g. RandomGen g => Word32 -> g -> (Word32, g)
genWord32R Word32
r)
uniformWord64R :: Word64 -> RandGen g -> RandT g m Word64
uniformWord64R Word64
r = forall (m :: * -> *) g a.
Applicative m =>
(g -> (a, g)) -> RandGen g -> RandT g m a
applyRandT (forall g. RandomGen g => Word64 -> g -> (Word64, g)
genWord64R Word64
r)
uniformWord8 :: RandGen g -> RandT g m Word8
uniformWord8 = forall (m :: * -> *) g a.
Applicative m =>
(g -> (a, g)) -> RandGen g -> RandT g m a
applyRandT forall g. RandomGen g => g -> (Word8, g)
genWord8
uniformWord16 :: RandGen g -> RandT g m Word16
uniformWord16 = forall (m :: * -> *) g a.
Applicative m =>
(g -> (a, g)) -> RandGen g -> RandT g m a
applyRandT forall g. RandomGen g => g -> (Word16, g)
genWord16
uniformWord32 :: RandGen g -> RandT g m Word32
uniformWord32 = forall (m :: * -> *) g a.
Applicative m =>
(g -> (a, g)) -> RandGen g -> RandT g m a
applyRandT forall g. RandomGen g => g -> (Word32, g)
genWord32
uniformWord64 :: RandGen g -> RandT g m Word64
uniformWord64 = forall (m :: * -> *) g a.
Applicative m =>
(g -> (a, g)) -> RandGen g -> RandT g m a
applyRandT forall g. RandomGen g => g -> (Word64, g)
genWord64
uniformShortByteString :: Int -> RandGen g -> RandT g m ShortByteString
uniformShortByteString Int
n = forall (m :: * -> *) g a.
Applicative m =>
(g -> (a, g)) -> RandGen g -> RandT g m a
applyRandT (forall g. RandomGen g => Int -> g -> (ShortByteString, g)
genShortByteString Int
n)
instance (Monad m, RandomGen g) => RandomGenM (RandGen g) g (RandT g m) where
applyRandomGenM :: forall a. (g -> (a, g)) -> RandGen g -> RandT g m a
applyRandomGenM = forall (m :: * -> *) g a.
Applicative m =>
(g -> (a, g)) -> RandGen g -> RandT g m a
applyRandT
applyRandT :: Applicative m => (g -> (a, g)) -> RandGen g -> RandT g m a
applyRandT :: forall (m :: * -> *) g a.
Applicative m =>
(g -> (a, g)) -> RandGen g -> RandT g m a
applyRandT g -> (a, g)
f RandGen g
_ = forall g (m :: * -> *) a. (g -> m (a, g)) -> RandT g m a
liftRandT (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. g -> (a, g)
f)
#endif
withRandGen ::
g
-> (RandGen g -> RandT g m a)
-> m (a, g)
withRandGen :: forall g (m :: * -> *) a.
g -> (RandGen g -> RandT g m a) -> m (a, g)
withRandGen g
g RandGen g -> RandT g m a
action = forall g (m :: * -> *) a. RandT g m a -> g -> m (a, g)
runRandT (RandGen g -> RandT g m a
action forall g. RandGen g
RandGen) g
g
withRandGen_ ::
Monad m
=> g
-> (RandGen g -> RandT g m a)
-> m a
withRandGen_ :: forall (m :: * -> *) g a.
Monad m =>
g -> (RandGen g -> RandT g m a) -> m a
withRandGen_ g
g RandGen g -> RandT g m a
action = forall (m :: * -> *) g a. Monad m => RandT g m a -> g -> m a
evalRandT (RandGen g -> RandT g m a
action forall g. RandGen g
RandGen) g
g