Created
June 24, 2015 06:45
-
-
Save cj3kim/c0db32ba27face6fe2a7 to your computer and use it in GitHub Desktop.
Log Analysis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module LogAnalysis where | |
import Log | |
parseMessage :: String -> LogMessage | |
parseMessage s = LogMessage messageType timestamp message | |
where wordAry = words s | |
firstChar = wordAry !! 0 | |
secondChar = wordAry !! 1 | |
messageType = case firstChar of | |
"I" -> Info | |
"W" -> Warning | |
"E" -> (Error (read secondChar :: Int)) | |
timestamp = case messageType of | |
(Error n) -> read (wordAry !! 2) :: Int | |
(Info) -> read (wordAry !! 1) :: Int | |
(Warning) -> read (wordAry !! 1) :: Int | |
message = case messageType of | |
(Error n) -> unwords (drop 3 wordAry) | |
(Info) -> unwords (drop 2 wordAry) | |
(Warning) -> unwords (drop 2 wordAry) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
okay, I will look more into pattern matching
husanu has left IRC (Remote host closed the connection)
reindeernix
why shouldn't you use !!?
husanu has joined ([email protected])
joneshf-laptop
partial
obb has left IRC (Remote host closed the connection)
cj3kim
and then come back when I'm done
whiteline
well, it's ugly. also, you're traversing a structure twice.
machine_coder has joined (~[email protected])
joneshf-laptop