{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}

-----------------------------------------------------------------------------
-- |
-- Copyright   :  (C) 2008-2016 Edward Kmett
-- License     :  BSD-style (see the file LICENSE)
--
-- Maintainer  :  Edward Kmett <ekmett@gmail.com>
-- Stability   :  provisional
-- Portability :  portable
--
----------------------------------------------------------------------------
module Data.Bifunctor.Biff
  ( Biff(..)
  ) where

import Data.Biapplicative
import Data.Bifoldable
import Data.Bifoldable1 (Bifoldable1(..))
import Data.Bifunctor.Swap (Swap (..))
import Data.Bitraversable
import Data.Foldable1 (Foldable1(..))
import Data.Functor.Classes
import GHC.Generics

-- | Compose two 'Functor's on the inside of a 'Bifunctor'.
newtype Biff p f g a b = Biff { forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
Biff p f g a b -> p (f a) (g b)
runBiff :: p (f a) (g b) }
  deriving (Biff p f g a b -> Biff p f g a b -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Eq (p (f a) (g b)) =>
Biff p f g a b -> Biff p f g a b -> Bool
/= :: Biff p f g a b -> Biff p f g a b -> Bool
$c/= :: forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Eq (p (f a) (g b)) =>
Biff p f g a b -> Biff p f g a b -> Bool
== :: Biff p f g a b -> Biff p f g a b -> Bool
$c== :: forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Eq (p (f a) (g b)) =>
Biff p f g a b -> Biff p f g a b -> Bool
Eq, Biff p f g a b -> Biff p f g a b -> Bool
Biff p f g a b -> Biff p f g a b -> Ordering
Biff p f g a b -> Biff p f g a b -> Biff p f g a b
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {k} {k} {p :: k -> k -> *} {k} {f :: k -> k} {k}
       {g :: k -> k} {a :: k} {b :: k}.
Ord (p (f a) (g b)) =>
Eq (Biff p f g a b)
forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Ord (p (f a) (g b)) =>
Biff p f g a b -> Biff p f g a b -> Bool
forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Ord (p (f a) (g b)) =>
Biff p f g a b -> Biff p f g a b -> Ordering
forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Ord (p (f a) (g b)) =>
Biff p f g a b -> Biff p f g a b -> Biff p f g a b
min :: Biff p f g a b -> Biff p f g a b -> Biff p f g a b
$cmin :: forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Ord (p (f a) (g b)) =>
Biff p f g a b -> Biff p f g a b -> Biff p f g a b
max :: Biff p f g a b -> Biff p f g a b -> Biff p f g a b
$cmax :: forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Ord (p (f a) (g b)) =>
Biff p f g a b -> Biff p f g a b -> Biff p f g a b
>= :: Biff p f g a b -> Biff p f g a b -> Bool
$c>= :: forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Ord (p (f a) (g b)) =>
Biff p f g a b -> Biff p f g a b -> Bool
> :: Biff p f g a b -> Biff p f g a b -> Bool
$c> :: forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Ord (p (f a) (g b)) =>
Biff p f g a b -> Biff p f g a b -> Bool
<= :: Biff p f g a b -> Biff p f g a b -> Bool
$c<= :: forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Ord (p (f a) (g b)) =>
Biff p f g a b -> Biff p f g a b -> Bool
< :: Biff p f g a b -> Biff p f g a b -> Bool
$c< :: forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Ord (p (f a) (g b)) =>
Biff p f g a b -> Biff p f g a b -> Bool
compare :: Biff p f g a b -> Biff p f g a b -> Ordering
$ccompare :: forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Ord (p (f a) (g b)) =>
Biff p f g a b -> Biff p f g a b -> Ordering
Ord, Int -> Biff p f g a b -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Show (p (f a) (g b)) =>
Int -> Biff p f g a b -> ShowS
forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Show (p (f a) (g b)) =>
[Biff p f g a b] -> ShowS
forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Show (p (f a) (g b)) =>
Biff p f g a b -> String
showList :: [Biff p f g a b] -> ShowS
$cshowList :: forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Show (p (f a) (g b)) =>
[Biff p f g a b] -> ShowS
show :: Biff p f g a b -> String
$cshow :: forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Show (p (f a) (g b)) =>
Biff p f g a b -> String
showsPrec :: Int -> Biff p f g a b -> ShowS
$cshowsPrec :: forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Show (p (f a) (g b)) =>
Int -> Biff p f g a b -> ShowS
Show, ReadPrec [Biff p f g a b]
ReadPrec (Biff p f g a b)
ReadS [Biff p f g a b]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Read (p (f a) (g b)) =>
ReadPrec [Biff p f g a b]
forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Read (p (f a) (g b)) =>
ReadPrec (Biff p f g a b)
forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Read (p (f a) (g b)) =>
Int -> ReadS (Biff p f g a b)
forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Read (p (f a) (g b)) =>
ReadS [Biff p f g a b]
readListPrec :: ReadPrec [Biff p f g a b]
$creadListPrec :: forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Read (p (f a) (g b)) =>
ReadPrec [Biff p f g a b]
readPrec :: ReadPrec (Biff p f g a b)
$creadPrec :: forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Read (p (f a) (g b)) =>
ReadPrec (Biff p f g a b)
readList :: ReadS [Biff p f g a b]
$creadList :: forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Read (p (f a) (g b)) =>
ReadS [Biff p f g a b]
readsPrec :: Int -> ReadS (Biff p f g a b)
$creadsPrec :: forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Read (p (f a) (g b)) =>
Int -> ReadS (Biff p f g a b)
Read, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k) x.
Rep (Biff p f g a b) x -> Biff p f g a b
forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k) x.
Biff p f g a b -> Rep (Biff p f g a b) x
$cto :: forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k) x.
Rep (Biff p f g a b) x -> Biff p f g a b
$cfrom :: forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k) x.
Biff p f g a b -> Rep (Biff p f g a b) x
Generic)
deriving instance Functor (p (f a)) => Generic1 (Biff p f g a)

instance (Eq2 p, Eq1 f, Eq1 g, Eq a) => Eq1 (Biff p f g a) where
  liftEq :: forall a b.
(a -> b -> Bool) -> Biff p f g a a -> Biff p f g a b -> Bool
liftEq = forall (f :: * -> * -> *) a b c d.
Eq2 f =>
(a -> b -> Bool) -> (c -> d -> Bool) -> f a c -> f b d -> Bool
liftEq2 forall a. Eq a => a -> a -> Bool
(==)
instance (Eq2 p, Eq1 f, Eq1 g) => Eq2 (Biff p f g) where
  liftEq2 :: forall a b c d.
(a -> b -> Bool)
-> (c -> d -> Bool) -> Biff p f g a c -> Biff p f g b d -> Bool
liftEq2 a -> b -> Bool
f c -> d -> Bool
g (Biff p (f a) (g c)
x) (Biff p (f b) (g d)
y) = forall (f :: * -> * -> *) a b c d.
Eq2 f =>
(a -> b -> Bool) -> (c -> d -> Bool) -> f a c -> f b d -> Bool
liftEq2 (forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
f) (forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq c -> d -> Bool
g) p (f a) (g c)
x p (f b) (g d)
y

instance (Ord2 p, Ord1 f, Ord1 g, Ord a) => Ord1 (Biff p f g a) where
  liftCompare :: forall a b.
(a -> b -> Ordering)
-> Biff p f g a a -> Biff p f g a b -> Ordering
liftCompare = forall (f :: * -> * -> *) a b c d.
Ord2 f =>
(a -> b -> Ordering)
-> (c -> d -> Ordering) -> f a c -> f b d -> Ordering
liftCompare2 forall a. Ord a => a -> a -> Ordering
compare
instance (Ord2 p, Ord1 f, Ord1 g) => Ord2 (Biff p f g) where
  liftCompare2 :: forall a b c d.
(a -> b -> Ordering)
-> (c -> d -> Ordering)
-> Biff p f g a c
-> Biff p f g b d
-> Ordering
liftCompare2 a -> b -> Ordering
f c -> d -> Ordering
g (Biff p (f a) (g c)
x) (Biff p (f b) (g d)
y) = forall (f :: * -> * -> *) a b c d.
Ord2 f =>
(a -> b -> Ordering)
-> (c -> d -> Ordering) -> f a c -> f b d -> Ordering
liftCompare2 (forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare a -> b -> Ordering
f) (forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare c -> d -> Ordering
g) p (f a) (g c)
x p (f b) (g d)
y

instance (Read2 p, Read1 f, Read1 g, Read a) => Read1 (Biff p f g a) where
  liftReadsPrec :: forall a.
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Biff p f g a a)
liftReadsPrec = forall (f :: * -> * -> *) a b.
Read2 f =>
(Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS b)
-> ReadS [b]
-> Int
-> ReadS (f a b)
liftReadsPrec2 forall a. Read a => Int -> ReadS a
readsPrec forall a. Read a => ReadS [a]
readList
instance (Read2 p, Read1 f, Read1 g) => Read2 (Biff p f g) where
  liftReadsPrec2 :: forall a b.
(Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS b)
-> ReadS [b]
-> Int
-> ReadS (Biff p f g a b)
liftReadsPrec2 Int -> ReadS a
rp1 ReadS [a]
rl1 Int -> ReadS b
rp2 ReadS [b]
rl2 Int
p = forall a. Bool -> ReadS a -> ReadS a
readParen (Int
p forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ \String
s0 -> do
    (String
"Biff",    String
s1) <- ReadS String
lex String
s0
    (String
"{",       String
s2) <- ReadS String
lex String
s1
    (String
"runBiff", String
s3) <- ReadS String
lex String
s2
    (p (f a) (g b)
x,         String
s4) <- forall (f :: * -> * -> *) a b.
Read2 f =>
(Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS b)
-> ReadS [b]
-> Int
-> ReadS (f a b)
liftReadsPrec2 (forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
liftReadsPrec Int -> ReadS a
rp1 ReadS [a]
rl1) (forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> ReadS [f a]
liftReadList Int -> ReadS a
rp1 ReadS [a]
rl1)
                                      (forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
liftReadsPrec Int -> ReadS b
rp2 ReadS [b]
rl2) (forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> ReadS [f a]
liftReadList Int -> ReadS b
rp2 ReadS [b]
rl2) Int
0 String
s3
    (String
"}",       String
s5) <- ReadS String
lex String
s4
    forall (m :: * -> *) a. Monad m => a -> m a
return (forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
p (f a) (g b) -> Biff p f g a b
Biff p (f a) (g b)
x, String
s5)

instance (Show2 p, Show1 f, Show1 g, Show a) => Show1 (Biff p f g a) where
  liftShowsPrec :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> Biff p f g a a -> ShowS
liftShowsPrec = forall (f :: * -> * -> *) a b.
Show2 f =>
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> f a b
-> ShowS
liftShowsPrec2 forall a. Show a => Int -> a -> ShowS
showsPrec forall a. Show a => [a] -> ShowS
showList
instance (Show2 p, Show1 f, Show1 g) => Show2 (Biff p f g) where
  liftShowsPrec2 :: forall a b.
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> Biff p f g a b
-> ShowS
liftShowsPrec2 Int -> a -> ShowS
sp1 [a] -> ShowS
sl1 Int -> b -> ShowS
sp2 [b] -> ShowS
sl2 Int
p (Biff p (f a) (g b)
x) = Bool -> ShowS -> ShowS
showParen (Int
p forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$
      String -> ShowS
showString String
"Biff {runBiff = "
    forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> * -> *) a b.
Show2 f =>
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> f a b
-> ShowS
liftShowsPrec2 (forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp1 [a] -> ShowS
sl1) (forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [f a] -> ShowS
liftShowList Int -> a -> ShowS
sp1 [a] -> ShowS
sl1)
                     (forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> b -> ShowS
sp2 [b] -> ShowS
sl2) (forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [f a] -> ShowS
liftShowList Int -> b -> ShowS
sp2 [b] -> ShowS
sl2) Int
0 p (f a) (g b)
x
    forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
'}'

instance (Bifunctor p, Functor f, Functor g) => Bifunctor (Biff p f g) where
  first :: forall a b c. (a -> b) -> Biff p f g a c -> Biff p f g b c
first a -> b
f = forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
p (f a) (g b) -> Biff p f g a b
Biff forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
Biff p f g a b -> p (f a) (g b)
runBiff
  {-# INLINE first #-}
  second :: forall b c a. (b -> c) -> Biff p f g a b -> Biff p f g a c
second b -> c
f = forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
p (f a) (g b) -> Biff p f g a b
Biff forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> c
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
Biff p f g a b -> p (f a) (g b)
runBiff
  {-# INLINE second #-}
  bimap :: forall a b c d.
(a -> b) -> (c -> d) -> Biff p f g a c -> Biff p f g b d
bimap a -> b
f c -> d
g = forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
p (f a) (g b) -> Biff p f g a b
Biff forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap c -> d
g) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
Biff p f g a b -> p (f a) (g b)
runBiff
  {-# INLINE bimap #-}

instance (Bifunctor p, Functor g) => Functor (Biff p f g a) where
  fmap :: forall a b. (a -> b) -> Biff p f g a a -> Biff p f g a b
fmap a -> b
f = forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
p (f a) (g b) -> Biff p f g a b
Biff forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
Biff p f g a b -> p (f a) (g b)
runBiff
  {-# INLINE fmap #-}

instance (Biapplicative p, Applicative f, Applicative g) => Biapplicative (Biff p f g) where
  bipure :: forall a b. a -> b -> Biff p f g a b
bipure a
a b
b = forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
p (f a) (g b) -> Biff p f g a b
Biff (forall (p :: * -> * -> *) a b. Biapplicative p => a -> b -> p a b
bipure (forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a) (forall (f :: * -> *) a. Applicative f => a -> f a
pure b
b))
  {-# INLINE bipure #-}

  Biff p (f (a -> b)) (g (c -> d))
fg <<*>> :: forall a b c d.
Biff p f g (a -> b) (c -> d) -> Biff p f g a c -> Biff p f g b d
<<*>> Biff p (f a) (g c)
xy = forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
p (f a) (g b) -> Biff p f g a b
Biff (forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
(<*>) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
(<*>) p (f (a -> b)) (g (c -> d))
fg forall (p :: * -> * -> *) a b c d.
Biapplicative p =>
p (a -> b) (c -> d) -> p a c -> p b d
<<*>> p (f a) (g c)
xy)
  {-# INLINE (<<*>>) #-}

instance (Bifoldable p, Foldable g) => Foldable (Biff p f g a) where
  foldMap :: forall m a. Monoid m => (a -> m) -> Biff p f g a a -> m
foldMap a -> m
f = forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap (forall a b. a -> b -> a
const forall a. Monoid a => a
mempty) (forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap a -> m
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
Biff p f g a b -> p (f a) (g b)
runBiff
  {-# INLINE foldMap #-}

instance (Bifoldable p, Foldable f, Foldable g) => Bifoldable (Biff p f g) where
  bifoldMap :: forall m a b.
Monoid m =>
(a -> m) -> (b -> m) -> Biff p f g a b -> m
bifoldMap a -> m
f b -> m
g = forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap (forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap a -> m
f) (forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap b -> m
g) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
Biff p f g a b -> p (f a) (g b)
runBiff
  {-# INLINE bifoldMap #-}

instance (Bifoldable1 p, Foldable1 f, Foldable1 g) => Bifoldable1 (Biff p f g) where
  bifoldMap1 :: forall m a b.
Semigroup m =>
(a -> m) -> (b -> m) -> Biff p f g a b -> m
bifoldMap1 a -> m
f b -> m
g = forall (t :: * -> * -> *) m a b.
(Bifoldable1 t, Semigroup m) =>
(a -> m) -> (b -> m) -> t a b -> m
bifoldMap1 (forall (t :: * -> *) m a.
(Foldable1 t, Semigroup m) =>
(a -> m) -> t a -> m
foldMap1 a -> m
f) (forall (t :: * -> *) m a.
(Foldable1 t, Semigroup m) =>
(a -> m) -> t a -> m
foldMap1 b -> m
g) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
Biff p f g a b -> p (f a) (g b)
runBiff
  {-# INLINE bifoldMap1 #-}

instance (Bitraversable p, Traversable g) => Traversable (Biff p f g a) where
  traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Biff p f g a a -> f (Biff p f g a b)
traverse a -> f b
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
p (f a) (g b) -> Biff p f g a b
Biff forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bitraversable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f (t c d)
bitraverse forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> f b
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
Biff p f g a b -> p (f a) (g b)
runBiff
  {-# INLINE traverse #-}

instance (Bitraversable p, Traversable f, Traversable g) => Bitraversable (Biff p f g) where
  bitraverse :: forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> Biff p f g a b -> f (Biff p f g c d)
bitraverse a -> f c
f b -> f d
g = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
p (f a) (g b) -> Biff p f g a b
Biff forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bitraversable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f (t c d)
bitraverse (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> f c
f) (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse b -> f d
g) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
Biff p f g a b -> p (f a) (g b)
runBiff
  {-# INLINE bitraverse #-}

-- | @since 5.6.1
instance (f ~ g, Functor f, Swap p) => Swap (Biff p f g) where
  swap :: forall a b. Biff p f g a b -> Biff p f g b a
swap = forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
p (f a) (g b) -> Biff p f g a b
Biff forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b. Swap p => p a b -> p b a
swap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} {k} {k} (p :: k -> k -> *) (f :: k -> k)
       (g :: k -> k) (a :: k) (b :: k).
Biff p f g a b -> p (f a) (g b)
runBiff