23 lines
671 B
Haskell
23 lines
671 B
Haskell
module Main where
|
|
|
|
import Control.Monad (forever)
|
|
import Data.Char (isSpace)
|
|
import Data.List (dropWhileEnd)
|
|
import System.IO (BufferMode (..), hFlush, hSetBuffering, stdin, stdout)
|
|
import System.IO.Error (catchIOError, isEOFError)
|
|
|
|
main :: IO ()
|
|
main = do
|
|
hSetBuffering stdin LineBuffering
|
|
hSetBuffering stdout LineBuffering
|
|
loop `catchIOError` \e -> if isEOFError e then return () else ioError e
|
|
where
|
|
loop = forever $ do
|
|
putStrLn "Please enter your name: "
|
|
putStr "> "
|
|
hFlush stdout
|
|
name <- dropWhileEnd isSpace . dropWhile isSpace <$> getLine
|
|
if null name
|
|
then loop
|
|
else putStrLn $ "Hello, " <> name <> "!\n"
|