module Control.Functor.Zap where
import Control.Comonad.Cofree
import Control.Monad.Either ()
import Control.Monad.Identity
class Zap f g | f -> g, g -> f where
zapWith :: (a -> b -> c) -> f a -> g b -> c
zap :: f (a -> b) -> g a -> b
zap = zapWith id
(>$<) :: Zap f g => f (a -> b) -> g a -> b
(>$<) = zap
instance Zap Identity Identity where
zapWith f (Identity a) (Identity b) = f a b
class BiZap p q | p -> q, q -> p where
bizapWith :: (a -> c -> e) -> (b -> d -> e) -> p a b -> q c d -> e
bizap :: p (a -> c) (b -> c) -> q a b -> c
bizap = bizapWith id id
(>>$<<) :: BiZap p q => p (a -> c) (b -> c) -> q a b -> c
(>>$<<) = bizap
instance BiZap (,) Either where
bizapWith l _ (f,_) (Left a) = l f a
bizapWith _ r (_,g) (Right b) = r g b
instance BiZap Either (,) where
bizapWith l _ (Left f) (a,_) = l f a
bizapWith _ r (Right g) (_,b) = r g b
instance (BiZap p q, Zap f g, Zap i j) => BiZap (BiffB p f i) (BiffB q g j) where
bizapWith l r fs as = bizapWith (zapWith l) (zapWith r) (runBiffB fs) (runBiffB as)