Created
February 11, 2010 20:49
-
-
Save mbenke/301938 to your computer and use it in GitHub Desktop.
Haskell I/O dialog sample
This file contains 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.IO | |
promptLine :: String -> IO String | |
promptLine prompt = do | |
putStr prompt | |
hFlush stdout | |
getLine | |
doesQuit :: String -> Bool | |
doesQuit "" = True | |
doesQuit "quit" = True | |
doesQuit "koniec" = True | |
doesQuit "exit" = True | |
doesQuit _ = False | |
mainLoop :: IO() | |
mainLoop = do | |
input <- promptLine "> " | |
more <- processInput input | |
if more | |
then mainLoop | |
else return () | |
main = mainLoop | |
processInput :: String -> IO Bool | |
processInput input = if doesQuit input then return False else do | |
putStrLn $ "Powiedziales: " ++ input | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment