Skip to content

Instantly share code, notes, and snippets.

@BlakeWilliams
Created August 17, 2014 18:37
Show Gist options
  • Select an option

  • Save BlakeWilliams/1d0a2545c24b4a9d2802 to your computer and use it in GitHub Desktop.

Select an option

Save BlakeWilliams/1d0a2545c24b4a9d2802 to your computer and use it in GitHub Desktop.
import System.Random
guessNumber :: Int -> IO ()
guessNumber answer = do
guess <- getLine
if read guess == answer
then putStrLn "You Win!"
else guessWrong answer (read guess)
guessWrong :: Int -> Int -> IO ()
guessWrong answer guess = do
if guess < answer
then do
putStrLn "Too low!"
else do
putStrLn "Too high!"
guessNumber answer
randomInt :: IO Int
randomInt = getStdRandom $ randomR (1, 1000)
main = do
putStrLn "I picked a number between 1 and 1000, try and guess it!"
number <- randomInt
guessNumber number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment