import Data.List (isPrefixOf) import System.Environment (getArgs) import System.IO (hPrint, stderr) main = do args <- getArgs mapM_ identify args identify f = do g <- isInteresting f case g of Right h -> putStrLn (f ++ ": " ++ if h then "interesting" else "boring") Left e -> hPrint stderr e isInteresting f = catch action handler where action = do x <- readFile f return (Right (x `contains` "Haskell")) handler e = return (Left e) [] `contains` _ = False (x:xs) `contains` y = y `isPrefixOf` (x:xs) || xs `contains` y