Hi,
I need some random numbers. The documentation identifies StdGen, but I can't
figure out how to invoke it. The documentation is great
in every way, except an actual example that I can essentially cut and paste.
Thanks
___
Haskell mailing list
I need some random numbers.
in the IO Monad, hiding the use of a generator
do x - randomRIO (0, 1 :: Double) ; print x
you can also make the state explicit:
do g0 - getStdGen ; let { ( x, g1 ) = randomR ( 0, 1::Double) g0 } ;
print x
a RandomGen is actually the state object for the
module Dice where
import System.Random
import System.IO.Unsafe (unsafePerformIO,unsafeInterleaveIO)
import Data.List (unfoldr)
dice4,dice6,dice8,dice10,dice12,dice20,dice666 :: [Int]
dice4 = randomRs (1,4) (read foo::StdGen)
dice6 = randomRs (1,6) (mkStdGen 5)
dice8 = randomRs (1,8)
import System.IO.Unsafe (unsafePerformIO,unsafeInterleaveIO)
Whoa! I'd be very cautious recommending these for newbies ...
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell
that is exact the way, how i had learned about the state monads like IO and
Maybe.
that was even before i understood the [] monad, folding and using Random; i
don't remember when that was... ghc-5.xx age.
in my opinion, unsafePerformIO is a good learning tool, as soon as you use it
tricky to
Hi Benny,
instance (Float a) = Num (Poly a) where
x + y = addPoly x y
I got the Cannot use type synonym in instance head error message when I
was trying to
compile the above code. Can you tell me why and how to solve it?
Unfortunately, you can not instantiate a class
Please keep this on the list, so everyone can benefit.
Benny [EMAIL PROTECTED] wrote:
Hello Jon
Thanks for the help. But it still didn't work after I changed the
codes from:
type Poly = [Float]
addPoly::Poly-Poly-Poly
addPoly x y = zipWith (+) x y
instance (Float a) = Num (Poly a)
type Poly = [Float]
addPoly::Poly-Poly-PolyaddPoly x y = zipWith (+) x y
instance (Float a) = Num (Poly a)
where
x + y= addPoly x y
I got the "Cannot use type synonym in instance head" error message when I
was trying to compile the above code. Can you tell me why and how to solve
it?
type Poly = [Float]
addPoly::Poly-Poly-PolyaddPoly x y =
zipWith (+) x y
instance (Float a) = Num (Poly a)
where
(+) = addPoly
I got the error message "Cannot use type synonym
in instance head" when I was trying to compile the codes above. Can anyone tell
me why and how to solve it?
At 2002-04-13 21:22, Benny wrote:
type Poly = [Float]
addPoly::Poly-Poly-Poly
addPoly x y = zipWith (+) x y
instance (Float a) = Num (Poly a) where
(+) = addPoly
I got the error message Cannot use type synonym in instance head when I
was trying to compile the codes above. Can
10 matches
Mail list logo