-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from thalerjonathan/develop
Contributing 'occasionally' and MonadRandom stuff to Dunai & BearRiver. Refs #40 .
- Loading branch information
Showing
5 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{-# LANGUAGE Arrows #-} | ||
module Control.Monad.Trans.MSF.Random | ||
( | ||
runRandS | ||
, evalRandS | ||
|
||
, getRandomS | ||
, getRandomsS | ||
, getRandomRS | ||
, getRandomRS_ | ||
, getRandomsRS | ||
, getRandomsRS_ | ||
) where | ||
|
||
-- External | ||
import Control.Monad.Random | ||
|
||
-- Internal | ||
import Data.MonadicStreamFunction | ||
|
||
-- | Updates the generator every step | ||
runRandS :: (RandomGen g, Monad m) | ||
=> MSF (RandT g m) a b | ||
-> g | ||
-> MSF m a (g, b) | ||
runRandS msf g = MSF $ \a -> do | ||
((b, msf'), g') <- runRandT (unMSF msf a) g | ||
return ((g', b), runRandS msf' g') | ||
|
||
-- | Updates the generator every step but discharges the generator | ||
evalRandS :: (RandomGen g, Monad m) => MSF (RandT g m) a b -> g -> MSF m a b | ||
evalRandS msf g = runRandS msf g >>> arr snd | ||
|
||
getRandomS :: (MonadRandom m, Random b) => MSF m a b | ||
getRandomS = arrM_ getRandom | ||
|
||
getRandomsS :: (MonadRandom m, Random b) => MSF m a [b] | ||
getRandomsS = arrM_ getRandoms | ||
|
||
getRandomRS :: (MonadRandom m, Random b) => (b, b) -> MSF m a b | ||
getRandomRS range = arrM_ $ getRandomR range | ||
|
||
getRandomRS_ :: (MonadRandom m, Random b) => MSF m (b, b) b | ||
getRandomRS_ = arrM getRandomR | ||
|
||
getRandomsRS :: (MonadRandom m, Random b) => (b, b) -> MSF m a [b] | ||
getRandomsRS range = arrM_ $ getRandomRs range | ||
|
||
getRandomsRS_ :: (MonadRandom m, Random b) => MSF m (b, b) [b] | ||
getRandomsRS_ = arrM getRandomRs |