In particular, is my untilEOF idiomatically ok? Is there a better way to accomplish this? Also, while talking about untilEOF, it is slightly annoying that hIsEOF returns IO Bool and that functions like 'not' only want Bool. Sure makes the logic tests feel like more work than they should be.
cat.hs: module Main where
import IO import System(getArgs)
untilEOF :: Handle -> (Handle -> IO ()) -> IO ()
untilEOF hdl f = do eof <- hIsEOF hdl
if eof then return ()
else do f hdl
untilEOF hdl fcat :: Handle -> IO ()
cat hdl = do line <- hGetLine hdl
putStrLn linecatFile :: FilePath -> IO ()
catFile path = do hdl <- openFile path ReadMode
untilEOF hdl catmain :: IO ()
main = do args <- getArgs
if (length args) > 0 then mapM_ catFile args
else untilEOF stdin cat
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe
