module Main where import System.Environment (getArgs) import Char (isSpace) cnt :: Int-> Int-> Int-> Bool-> String-> (Int, Int, Int) cnt l w c _ [] = (l, w, c) cnt l w c blank (x:xs) | isSpace x && not blank = cnt l' (w+1) (c+1) True xs | isSpace x && blank = cnt l' w (c+1) True xs | otherwise = cnt l w (c+1) False xs where l' = if x == '\n' then l+1 else l wc2 :: String-> IO () wc2 file = catch (do c <- readFile file putStrLn (file ++ ": "++ show (cnt 0 0 0 False c) ++ " lines, words, characters.")) (\e-> putStrLn ("Fehler beim Lesen: "++ show e)) main = do args <- getArgs mapM_ wc2 args