module LoopCompF(loopCompF,loopCompSP,loopThroughBothF,loopThroughBothSP) where
import Fudget        
import CompFfun(prepostMapHigh)
import CompF(compF)
import CompSP(compSP,prepostMapSP)
import Loop(loopLeftSP)
import Loops(loopLeftF)

-- loopComp = symmetric version of loopThroughRight

loopCompF :: F (Either (Either r2l inl) (Either l2r inr))
               (Either (Either l2r outl) (Either r2l outr)) ->
	     F (Either inl inr) (Either outl outr)
loopCompF :: F (Either (Either r2l inl) (Either l2r inr))
  (Either (Either l2r outl) (Either r2l outr))
-> F (Either inl inr) (Either outl outr)
loopCompF = F (Either (Either l2r r2l) (Either inl inr))
  (Either (Either l2r r2l) (Either outl outr))
-> F (Either inl inr) (Either outl outr)
forall a b c. F (Either a b) (Either a c) -> F b c
loopLeftF (F (Either (Either l2r r2l) (Either inl inr))
   (Either (Either l2r r2l) (Either outl outr))
 -> F (Either inl inr) (Either outl outr))
-> (F (Either (Either r2l inl) (Either l2r inr))
      (Either (Either l2r outl) (Either r2l outr))
    -> F (Either (Either l2r r2l) (Either inl inr))
         (Either (Either l2r r2l) (Either outl outr)))
-> F (Either (Either r2l inl) (Either l2r inr))
     (Either (Either l2r outl) (Either r2l outr))
-> F (Either inl inr) (Either outl outr)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either (Either l2r r2l) (Either inl inr)
 -> Either (Either r2l inl) (Either l2r inr))
-> (Either (Either l2r outl) (Either r2l outr)
    -> Either (Either l2r r2l) (Either outl outr))
-> F (Either (Either r2l inl) (Either l2r inr))
     (Either (Either l2r outl) (Either r2l outr))
-> F (Either (Either l2r r2l) (Either inl inr))
     (Either (Either l2r r2l) (Either outl outr))
forall hi b c ho. (hi -> b) -> (c -> ho) -> F b c -> F hi ho
prepostMapHigh Either (Either l2r r2l) (Either inl inr)
-> Either (Either r2l inl) (Either l2r inr)
forall a a b b.
Either (Either a a) (Either b b)
-> Either (Either a b) (Either a b)
pre Either (Either l2r outl) (Either r2l outr)
-> Either (Either l2r r2l) (Either outl outr)
forall a a b b.
Either (Either a a) (Either b b)
-> Either (Either a b) (Either a b)
post

loopThroughBothF :: F (Either r2l inl) (Either l2r outl)
-> F (Either l2r inr) (Either r2l outr)
-> F (Either inl inr) (Either outl outr)
loopThroughBothF F (Either r2l inl) (Either l2r outl)
fud1 F (Either l2r inr) (Either r2l outr)
fud2 = F (Either (Either r2l inl) (Either l2r inr))
  (Either (Either l2r outl) (Either r2l outr))
-> F (Either inl inr) (Either outl outr)
forall r2l inl l2r inr outl outr.
F (Either (Either r2l inl) (Either l2r inr))
  (Either (Either l2r outl) (Either r2l outr))
-> F (Either inl inr) (Either outl outr)
loopCompF (F (Either r2l inl) (Either l2r outl)
fud1 F (Either r2l inl) (Either l2r outl)
-> F (Either l2r inr) (Either r2l outr)
-> F (Either (Either r2l inl) (Either l2r inr))
     (Either (Either l2r outl) (Either r2l outr))
forall a b c d. F a b -> F c d -> F (Either a c) (Either b d)
`compF` F (Either l2r inr) (Either r2l outr)
fud2)
loopThroughBothSP :: SP (Either a b) (Either a a)
-> SP (Either a b) (Either a b) -> SP (Either b b) (Either a b)
loopThroughBothSP SP (Either a b) (Either a a)
sp1 SP (Either a b) (Either a b)
sp2 = SP
  (Either (Either a b) (Either a b))
  (Either (Either a a) (Either a b))
-> SP (Either b b) (Either a b)
forall a b a b a b.
SP
  (Either (Either a b) (Either a b))
  (Either (Either a a) (Either a b))
-> SP (Either b b) (Either a b)
loopCompSP (SP (Either a b) (Either a a)
sp1 SP (Either a b) (Either a a)
-> SP (Either a b) (Either a b)
-> SP
     (Either (Either a b) (Either a b))
     (Either (Either a a) (Either a b))
forall a1 a2 a3 b.
SP a1 a2 -> SP a3 b -> SP (Either a1 a3) (Either a2 b)
`compSP` SP (Either a b) (Either a b)
sp2)

loopCompSP :: SP
  (Either (Either a b) (Either a b))
  (Either (Either a a) (Either a b))
-> SP (Either b b) (Either a b)
loopCompSP = SP
  (Either (Either a a) (Either b b))
  (Either (Either a a) (Either a b))
-> SP (Either b b) (Either a b)
forall a1 a2 b. SP (Either a1 a2) (Either a1 b) -> SP a2 b
loopLeftSP (SP
   (Either (Either a a) (Either b b))
   (Either (Either a a) (Either a b))
 -> SP (Either b b) (Either a b))
-> (SP
      (Either (Either a b) (Either a b))
      (Either (Either a a) (Either a b))
    -> SP
         (Either (Either a a) (Either b b))
         (Either (Either a a) (Either a b)))
-> SP
     (Either (Either a b) (Either a b))
     (Either (Either a a) (Either a b))
-> SP (Either b b) (Either a b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either (Either a a) (Either b b)
 -> Either (Either a b) (Either a b))
-> (Either (Either a a) (Either a b)
    -> Either (Either a a) (Either a b))
-> SP
     (Either (Either a b) (Either a b))
     (Either (Either a a) (Either a b))
-> SP
     (Either (Either a a) (Either b b))
     (Either (Either a a) (Either a b))
forall t1 a t2 b. (t1 -> a) -> (t2 -> b) -> SP a t2 -> SP t1 b
prepostMapSP Either (Either a a) (Either b b)
-> Either (Either a b) (Either a b)
forall a a b b.
Either (Either a a) (Either b b)
-> Either (Either a b) (Either a b)
pre Either (Either a a) (Either a b)
-> Either (Either a a) (Either a b)
forall a a b b.
Either (Either a a) (Either b b)
-> Either (Either a b) (Either a b)
post

post :: Either (Either a a) (Either b b)
-> Either (Either a b) (Either a b)
post (Left  (Left  a
x)) = Either a b -> Either (Either a b) (Either a b)
forall a b. a -> Either a b
Left (a -> Either a b
forall a b. a -> Either a b
Left a
x)
post (Left  (Right a
x)) = Either a b -> Either (Either a b) (Either a b)
forall a b. b -> Either a b
Right (a -> Either a b
forall a b. a -> Either a b
Left a
x)
post (Right (Left b
x)) = Either a b -> Either (Either a b) (Either a b)
forall a b. a -> Either a b
Left (b -> Either a b
forall a b. b -> Either a b
Right b
x)
post (Right (Right b
x)) = Either a b -> Either (Either a b) (Either a b)
forall a b. b -> Either a b
Right (b -> Either a b
forall a b. b -> Either a b
Right b
x)
-- post = either (either (Left.Left) (Right.Left))  (either (Left.Right) (Right.Right))

pre :: Either (Either a a) (Either b b)
-> Either (Either a b) (Either a b)
pre (Right (Left b
x)) = Either a b -> Either (Either a b) (Either a b)
forall a b. a -> Either a b
Left (b -> Either a b
forall a b. b -> Either a b
Right b
x)
pre (Right (Right b
x)) = Either a b -> Either (Either a b) (Either a b)
forall a b. b -> Either a b
Right (b -> Either a b
forall a b. b -> Either a b
Right b
x)
pre (Left (Left a
x)) = Either a b -> Either (Either a b) (Either a b)
forall a b. b -> Either a b
Right (a -> Either a b
forall a b. a -> Either a b
Left a
x)
pre (Left (Right a
x)) = Either a b -> Either (Either a b) (Either a b)
forall a b. a -> Either a b
Left (a -> Either a b
forall a b. a -> Either a b
Left a
x)