thenEitherA :: (Eq q1, Eq q2) => Auto a (Either q1 q2) -> Auto a (Either q1 q2) -> Auto a (Either q1 q2) thenEitherA (A s1 ini1 ac1 t1) (A s2 ini2 ac2 t2) = (A st init acc tr) where st = s1 ++ s2 init = if any ac1 ini1 then ini1 ++ ini2 else ini1 acc s = ac2 s tr s w = let l1 = t1 s w in if (not (l1 == [])) then if any ac1 l1 then (l1 ++ ini2) else l1 else if (not (t2 s w == [])) then (t2 s w) else [] thenaA :: (Eq q1, Eq q2) => Auto a q1 -> Auto a q2 -> Auto a (Either q1 q2) thenaA (A s1 ini1 ac1 t1) (A s2 ini2 ac2 t2) = thenEitherA (leftA (A s1 ini1 ac1 t1)) (rightA (A s2 ini2 ac2 t2))