MonadRandom or Control.Monad.Random

Where can I find MonadRandom or Control.Monad.Random to install? It doesn't seem to be a system library, I can't find it with cabal or Hoogle. Thanks, Mike

On Jul 30, 2009, at 20:04 , Michael P Mossey wrote:
Where can I find MonadRandom or Control.Monad.Random to install? It doesn't seem to be a system library, I can't find it with cabal or Hoogle.
Cabal should have found http://hackage.haskell.org/package/MonadRandom -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

On Thu, Jul 30, 2009 at 05:04:54PM -0700, Michael P Mossey wrote:
Where can I find MonadRandom or Control.Monad.Random to install? It doesn't seem to be a system library, I can't find it with cabal or Hoogle.
'cabal install MonadRandom' ought to work. Note that you may have to 'cabal update' first to make sure cabal has the most up-to-date package list. You can also always look at the complete list of packages on Hackage by going to hackage.haskell.org. -Brent

Brent Yorgey wrote:
On Thu, Jul 30, 2009 at 05:04:54PM -0700, Michael P Mossey wrote:
Where can I find MonadRandom or Control.Monad.Random to install? It doesn't seem to be a system library, I can't find it with cabal or Hoogle.
'cabal install MonadRandom' ought to work. Note that you may have to 'cabal update' first to make sure cabal has the most up-to-date package list. You can also always look at the complete list of packages on Hackage by going to hackage.haskell.org.
-Brent _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
That worked. I'm looking at this example from the docs. I understand most of this but I can't find a definition of getRandomR. See die has type (Rand g Int) I'm assuming getRandomR is a function that has that type, but I can't find its definition. import Control.Monad.Random die :: (RandomGen g) => Rand g Int die = getRandomR (1,6) dice :: (RandomGen g) => Int -> Rand g [Int] dice n = sequence (replicate n die) main = do values <- evalRandIO (dice 2) putStrLn (show values)

On Fri, Jul 31, 2009 at 05:55:43PM -0700, Michael P Mossey wrote:
Brent Yorgey wrote:
On Thu, Jul 30, 2009 at 05:04:54PM -0700, Michael P Mossey wrote:
Where can I find MonadRandom or Control.Monad.Random to install? It doesn't seem to be a system library, I can't find it with cabal or Hoogle.
'cabal install MonadRandom' ought to work. Note that you may have to 'cabal update' first to make sure cabal has the most up-to-date package list. You can also always look at the complete list of packages on Hackage by going to hackage.haskell.org.
-Brent _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
That worked.
I'm looking at this example from the docs. I understand most of this but I can't find a definition of getRandomR. See die has type (Rand g Int) I'm assuming getRandomR is a function that has that type, but I can't find its definition.
getRandomR has type (MonadRandom m, Random a) => (a, a) -> m a which in particular can be specialized to (RandomGen g) => (Int,Int) -> Rand g Int . The documentation for getRandomR, and the other methods of the MonadRandom class, can be found here: http://hackage.haskell.org/packages/archive/MonadRandom/0.1.3/doc/html/Contr... -Brent

Brent Yorgey wrote:
On Fri, Jul 31, 2009 at 05:55:43PM -0700, Michael P Mossey wrote:
I'm looking at this example from the docs. I understand most of this but I can't find a definition of getRandomR. See die has type (Rand g Int) I'm assuming getRandomR is a function that has that type, but I can't find its definition.
getRandomR has type
(MonadRandom m, Random a) => (a, a) -> m a
which in particular can be specialized to
(RandomGen g) => (Int,Int) -> Rand g Int .
The documentation for getRandomR, and the other methods of the MonadRandom class, can be found here:
http://hackage.haskell.org/packages/archive/MonadRandom/0.1.3/doc/html/Contr...
Thanks. I'm still getting used to Haskell documentation. I was looking in Control.Monad.Random, but I needed to look in Control.Monad.Random.Class. So I would like to know how to do something which is on the surface imperative-like: toss a die until a 1 comes up, and count the number of tosses. This would involve some kind of looping with an exit condition in an imperative language. Can someone show me how to write that in Haskell? (Actually I want to do a lot more than that, but I just want to start there.) Thanks, Mike

On Sat, Aug 01, 2009 at 10:17:20AM -0700, Michael Mossey wrote:
Brent Yorgey wrote:
On Fri, Jul 31, 2009 at 05:55:43PM -0700, Michael P Mossey wrote:
I'm looking at this example from the docs. I understand most of this but I can't find a definition of getRandomR. See die has type (Rand g Int) I'm assuming getRandomR is a function that has that type, but I can't find its definition.
getRandomR has type (MonadRandom m, Random a) => (a, a) -> m a
which in particular can be specialized to (RandomGen g) => (Int,Int) -> Rand g Int . The documentation for getRandomR, and the other methods of the MonadRandom class, can be found here:
http://hackage.haskell.org/packages/archive/MonadRandom/0.1.3/doc/html/Contr...
Thanks. I'm still getting used to Haskell documentation. I was looking in Control.Monad.Random, but I needed to look in Control.Monad.Random.Class.
So I would like to know how to do something which is on the surface imperative-like: toss a die until a 1 comes up, and count the number of tosses. This would involve some kind of looping with an exit condition in an imperative language. Can someone show me how to write that in Haskell?
(Actually I want to do a lot more than that, but I just want to start there.)
You could do something as simple as this: tossesUntilOne :: (RandomGen g) => Rand g Int tossesUntilOne = do tosses <- getRandomRs (1,6) return $ length (takeWhile (/= 1) tosses) + 1 That is, instead of writing it as a loop with an exit condition, you can just generate an infinite list of tosses, then count the length of the portion before the first 1. -Brent
participants (4)
-
Brandon S. Allbery KF8NH
-
Brent Yorgey
-
Michael Mossey
-
Michael P Mossey