Skip to content

Instantly share code, notes, and snippets.

@MiyamonY
Created February 27, 2015 12:37
Show Gist options
  • Save MiyamonY/b6860f4f9555484e2286 to your computer and use it in GitHub Desktop.
Save MiyamonY/b6860f4f9555484e2286 to your computer and use it in GitHub Desktop.
import System.Random
import Control.Monad (when)
main :: IO ()
main = do
gen <- getStdGen
askForNumber gen
askForNumber :: StdGen -> IO ()
askForNumber gen = do
let (randomNumber, newGen) = randomR (1, 10) gen :: (Int, StdGen)
putStrLn "Which in the range from 1 to 10 am I thinking of?"
numberString <- getLine
when (not $ null numberString) $ do
let number = read numberString
if randomNumber == number
then putStrLn "You are correct!"
else putStrLn $ "Sorry, it was " ++ show randomNumber
askForNumber newGen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment