Writing for both State and StateT
Mark T.B. Carroll
Mark.Carroll@Aetion.com
Tue, 22 Apr 2003 07:48:57 -0400 (EDT)
At the moment I have code like,
next_random_probability :: (RandomGen g, Num a, Random a) => State g a
next_random_probability =
do old_rng <- get
let (random_probability, new_rng) = randomR (0, 1) old_rng
put new_rng
return random_probability
next_random_probabilityT :: (RandomGen g, Num a, Random a, Monad m) => StateT g m a
next_random_probabilityT =
do old_rng <- get
let (random_probability, new_rng) = randomR (0, 1) old_rng
put new_rng
return random_probability
Because these just use get and put which are both from MonadState, is it
possible to write just one next_random_probability with a more general
type signature, maybe mentioning MonadState, or at least two wrappers that
call the same worker function, so that the same code is good for both
State and StateT?
-- Mark