No title

Anonymous Coward 2018-03-03 20:42:52.639843 UTC

1{-# OPTIONS_GHC -Wall #-}
2module LogAnalysis where
3
4import Log
5
6readHead :: [String] -> Int
7readHead = read . head
8
9concatenateTail :: [String] -> String
10concatenateTail = unwords . tail
11
12parseMessage :: String -> LogMessage
13parseMessage [] = Unknown ""
14parseMessage (x:xs)
15 | x == 'E' && (length parts) >= 2 = LogMessage (Error (readHead parts))
16 ((readHead . tail) parts)
17 (unwords (drop 1 parts))
18 | x == 'W' && (length parts) >= 3 = LogMessage Warning (readHead parts) (concatenateTail parts)
19 | x == 'I' && (length parts) >= 2 = LogMessage Info (readHead parts) (concatenateTail parts)
20 | otherwise = Unknown (x:xs)
21 where parts = words xs
22