{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}

#if __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE DeriveGeneric #-}
#endif

#if __GLASGOW_HASKELL__ >= 706
{-# LANGUAGE PolyKinds #-}
#endif

#if __GLASGOW_HASKELL__ >= 708
{-# LANGUAGE Safe #-}
#elif __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE Trustworthy #-}
#endif
#include "bifunctors-common.h"

-----------------------------------------------------------------------------
-- |
-- 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

#if __GLASGOW_HASKELL__ < 710
import Control.Applicative
#endif

import Data.Biapplicative
import Data.Bifoldable
import Data.Bitraversable

#if __GLASGOW_HASKELL__ < 710
import Data.Foldable
import Data.Monoid
import Data.Traversable
#endif

#if __GLASGOW_HASKELL__ >= 708
import Data.Typeable
#endif

#if __GLASGOW_HASKELL__ >= 702
import GHC.Generics
#endif

#if LIFTED_FUNCTOR_CLASSES
import Data.Functor.Classes
#endif

-- | Compose two 'Functor's on the inside of a 'Bifunctor'.
newtype Biff p f g a b = Biff { 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
(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)
-> Eq (Biff p f g a b)
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, Eq (Biff p f g a b)
Eq (Biff p f g a b)
-> (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 -> Bool)
-> (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)
-> (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 -> Biff p f g a b)
-> (Biff p f g a b -> Biff p f g a b -> Biff p f g a b)
-> Ord (Biff p f g a 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 -> 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
$cp1Ord :: 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)
Ord, Int -> Biff p f g a b -> ShowS
[Biff p f g a b] -> ShowS
Biff p f g a b -> String
(Int -> Biff p f g a b -> ShowS)
-> (Biff p f g a b -> String)
-> ([Biff p f g a b] -> ShowS)
-> Show (Biff p f g a b)
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)
Int -> ReadS (Biff p f g a b)
ReadS [Biff p f g a b]
(Int -> ReadS (Biff p f g a b))
-> ReadS [Biff p f g a b]
-> ReadPrec (Biff p f g a b)
-> ReadPrec [Biff p f g a b]
-> Read (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
#if __GLASGOW_HASKELL__ >= 702
           , (forall x. Biff p f g a b -> Rep (Biff p f g a b) x)
-> (forall x. Rep (Biff p f g a b) x -> Biff p f g a b)
-> Generic (Biff p f g a b)
forall x. Rep (Biff p f g a b) x -> Biff p f g a b
forall x. Biff p f g a b -> Rep (Biff p f g a b) x
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
#endif
#if __GLASGOW_HASKELL__ >= 708
           , Typeable
#endif
           )
#if __GLASGOW_HASKELL__ >= 702
# if __GLASGOW_HASKELL__ >= 708
deriving instance Functor (p (f a)) => Generic1 (Biff p f g a)
# else
data BiffMetaData
data BiffMetaCons
data BiffMetaSel

instance Datatype BiffMetaData where
    datatypeName = const "Biff"
    moduleName = const "Data.Bifunctor.Biff"

instance Constructor BiffMetaCons where
    conName = const "Biff"
    conIsRecord = const True

instance Selector BiffMetaSel where
    selName = const "runBiff"

instance Functor (p (f a)) => Generic1 (Biff p f g a) where
    type Rep1 (Biff p f g a) = D1 BiffMetaData (C1 BiffMetaCons
        (S1 BiffMetaSel (p (f a) :.: Rec1 g)))
    from1 = M1 . M1 . M1 . Comp1 . fmap Rec1 . runBiff
    to1 = Biff . fmap unRec1 . unComp1 . unM1 . unM1 . unM1
# endif
#endif

#if LIFTED_FUNCTOR_CLASSES
instance (Eq2 p, Eq1 f, Eq1 g, Eq a) => Eq1 (Biff p f g a) where
  liftEq :: (a -> b -> Bool) -> Biff p f g a a -> Biff p f g a b -> Bool
liftEq = (a -> a -> Bool)
-> (a -> b -> Bool) -> Biff p f g a a -> Biff p f g a b -> Bool
forall (f :: * -> * -> *) a b c d.
Eq2 f =>
(a -> b -> Bool) -> (c -> d -> Bool) -> f a c -> f b d -> Bool
liftEq2 a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
instance (Eq2 p, Eq1 f, Eq1 g) => Eq2 (Biff p f g) where
  liftEq2 :: (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) = (f a -> f b -> Bool)
-> (g c -> g d -> Bool) -> p (f a) (g c) -> p (f b) (g d) -> Bool
forall (f :: * -> * -> *) a b c d.
Eq2 f =>
(a -> b -> Bool) -> (c -> d -> Bool) -> f a c -> f b d -> Bool
liftEq2 ((a -> b -> Bool) -> f a -> f b -> Bool
forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
f) ((c -> d -> Bool) -> g c -> g d -> Bool
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 :: (a -> b -> Ordering)
-> Biff p f g a a -> Biff p f g a b -> Ordering
liftCompare = (a -> a -> Ordering)
-> (a -> b -> Ordering)
-> Biff p f g a a
-> Biff p f g a b
-> Ordering
forall (f :: * -> * -> *) a b c d.
Ord2 f =>
(a -> b -> Ordering)
-> (c -> d -> Ordering) -> f a c -> f b d -> Ordering
liftCompare2 a -> a -> Ordering
forall a. Ord a => a -> a -> Ordering
compare
instance (Ord2 p, Ord1 f, Ord1 g) => Ord2 (Biff p f g) where
  liftCompare2 :: (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) = (f a -> f b -> Ordering)
-> (g c -> g d -> Ordering)
-> p (f a) (g c)
-> p (f b) (g d)
-> Ordering
forall (f :: * -> * -> *) a b c d.
Ord2 f =>
(a -> b -> Ordering)
-> (c -> d -> Ordering) -> f a c -> f b d -> Ordering
liftCompare2 ((a -> b -> Ordering) -> f a -> f b -> Ordering
forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare a -> b -> Ordering
f) ((c -> d -> Ordering) -> g c -> g d -> Ordering
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 :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Biff p f g a a)
liftReadsPrec = (Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS a)
-> ReadS [a]
-> Int
-> ReadS (Biff p f g a a)
forall (f :: * -> * -> *) a b.
Read2 f =>
(Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS b)
-> ReadS [b]
-> Int
-> ReadS (f a b)
liftReadsPrec2 Int -> ReadS a
forall a. Read a => Int -> ReadS a
readsPrec ReadS [a]
forall a. Read a => ReadS [a]
readList
instance (Read2 p, Read1 f, Read1 g) => Read2 (Biff p f g) where
  liftReadsPrec2 :: (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 = Bool -> ReadS (Biff p f g a b) -> ReadS (Biff p f g a b)
forall a. Bool -> ReadS a -> ReadS a
readParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ReadS (Biff p f g a b) -> ReadS (Biff p f g a b))
-> ReadS (Biff p f g a b) -> ReadS (Biff p f g a b)
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) <- (Int -> ReadS (f a))
-> ReadS [f a]
-> (Int -> ReadS (g b))
-> ReadS [g b]
-> Int
-> ReadS (p (f a) (g b))
forall (f :: * -> * -> *) a b.
Read2 f =>
(Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS b)
-> ReadS [b]
-> Int
-> ReadS (f a b)
liftReadsPrec2 ((Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
liftReadsPrec Int -> ReadS a
rp1 ReadS [a]
rl1) ((Int -> ReadS a) -> ReadS [a] -> ReadS [f a]
forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> ReadS [f a]
liftReadList Int -> ReadS a
rp1 ReadS [a]
rl1)
                                      ((Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (g b)
forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
liftReadsPrec Int -> ReadS b
rp2 ReadS [b]
rl2) ((Int -> ReadS b) -> ReadS [b] -> ReadS [g b]
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
    (Biff p f g a b, String) -> [(Biff p f g a b, String)]
forall (m :: * -> *) a. Monad m => a -> m a
return (p (f a) (g b) -> Biff p f g a 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 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 :: (Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> Biff p f g a a -> ShowS
liftShowsPrec = (Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> a -> ShowS)
-> ([a] -> ShowS)
-> Int
-> Biff p f g a a
-> ShowS
forall (f :: * -> * -> *) a b.
Show2 f =>
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> f a b
-> ShowS
liftShowsPrec2 Int -> a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec [a] -> ShowS
forall a. Show a => [a] -> ShowS
showList
instance (Show2 p, Show1 f, Show1 g) => Show2 (Biff p f g) where
  liftShowsPrec2 :: (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 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$
      String -> ShowS
showString String
"Biff {runBiff = "
    ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> f a -> ShowS)
-> ([f a] -> ShowS)
-> (Int -> g b -> ShowS)
-> ([g b] -> ShowS)
-> Int
-> p (f a) (g b)
-> ShowS
forall (f :: * -> * -> *) a b.
Show2 f =>
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> f a b
-> ShowS
liftShowsPrec2 ((Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp1 [a] -> ShowS
sl1) ((Int -> a -> ShowS) -> ([a] -> ShowS) -> [f a] -> ShowS
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [f a] -> ShowS
liftShowList Int -> a -> ShowS
sp1 [a] -> ShowS
sl1)
                     ((Int -> b -> ShowS) -> ([b] -> ShowS) -> Int -> g b -> ShowS
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> b -> ShowS
sp2 [b] -> ShowS
sl2) ((Int -> b -> ShowS) -> ([b] -> ShowS) -> [g b] -> ShowS
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
    ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
'}'
#endif

instance (Bifunctor p, Functor f, Functor g) => Bifunctor (Biff p f g) where
  first :: (a -> b) -> Biff p f g a c -> Biff p f g b c
first a -> b
f = p (f b) (g c) -> Biff p f g b c
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 b) (g c) -> Biff p f g b c)
-> (Biff p f g a c -> p (f b) (g c))
-> Biff p f g a c
-> Biff p f g b c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (f a -> f b) -> p (f a) (g c) -> p (f b) (g c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ((a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) (p (f a) (g c) -> p (f b) (g c))
-> (Biff p f g a c -> p (f a) (g c))
-> Biff p f g a c
-> p (f b) (g c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Biff p f g a c -> p (f a) (g c)
forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Biff p f g a b -> p (f a) (g b)
runBiff
  {-# INLINE first #-}
  second :: (b -> c) -> Biff p f g a b -> Biff p f g a c
second b -> c
f = p (f a) (g c) -> Biff p f g a c
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 c) -> Biff p f g a c)
-> (Biff p f g a b -> p (f a) (g c))
-> Biff p f g a b
-> Biff p f g a c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (g b -> g c) -> p (f a) (g b) -> p (f a) (g c)
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second ((b -> c) -> g b -> g c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> c
f) (p (f a) (g b) -> p (f a) (g c))
-> (Biff p f g a b -> p (f a) (g b))
-> Biff p f g a b
-> p (f a) (g c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Biff p f g a b -> p (f a) (g b)
forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Biff p f g a b -> p (f a) (g b)
runBiff
  {-# INLINE second #-}
  bimap :: (a -> b) -> (c -> d) -> Biff p f g a c -> Biff p f g b d
bimap a -> b
f c -> d
g = p (f b) (g d) -> Biff p f g b d
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 b) (g d) -> Biff p f g b d)
-> (Biff p f g a c -> p (f b) (g d))
-> Biff p f g a c
-> Biff p f g b d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (f a -> f b) -> (g c -> g d) -> p (f a) (g c) -> p (f b) (g d)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap ((a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) ((c -> d) -> g c -> g d
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap c -> d
g) (p (f a) (g c) -> p (f b) (g d))
-> (Biff p f g a c -> p (f a) (g c))
-> Biff p f g a c
-> p (f b) (g d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Biff p f g a c -> p (f a) (g c)
forall k k (p :: k -> k -> *) k (f :: k -> 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 :: (a -> b) -> Biff p f g a a -> Biff p f g a b
fmap a -> b
f = p (f a) (g b) -> Biff p f g a 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 (p (f a) (g b) -> Biff p f g a b)
-> (Biff p f g a a -> p (f a) (g b))
-> Biff p f g a a
-> Biff p f g a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (g a -> g b) -> p (f a) (g a) -> p (f a) (g b)
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second ((a -> b) -> g a -> g b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) (p (f a) (g a) -> p (f a) (g b))
-> (Biff p f g a a -> p (f a) (g a))
-> Biff p f g a a
-> p (f a) (g b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Biff p f g a a -> p (f a) (g a)
forall k k (p :: k -> k -> *) k (f :: k -> 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 :: a -> b -> Biff p f g a b
bipure a
a b
b = p (f a) (g b) -> Biff p f g a 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 (f a -> g b -> p (f a) (g b)
forall (p :: * -> * -> *) a b. Biapplicative p => a -> b -> p a b
bipure (a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a) (b -> g b
forall (f :: * -> *) a. Applicative f => a -> f a
pure b
b))
  {-# INLINE bipure #-}

  Biff p (f (a -> b)) (g (c -> d))
fg <<*>> :: 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 = p (f b) (g d) -> Biff p f g b d
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 ((f (a -> b) -> f a -> f b)
-> (g (c -> d) -> g c -> g d)
-> p (f (a -> b)) (g (c -> d))
-> p (f a -> f b) (g c -> g d)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
(<*>) g (c -> d) -> g c -> g d
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
(<*>) p (f (a -> b)) (g (c -> d))
fg p (f a -> f b) (g c -> g d) -> p (f a) (g c) -> p (f b) (g d)
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 :: (a -> m) -> Biff p f g a a -> m
foldMap a -> m
f = (f a -> m) -> (g a -> m) -> p (f a) (g a) -> m
forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap (m -> f a -> m
forall a b. a -> b -> a
const m
forall a. Monoid a => a
mempty) ((a -> m) -> g a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap a -> m
f) (p (f a) (g a) -> m)
-> (Biff p f g a a -> p (f a) (g a)) -> Biff p f g a a -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Biff p f g a a -> p (f a) (g a)
forall k k (p :: k -> k -> *) k (f :: k -> 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 :: (a -> m) -> (b -> m) -> Biff p f g a b -> m
bifoldMap a -> m
f b -> m
g = (f a -> m) -> (g b -> m) -> p (f a) (g b) -> m
forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap ((a -> m) -> f a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap a -> m
f) ((b -> m) -> g b -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap b -> m
g) (p (f a) (g b) -> m)
-> (Biff p f g a b -> p (f a) (g b)) -> Biff p f g a b -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Biff p f g a b -> p (f a) (g b)
forall k k (p :: k -> k -> *) k (f :: k -> k) k (g :: k -> k)
       (a :: k) (b :: k).
Biff p f g a b -> p (f a) (g b)
runBiff
  {-# INLINE bifoldMap #-}

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