Haskell/Understanding monads/Solutions/IO

Print a list of arbitrary valuesEdit

The function map would print out every value from the list, but would produce [IO ()]. We'd thus need to chain sequence $ map, which is exactly how the function mapM is defined. Because we are not collecting the results of print but focus only on its actions, we can discard them with mapM_.

printList :: Show a => [a] -> IO ()
printList = mapM_ print