> module Process
> (process)
> where
> data State = O | I
> acc :: Eq a => State -> a -> a -> [a] -> Bool
> acc O c1 c2 l | length l > 0 && head l == c1 = acc I c1 c2 (tail l)
> | length l > 0 && head l /= c1 = acc O c1 c2 (tail l)
> | l == [] = True
> | otherwise = True
> acc I c1 c2 l | length l > 0 && head l == c2 = acc O c1 c2 (tail l)
> | length l > 0 && head l /= c2 = acc I c1 c2 (tail l)
> | l == [] = False
> | otherwise = False
> dec :: Eq a => a -> a -> [a] -> Bool
> dec c1 c2 = acc O c1 c2
> inout :: Eq a => a -> a -> [a] -> [Bool]
> inout c1 c2 l = map (dec c1 c2) [take k l | k <- [1..length l]]
> pairs :: Eq t => t -> t -> [t] -> [(t, Bool)]
> pairs c1 c2 t = zipWith (\ x y -> (x,y)) t (inout c1 c2 t)
> pairstotags :: Eq t => t -> t -> [t] -> [t] -> (t, Bool) -> [t]
> pairstotags c1 c2 p q (a, b) | (a == c1 && b == False) = p
> | (a == c2 && b == True ) = q
> | otherwise = [a]
> process :: Eq t => t -> t -> [t] -> [t] -> [t] -> [t]
> process c1 c2 p q x = concatMap (pairstotags c1 c2 p q) (pairs c1 c2 x)