CIS194/Lecture 03/LogAnalysis/LogAnalysis.hs

29 lines
611 B
Haskell
Raw Normal View History

2016-10-17 15:01:20 +00:00
module LogAnalysis where
import Text.Read ( readMaybe )
data MessageType = Info
| Warning
| Error Int
deriving (Show, Eq)
type Timestamp = Int
data LogMessage = LogMessage MessageType Timestamp String
deriving (Show, Eq)
data MaybeLogMessage = ValidLM LogMessage
| InvalidLM String
deriving (Show, Eq)
data MaybeInt = ValidInt Int
| InvalidInt
deriving (Show, Eq)
readInt :: String -> MaybeInt
readInt s
| Just i <- readMaybe s = ValidInt i
| otherwise = InvalidInt
-- parseMessage :: String -> MaybeLogMessage