
Richard A. O'Keefe schreef op 2-3-2015 om 0:59:
On 1/03/2015, at 11:17 pm, Roelof Wobben
wrote: Now I have to find out how I can test if the LogMessage has the text "this is not the right format" in it.
Well, the Haskell libraries include regular expression support. At an elementary level, you can always do
is_prefix_of :: Eq x => [x] -> [x] -> Bool is_prefix_of (x:xs) (y:ys) = x == y && is_prefix_of xs ys is_prefix_of (x:xs) [] = False is_prefix_of [] _ = True
is_infix_of :: Eq x => [x] -> [x] -> Bool
is_infix_of xs ys = xs `is_prefix_of` ys || (not (null ys) && xs `is_infix_of` tail ys)
"this is not the right format" `is_infix_of` aLogMessage
But it would be better if your LogMessage were not a string but something structured where you did not have to go looking for that text because you KNEW where to look for it.
I know where to look. A LogMessage looks like this : data LogMessage = LogMessage MessageType TimeStamp String | Unknown String deriving (Show, Eq) So if it's Unknown with a string then it will not be inserted into the MessageTree The only thing I have to find out if LogMessage contains this. Roelof