module FRP.Rhine.ClSF.Random.Util where

-- transformers
import Control.Monad.Trans.Reader

-- MonadRandom
import Control.Monad.Random

-- | Commute one 'ReaderT' layer past a 'RandT' layer.
commuteReaderRand :: ReaderT r (RandT g m) a -> RandT g (ReaderT r m) a
commuteReaderRand :: forall r g (m :: Type -> Type) a.
ReaderT r (RandT g m) a -> RandT g (ReaderT r m) a
commuteReaderRand (ReaderT r -> RandT g m a
f) = (g -> ReaderT r m (a, g)) -> RandT g (ReaderT r m) a
forall g (m :: Type -> Type) a. (g -> m (a, g)) -> RandT g m a
liftRandT ((g -> ReaderT r m (a, g)) -> RandT g (ReaderT r m) a)
-> (g -> ReaderT r m (a, g)) -> RandT g (ReaderT r m) a
forall a b. (a -> b) -> a -> b
$ \g
g -> (r -> m (a, g)) -> ReaderT r m (a, g)
forall r (m :: Type -> Type) a. (r -> m a) -> ReaderT r m a
ReaderT ((r -> m (a, g)) -> ReaderT r m (a, g))
-> (r -> m (a, g)) -> ReaderT r m (a, g)
forall a b. (a -> b) -> a -> b
$ \r
r -> RandT g m a -> g -> m (a, g)
forall g (m :: Type -> Type) a. RandT g m a -> g -> m (a, g)
runRandT (r -> RandT g m a
f r
r) g
g