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

Dan Stromberg strombrg at gmail.com
Tue Oct 20 15:58:46 UTC 2015


Here's a small program that replicates the compilation issue I'm seeing:

import qualified System.Posix.Files

get_size :: String -> IO Integer
get_size filename = do
    file_status <- System.Posix.Files.getFileStatus filename
    let file_size = System.Posix.Files.fileSize file_status
    let integer_file_size = fromIntegral file_size
    return integer_file_size

main :: IO ()
main = do
    let filenames = ["/etc/services"]
    let sizes = map get_size filenames
    mapM_ print sizes

The compilation error I get is:

ghc -Wall --make -o stat2 stat2.hs
[1 of 1] Compiling Main             ( stat2.hs, stat2.o )

stat2.hs:15:11:
    No instance for (Show (IO Integer)) arising from a use of `print'
    Possible fix: add an instance declaration for (Show (IO Integer))
    In the first argument of `mapM_', namely `print'
    In a stmt of a 'do' block: mapM_ print sizes
    In the expression:
      do { let filenames = ...;
           let sizes = map get_size filenames;
           mapM_ print sizes }
make: *** [stat2] Error 1

I've googled quite a bit, and guessed quite a bit, and added type
declarations some, but I'm still not converging on a solution.

Why can't I print an IO Integer?

Thanks!

-- 
Dan Stromberg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151020/f1cdc810/attachment.html>


More information about the Beginners mailing list