[Haskell-beginners] Why can't I print an IO Integer?

Marcin Mrotek marcin.jan.mrotek at gmail.com
Tue Oct 20 16:17:14 UTC 2015


Hello,

Function "print" has type "Show a => a -> IO ()". To use it with a value of
type "IO Int", you need to use (>>=), which, specialized to IO, has type
"IO a -> (a -> IO b) -> IO b". "print =<< foo", if foo :: IO Int, will have
type IO () and is going to print the integer from foo. In your code,
though, you can use mapM instead of map:

    sizes <- mapM get_size filenames
    mapM_ print sizes

Best regards,
Marcin Mrotek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151020/f14ab47f/attachment.html>


More information about the Beginners mailing list