You need to display the list, but since these are I / O operations, you also need to execute them (since map will return a list of I / O operations without them, see the following example).
sequence $ map (putStrLn . show) [1,2,3,4]
There is a function that already does this, mapM . Thus, an example can be simplified as:
mapM (putStrLn . show) [1,2,3,4]
Another thing you can do is use mapM_ , which instead uses sequence_ and will ignore the result of the IO action for each of the elements. Therefore, the return type will be IO () instead of IO [()] (previous example).
mapM_ (putStrLn . show) [1,2,3,4]
thoferon
source share