A better way to map a function that requires IO over a list

前端 未结 4 1475
感动是毒
感动是毒 2021-01-20 03:40

So lately I have a list of strings, and need to independently go over each one and perform some IO function.

So basically what I have is this:

4条回答
  •  猫巷女王i
    2021-01-20 04:27

    Your goOverList function can be written mapM_ putStrLn where mapM_ is a function in the standard Prelude.

    You can also simplify your own implementation:

    goOverList :: [String] -> IO ()
    
    goOverList [] = return ()
    
    goOverList (x:xs) = do
        putStrLn x
        goOverList xs
    

提交回复
热议问题