matchesPattern1 s = mp s (0, 0, 0)
where
mp [] (a, b, c) = a + b == c
mp (x:xs) (a, b, c) | x == 'a' = mp xs ((a + 1), b, c)
| x == 'b' = mp xs (a, (b + 1), c)
| x == 'c' = mp xs (a, b, (c + 1))
matchesPattern2 s = mp s (0, 0, 0) (False, False, False)
where
mp [] (a, b, c) _ = a + b == c
mp (x:xs) (a, b, c) (sa, sb, sc) | x == 'a' =
if sb || sc
then False
else mp xs ((a + 1), b, c) (True, sb, sc)
| x == 'b' =
if sc
then False
else mp xs (a, (b + 1), c) (sa, True, sc)
| x == 'c' =
mp xs (a, b, (c + 1)) (sa, sb, True)
matchesPattern3 s = mp s (0, 0, 0) (False, False, False)
where
mp [] (a, b, c) _ = (a == c) && (a > 0)
mp (x:xs) (a, b, c) (sa, sb, sc) | x == 'a' =
if sb || sc
then False
else mp xs ((a + 1), b, c) (True, sb, sc)
| x == 'b' =
if sc
then False
else mp xs (a, (b + 1), c) (sa, True, sc)
| x == 'c' =
mp xs (a, b, (c + 1)) (sa, sb, True)