IO library report

Ian Lynagh igloo@earth.li
Wed, 28 Nov 2001 18:31:59 +0000


The report has the following example:

    import IO

    main = do
             hSetBuffering stdout NoBuffering            
             putStr   "Enter an integer: "        
             x1 <- readNum 
             putStr   "Enter another integer: "          
             x2 <- readNum                          
             putStr  ("Their sum is " ++ show (x1+x2) ++ "\n")
           where readNum :: IO Integer
    -- Need a type signature for 
    -- readLn to avoid ambiguity
                 readNum = readLn

However, I believe that due to the monomorphism restriction and type
defaulting the type signature isn't actually required.

The next example:

    import IO
    import System

    main = do 
             [f1,f2] <- getArgs
             h1 <- openFile f1 ReadMode     
             h2 <- openFile f2 WriteMode 
             copyFile h1 h2            
             hClose h1                  
             hClose h2

    copyFile h1 h2 = do
                       eof <- hIsEOF h1
                       if eof then return () else
                          do
                            c <- hGetChar h1
                            hPutChar h2 (toUpper c)   
                            copyFile h1 h2

also requires Char to be imported for toUpper, as does the final example

    import System

    main = do
             [f1,f2] <- getArgs
             s <- readFile f1
             writeFile f2 (map toUpper s)


The section also doesn't follow the convention of the portable part of
the module definition being given at the end of the section.


Thanks
Ian