Created
August 17, 2014 18:37
-
-
Save BlakeWilliams/1d0a2545c24b4a9d2802 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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