[Haskell-cafe] how to make this work recursive ?

Richard A. O'Keefe ok at cs.otago.ac.nz
Sun Mar 1 23:59:40 UTC 2015


On 1/03/2015, at 11:17 pm, Roelof Wobben <r.wobben at home.nl> 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.




More information about the Haskell-Cafe mailing list