From: Ramakrishnan Muthukrishnan Date: Mon, 15 Dec 2014 16:07:12 +0000 (+0530) Subject: hw #2 solution. WIP X-Git-Url: https://git.rkrishnan.org/%5B/frontends/flags/%22doc.html/$rel_link?a=commitdiff_plain;h=936f769f8b1b3a80de9848081cb56ffc6873ea7e;p=yorgey.git hw #2 solution. WIP --- diff --git a/hw2/LogAnalysis.hs b/hw2/LogAnalysis.hs new file mode 100644 index 0000000..dc393b2 --- /dev/null +++ b/hw2/LogAnalysis.hs @@ -0,0 +1,18 @@ +{-# OPTIONS_GHC -Wall #-} +module LogAnalysis where + +import Log + +parseMessage :: String -> LogMessage +parseMessage s = let ws = words s in + parseMessage' ws + where + parseMessage' ("I":ts:ws') = LogMessage Info (read ts) (unwords ws') + parseMessage' ("W":ts:ws') = LogMessage Warning (read ts) (unwords ws') + parseMessage' ("E":level:ts:ws') = LogMessage (Error (read level)) (read ts) (unwords ws') + parseMessage' x = Unknown (unwords x) + +parse :: String -> [LogMessage] +parse s = map parseMessage (lines s) + +