module ParseLog (parseLog) where import IO import Data.IORef import Hit data Stat = Stat { latest :: CalendarTime, total :: Int } _doParse line stat = let hit = parseHit line in Stat (max (time hit) (latest stat)) (total stat + 1) _parseLine fh state = do { line <- hGetLine fh ; value <- readIORef state ; writeIORef state (_doParse line value) ; } _parseLines fh state = do { end <- hIsEOF fh ; if end then return () else _parseLine fh state >> _parseLines fh state } parseLog fh = do initial <- newIORef (Stat epoch 0) _parseLines fh initial final <- readIORef initial putStrLn $ "fini " ++ (show $ total final) -- putStrLn ("Total: " ++ (show $ total final) ++ " ending at " ++ (show $ latest final))