This is an example from Learn You a Haskell:
main = do
putStrLn "hello, what's your name?"
name <- getLine
putStrLn ("Hey, " ++ name ++ ", you rock!")
The same redone without do for clarity:
main =
putStrLn "hello, what's your name?" >>
getLine >>= \name ->
putStrLn $ "Hey, " ++ name ++ ", you rock!"
How am I supposed to loop it cleanly (until "q"), the Haskell way (use of do discouraged)?
I borrowed this from Haskell - loop over user input
main = mapM_ process . takeWhile (/= "q") . lines =<< getLine
where process line = do
putStrLn line
for starters, but it won't loop.
doisn't discouraged. There's some discussion about whether or not to usedonotation when introducing monads to beginners because it might give them even crazier ideas about what monads are, but in normal haskell use of do is fine. Also, if you know how to do it withdo, you know how to do it without. Your problem here has nothing to do withdonotation.getLineinstead ofgetContentsgetContentshelps. Unfortunately, I'm still at a loss about how to insert prompt/response into the picture.