rand* why not of type State g a

the rand* function are examples for a typical state usage, arent' they? Is there any reasoon why they are not defined RandomGen g => State g a rather than RandomGen g => (a,a) -> g -> (a,g) ? Marc

On Sun, 13 Aug 2006, Marc Weber wrote:
the rand* function are examples for a typical state usage, arent' they? Is there any reasoon why they are not defined RandomGen g => State g a rather than RandomGen g => (a,a) -> g -> (a,g) ?
It's probably because Control.Monad.State belongs to the MTL which is outside Prelude. Nonetheless I find it also more convenient to use the State monad for random number generators: http://darcs.haskell.org/htam/src/Stochastic.hs http://www.haskell.org/pipermail/haskell-cafe/2005-May/009775.html

Henning Thielemann writes:
On Sun, 13 Aug 2006, Marc Weber wrote:
the rand* function are examples for a typical state usage, arent'
they?
Is there any reasoon why they are not defined RandomGen g => State g a rather than RandomGen g => (a,a) -> g -> (a,g) ?
It's probably because Control.Monad.State belongs to the MTL which is outside Prelude.
On the other hand, if you are using MTL, you'd probably want a more
general signature, like:
(RandomGen g, MonadState g m) => m a
--
David Menendez

On Sun, Aug 20, 2006 at 12:32:05AM +0200, Henning Thielemann wrote:
On Sun, 13 Aug 2006, Marc Weber wrote:
the rand* function are examples for a typical state usage, arent' they? Is there any reasoon why they are not defined RandomGen g => State g a rather than RandomGen g => (a,a) -> g -> (a,g) ?
It's probably because Control.Monad.State belongs to the MTL which is outside Prelude. Nonetheless I find it also more convenient to use the State monad for random number generators: http://darcs.haskell.org/htam/src/Stochastic.hs http://www.haskell.org/pipermail/haskell-cafe/2005-May/009775.html
Exactly, and thanks to the right order of parameters and the result pair, you can easily use random* functions in a State monad: do x <- State random y <- State (randomR (0, 100)) ... Best regards Tomasz
participants (4)
-
David Menendez
-
Henning Thielemann
-
Marc Weber
-
Tomasz Zielonka