]> git.rkrishnan.org Git - yorgey.git/commitdiff
hw #2 solution. WIP
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Mon, 15 Dec 2014 16:07:12 +0000 (21:37 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Mon, 15 Dec 2014 16:07:12 +0000 (21:37 +0530)
hw2/LogAnalysis.hs [new file with mode: 0644]

diff --git a/hw2/LogAnalysis.hs b/hw2/LogAnalysis.hs
new file mode 100644 (file)
index 0000000..dc393b2
--- /dev/null
@@ -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)
+
+