The Haskell way to do IO Loops (without explicit recursion)?
问题 I want to read a list of strings seperated by newlines from STDIN, until a new line is witnessed and I want an action of the type IO [String] . Here is how I would do it with recursion: myReadList :: IO String myReadList = go [] where go :: [String] -> IO [String] go l = do { inp <- getLine; if (inp == "") then return l; else go (inp:l); } However, this method of using go obscures readability and is a pattern so common that one would ideally want to abstract this out. So, this was my attempt: