haskell-wasm-repl/app/Main.hs

23 lines
671 B
Haskell
Raw Normal View History

2024-10-10 19:12:48 +05:30
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"