I have a simple function that uses Control.Monad.Random to create a function that can display a random number.
import Control.Monad.Random import Data.Random unif_bound :: (RandomGen g, Monad m) => Double -> Double -> RandT gm Double unif_bound lb ub = getRandomR (lb,ub)
And I run this to generate random numbers in GHCI like:
> gen <- newStdGen > runRandT (unif_bound 1.0 3.0) gen (1.7569726469904563,1700403094 44073136) > runRandT (unif_bound 3.0, 1.0) gen (1.7569726469904563,1700403094 44073136)
However, I would like to modify this code to check that lb < ub , and wrap it in MaybeT. The idea is to fetch where lb > ub should return Nothing . I understand that this is where monad transformers occur, but I had never used them before and did not know where to start.
For reference, RandT is defined as
Thanks!
source share