Working on terminal based app that uses a number of putStr
/getLine
's for gathering user input. Would like to use the following function to shorten the tedious putStr
getLine
by feeding it a list of questions and returning the answers in a list (recursively). Although the getLine
s terminate nicely, I cannot avoid the non-exhaustive patterns
on the putStr
side of things.
This is not a duplicate. Multiple getLine
's can be done using replicateM
, but it's the combination of questions/answers I am after.
(***) = hFlush stdout
questionnaire :: [String] -> IO [String]
questionnaire (x:xs) = do
putStr x
(***)
user <- getLine
case user of
"" -> return []
_ -> do
nextUser <- questionnaire xs
return (user : nextUser)