Skip to content

Instantly share code, notes, and snippets.

@mbenke
Created February 11, 2010 20:49
Show Gist options
  • Save mbenke/301938 to your computer and use it in GitHub Desktop.
Save mbenke/301938 to your computer and use it in GitHub Desktop.
Haskell I/O dialog sample
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