Facebook
From Unreliable Human, 10 Years ago, written in Haskell.
This paste is a reply to Untitled from Paltry Coyote - view diff
Embed
Download Paste or View Raw
Hits: 515
  1. thenEitherA :: (Eq q1, Eq q2) => Auto a (Either q1 q2) -> Auto a (Either q1 q2) -> Auto a (Either q1 q2)
  2. thenEitherA (A s1 ini1 ac1 t1) (A s2 ini2 ac2 t2) = (A st init acc tr) where
  3.         st = s1 ++ s2
  4.         init =  if any ac1 ini1 then
  5.                                 ini1 ++ ini2
  6.                         else
  7.                                 ini1
  8.         acc s = ac2 s
  9.         tr s w =        let l1 = t1 s w
  10.                                         in      if (not (l1 == [])) then
  11.                                                         if any ac1 l1 then
  12.                                                                 (l1 ++ ini2)
  13.                                                         else
  14.                                                                 l1
  15.                                                 else
  16.                                                         if (not (t2 s w == [])) then
  17.                                                                 (t2 s w)
  18.                                                         else
  19.                                                                 []
  20.                                        
  21. thenaA :: (Eq q1, Eq q2) => Auto a q1 -> Auto a q2 -> Auto a (Either q1 q2)
  22. thenaA (A s1 ini1 ac1 t1) (A s2 ini2 ac2 t2) = thenEitherA (leftA (A s1 ini1 ac1 t1)) (rightA (A s2 ini2 ac2 t2))