[Haskell-cafe] Simple program. Simple problem?
michael rice
nowgate at yahoo.com
Sun Oct 11 18:10:12 EDT 2009
What is going wrong here?
Michael
=======
import System.Random
coinToss :: StdGen -> IO ()
coinToss gen = putStrLn "What's your guess, heads or tails ('h' or 't')?"
>> getChar
>>= \c -> let (randInt, _) = randomR(0,1) gen :: (Int, StdGen)
in if c == ((!!) "ht" randInt) then putStrLn "You win!" else putStrLn "You lose!"
main = do
gen <- getStdGen
coinToss gen
gen <- newStdGen
main
=======
[michael at localhost ~]$ runhaskell cointoss.hs
What's your guess, heads or tails ('h' or 't')?
h
You win!
What's your guess, heads or tails ('h' or 't')?
You lose!
What's your guess, heads or tails ('h' or 't')?
h
You lose!
What's your guess, heads or tails ('h' or 't')?
You lose!
What's your guess, heads or tails ('h' or 't')?
^Ccointoss.hs: cointoss.hs: interrupted
[michael at localhost ~]$
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091011/2571510d/attachment.html
More information about the Haskell-Cafe
mailing list