{- #!/usr/local/bin/runhugs -} import System cntWords :: FilePath -> IO () cntWords file = do c <- readFile file let s = (length . words) c putStr (file ++ " : " ++ (show s) ++ " words\n") main = do r<- getProgName; a<- getArgs catch (mapM_ cntWords a) (\e-> putStrLn (r++ ": "++ (show e))) -- This version continues with the next file if an error occcurs: -- -- mapM_ (\f-> (catch (cntWords f) -- (\e-> putStrLn (r++ ": "++ (show e))))) a