Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

guess.hs

Name: Anonymous 2012-09-28 22:32

import System.Random

main =  randomRIO (1,100) >>= guess 1
    where
    guess n x = putStrLn "Guess: " >> getLine >>= correct n x
    correct n x y
        | x == (read y :: Int) = putStrLn ("Correct!\n" ++ show n ++ " Guesses.")  >> getLine >> return ()
        | x >  (read y :: Int) = putStrLn "Higher!\n" >> guess (n + 1) x
        | x <  (read y :: Int) = putStrLn "Lower!\n"  >> guess (n + 1) x\n" ++ show n ++ " Guesses.")  >> getLine >> return ()
        | x >  (read y :: Int) = putStrLn "Higher!\n" >> guess (n + 1) x
        | x <  (read y :: Int) = putStrLn "Lower!\n"  >> guess (n + 1) x

Name: Anonymous 2012-09-28 22:33

rm the last twohous

Name: Anonymous 2012-09-29 0:57

Why bother with haskell if you're basically writing imperative code in the IO monad? sage

Don't change these.
Name: Email:
Entire Thread Thread List