{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE TypeFamilies #-}

#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.Wrapped
  ( WrappedBifunctor(..)
  ) 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

-- | Make a 'Functor' over the second argument of a 'Bifunctor'.
newtype WrappedBifunctor p a b = WrapBifunctor { WrappedBifunctor p a b -> p a b
unwrapBifunctor :: p a b }
  deriving ( WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool
(WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool)
-> (WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool)
-> Eq (WrappedBifunctor p a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Eq (p a b) =>
WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool
/= :: WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool
$c/= :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Eq (p a b) =>
WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool
== :: WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool
$c== :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Eq (p a b) =>
WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool
Eq, Eq (WrappedBifunctor p a b)
Eq (WrappedBifunctor p a b)
-> (WrappedBifunctor p a b -> WrappedBifunctor p a b -> Ordering)
-> (WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool)
-> (WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool)
-> (WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool)
-> (WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool)
-> (WrappedBifunctor p a b
    -> WrappedBifunctor p a b -> WrappedBifunctor p a b)
-> (WrappedBifunctor p a b
    -> WrappedBifunctor p a b -> WrappedBifunctor p a b)
-> Ord (WrappedBifunctor p a b)
WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool
WrappedBifunctor p a b -> WrappedBifunctor p a b -> Ordering
WrappedBifunctor p a b
-> WrappedBifunctor p a b -> WrappedBifunctor p 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 -> *) (a :: k) (b :: k).
Ord (p a b) =>
Eq (WrappedBifunctor p a b)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedBifunctor p a b -> WrappedBifunctor p a b -> Ordering
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedBifunctor p a b
-> WrappedBifunctor p a b -> WrappedBifunctor p a b
min :: WrappedBifunctor p a b
-> WrappedBifunctor p a b -> WrappedBifunctor p a b
$cmin :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedBifunctor p a b
-> WrappedBifunctor p a b -> WrappedBifunctor p a b
max :: WrappedBifunctor p a b
-> WrappedBifunctor p a b -> WrappedBifunctor p a b
$cmax :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedBifunctor p a b
-> WrappedBifunctor p a b -> WrappedBifunctor p a b
>= :: WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool
$c>= :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool
> :: WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool
$c> :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool
<= :: WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool
$c<= :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool
< :: WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool
$c< :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedBifunctor p a b -> WrappedBifunctor p a b -> Bool
compare :: WrappedBifunctor p a b -> WrappedBifunctor p a b -> Ordering
$ccompare :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
WrappedBifunctor p a b -> WrappedBifunctor p a b -> Ordering
$cp1Ord :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p a b) =>
Eq (WrappedBifunctor p a b)
Ord, Int -> WrappedBifunctor p a b -> ShowS
[WrappedBifunctor p a b] -> ShowS
WrappedBifunctor p a b -> String
(Int -> WrappedBifunctor p a b -> ShowS)
-> (WrappedBifunctor p a b -> String)
-> ([WrappedBifunctor p a b] -> ShowS)
-> Show (WrappedBifunctor p a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Show (p a b) =>
Int -> WrappedBifunctor p a b -> ShowS
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Show (p a b) =>
[WrappedBifunctor p a b] -> ShowS
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Show (p a b) =>
WrappedBifunctor p a b -> String
showList :: [WrappedBifunctor p a b] -> ShowS
$cshowList :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Show (p a b) =>
[WrappedBifunctor p a b] -> ShowS
show :: WrappedBifunctor p a b -> String
$cshow :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Show (p a b) =>
WrappedBifunctor p a b -> String
showsPrec :: Int -> WrappedBifunctor p a b -> ShowS
$cshowsPrec :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Show (p a b) =>
Int -> WrappedBifunctor p a b -> ShowS
Show, ReadPrec [WrappedBifunctor p a b]
ReadPrec (WrappedBifunctor p a b)
Int -> ReadS (WrappedBifunctor p a b)
ReadS [WrappedBifunctor p a b]
(Int -> ReadS (WrappedBifunctor p a b))
-> ReadS [WrappedBifunctor p a b]
-> ReadPrec (WrappedBifunctor p a b)
-> ReadPrec [WrappedBifunctor p a b]
-> Read (WrappedBifunctor p a b)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p a b) =>
ReadPrec [WrappedBifunctor p a b]
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p a b) =>
ReadPrec (WrappedBifunctor p a b)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p a b) =>
Int -> ReadS (WrappedBifunctor p a b)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p a b) =>
ReadS [WrappedBifunctor p a b]
readListPrec :: ReadPrec [WrappedBifunctor p a b]
$creadListPrec :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p a b) =>
ReadPrec [WrappedBifunctor p a b]
readPrec :: ReadPrec (WrappedBifunctor p a b)
$creadPrec :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p a b) =>
ReadPrec (WrappedBifunctor p a b)
readList :: ReadS [WrappedBifunctor p a b]
$creadList :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p a b) =>
ReadS [WrappedBifunctor p a b]
readsPrec :: Int -> ReadS (WrappedBifunctor p a b)
$creadsPrec :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p a b) =>
Int -> ReadS (WrappedBifunctor p a b)
Read
#if __GLASGOW_HASKELL__ >= 702
           , (forall x.
 WrappedBifunctor p a b -> Rep (WrappedBifunctor p a b) x)
-> (forall x.
    Rep (WrappedBifunctor p a b) x -> WrappedBifunctor p a b)
-> Generic (WrappedBifunctor p a b)
forall x. Rep (WrappedBifunctor p a b) x -> WrappedBifunctor p a b
forall x. WrappedBifunctor p a b -> Rep (WrappedBifunctor p 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 -> *) (a :: k) (b :: k) x.
Rep (WrappedBifunctor p a b) x -> WrappedBifunctor p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k) x.
WrappedBifunctor p a b -> Rep (WrappedBifunctor p a b) x
$cto :: forall k k (p :: k -> k -> *) (a :: k) (b :: k) x.
Rep (WrappedBifunctor p a b) x -> WrappedBifunctor p a b
$cfrom :: forall k k (p :: k -> k -> *) (a :: k) (b :: k) x.
WrappedBifunctor p a b -> Rep (WrappedBifunctor p a b) x
Generic
#endif
#if __GLASGOW_HASKELL__ >= 708
           , (forall (a :: k).
 WrappedBifunctor p a a -> Rep1 (WrappedBifunctor p a) a)
-> (forall (a :: k).
    Rep1 (WrappedBifunctor p a) a -> WrappedBifunctor p a a)
-> Generic1 (WrappedBifunctor p a)
forall (a :: k).
Rep1 (WrappedBifunctor p a) a -> WrappedBifunctor p a a
forall (a :: k).
WrappedBifunctor p a a -> Rep1 (WrappedBifunctor p a) a
forall k k (p :: k -> k -> *) (a :: k) (a :: k).
Rep1 (WrappedBifunctor p a) a -> WrappedBifunctor p a a
forall k k (p :: k -> k -> *) (a :: k) (a :: k).
WrappedBifunctor p a a -> Rep1 (WrappedBifunctor p a) a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cto1 :: forall k k (p :: k -> k -> *) (a :: k) (a :: k).
Rep1 (WrappedBifunctor p a) a -> WrappedBifunctor p a a
$cfrom1 :: forall k k (p :: k -> k -> *) (a :: k) (a :: k).
WrappedBifunctor p a a -> Rep1 (WrappedBifunctor p a) a
Generic1
           , Typeable
#endif
           )

#if __GLASGOW_HASKELL__ >= 702 && __GLASGOW_HASKELL__ < 708
data WrappedBifunctorMetaData
data WrappedBifunctorMetaCons
data WrappedBifunctorMetaSel

instance Datatype WrappedBifunctorMetaData where
    datatypeName = const "WrappedBifunctor"
    moduleName = const "Data.Bifunctor.Wrapped"

instance Constructor WrappedBifunctorMetaCons where
    conName = const "WrapBifunctor"
    conIsRecord = const True

instance Selector WrappedBifunctorMetaSel where
    selName = const "unwrapBifunctor"

instance Generic1 (WrappedBifunctor p a) where
    type Rep1 (WrappedBifunctor p a) = D1 WrappedBifunctorMetaData
        (C1 WrappedBifunctorMetaCons
            (S1 WrappedBifunctorMetaSel (Rec1 (p a))))
    from1 = M1 . M1 . M1 . Rec1 . unwrapBifunctor
    to1 = WrapBifunctor . unRec1 . unM1 . unM1 . unM1
#endif

#if LIFTED_FUNCTOR_CLASSES
instance (Eq2 p, Eq a) => Eq1 (WrappedBifunctor p a) where
  liftEq :: (a -> b -> Bool)
-> WrappedBifunctor p a a -> WrappedBifunctor p a b -> Bool
liftEq = (a -> a -> Bool)
-> (a -> b -> Bool)
-> WrappedBifunctor p a a
-> WrappedBifunctor p 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 => Eq2 (WrappedBifunctor p) where
  liftEq2 :: (a -> b -> Bool)
-> (c -> d -> Bool)
-> WrappedBifunctor p a c
-> WrappedBifunctor p b d
-> Bool
liftEq2 a -> b -> Bool
f c -> d -> Bool
g (WrapBifunctor p a c
x) (WrapBifunctor p b d
y) = (a -> b -> Bool) -> (c -> d -> Bool) -> p a c -> p b 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 c -> d -> Bool
g p a c
x p b d
y

instance (Ord2 p, Ord a) => Ord1 (WrappedBifunctor p a) where
  liftCompare :: (a -> b -> Ordering)
-> WrappedBifunctor p a a -> WrappedBifunctor p a b -> Ordering
liftCompare = (a -> a -> Ordering)
-> (a -> b -> Ordering)
-> WrappedBifunctor p a a
-> WrappedBifunctor p 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 => Ord2 (WrappedBifunctor p) where
  liftCompare2 :: (a -> b -> Ordering)
-> (c -> d -> Ordering)
-> WrappedBifunctor p a c
-> WrappedBifunctor p b d
-> Ordering
liftCompare2 a -> b -> Ordering
f c -> d -> Ordering
g (WrapBifunctor p a c
x) (WrapBifunctor p b d
y) = (a -> b -> Ordering)
-> (c -> d -> Ordering) -> p a c -> p b 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 c -> d -> Ordering
g p a c
x p b d
y

instance (Read2 p, Read a) => Read1 (WrappedBifunctor p a) where
  liftReadsPrec :: (Int -> ReadS a)
-> ReadS [a] -> Int -> ReadS (WrappedBifunctor p a a)
liftReadsPrec = (Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS a)
-> ReadS [a]
-> Int
-> ReadS (WrappedBifunctor p 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 => Read2 (WrappedBifunctor p) where
  liftReadsPrec2 :: (Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS b)
-> ReadS [b]
-> Int
-> ReadS (WrappedBifunctor p a b)
liftReadsPrec2 Int -> ReadS a
rp1 ReadS [a]
rl1 Int -> ReadS b
rp2 ReadS [b]
rl2 Int
p = Bool
-> ReadS (WrappedBifunctor p a b) -> ReadS (WrappedBifunctor p 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 (WrappedBifunctor p a b) -> ReadS (WrappedBifunctor p a b))
-> ReadS (WrappedBifunctor p a b) -> ReadS (WrappedBifunctor p a b)
forall a b. (a -> b) -> a -> b
$ \String
s0 -> do
    (String
"WrapBifunctor",   String
s1) <- ReadS String
lex String
s0
    (String
"{",               String
s2) <- ReadS String
lex String
s1
    (String
"unwrapBifunctor", String
s3) <- ReadS String
lex String
s2
    (p a b
x,                 String
s4) <- (Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS b)
-> ReadS [b]
-> Int
-> ReadS (p a 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
rp1 ReadS [a]
rl1 Int -> ReadS b
rp2 ReadS [b]
rl2 Int
0 String
s3
    (String
"}",               String
s5) <- ReadS String
lex String
s4
    (WrappedBifunctor p a b, String)
-> [(WrappedBifunctor p a b, String)]
forall (m :: * -> *) a. Monad m => a -> m a
return (p a b -> WrappedBifunctor p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedBifunctor p a b
WrapBifunctor p a b
x, String
s5)

instance (Show2 p, Show a) => Show1 (WrappedBifunctor p a) where
  liftShowsPrec :: (Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> WrappedBifunctor p a a -> ShowS
liftShowsPrec = (Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> a -> ShowS)
-> ([a] -> ShowS)
-> Int
-> WrappedBifunctor p 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 => Show2 (WrappedBifunctor p) where
  liftShowsPrec2 :: (Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> WrappedBifunctor p a b
-> ShowS
liftShowsPrec2 Int -> a -> ShowS
sp1 [a] -> ShowS
sl1 Int -> b -> ShowS
sp2 [b] -> ShowS
sl2 Int
p (WrapBifunctor p a 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
"WrapBifunctor {unwrapBifunctor = "
    ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> p a 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
sp1 [a] -> ShowS
sl1 Int -> b -> ShowS
sp2 [b] -> ShowS
sl2 Int
0 p a b
x
    ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
'}'
#endif

instance Bifunctor p => Bifunctor (WrappedBifunctor p) where
  first :: (a -> b) -> WrappedBifunctor p a c -> WrappedBifunctor p b c
first a -> b
f = p b c -> WrappedBifunctor p b c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedBifunctor p a b
WrapBifunctor (p b c -> WrappedBifunctor p b c)
-> (WrappedBifunctor p a c -> p b c)
-> WrappedBifunctor p a c
-> WrappedBifunctor p b c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> p a c -> p b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
f (p a c -> p b c)
-> (WrappedBifunctor p a c -> p a c)
-> WrappedBifunctor p a c
-> p b c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedBifunctor p a c -> p a c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedBifunctor p a b -> p a b
unwrapBifunctor
  {-# INLINE first #-}
  second :: (b -> c) -> WrappedBifunctor p a b -> WrappedBifunctor p a c
second b -> c
f = p a c -> WrappedBifunctor p a c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedBifunctor p a b
WrapBifunctor (p a c -> WrappedBifunctor p a c)
-> (WrappedBifunctor p a b -> p a c)
-> WrappedBifunctor p a b
-> WrappedBifunctor p a c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> c) -> p a b -> p a c
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second b -> c
f (p a b -> p a c)
-> (WrappedBifunctor p a b -> p a b)
-> WrappedBifunctor p a b
-> p a c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedBifunctor p a b -> p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedBifunctor p a b -> p a b
unwrapBifunctor
  {-# INLINE second #-}
  bimap :: (a -> b)
-> (c -> d) -> WrappedBifunctor p a c -> WrappedBifunctor p b d
bimap a -> b
f c -> d
g = p b d -> WrappedBifunctor p b d
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedBifunctor p a b
WrapBifunctor (p b d -> WrappedBifunctor p b d)
-> (WrappedBifunctor p a c -> p b d)
-> WrappedBifunctor p a c
-> WrappedBifunctor p b d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> (c -> d) -> p a c -> p b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap a -> b
f c -> d
g (p a c -> p b d)
-> (WrappedBifunctor p a c -> p a c)
-> WrappedBifunctor p a c
-> p b d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedBifunctor p a c -> p a c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedBifunctor p a b -> p a b
unwrapBifunctor
  {-# INLINE bimap #-}

instance Bifunctor p => Functor (WrappedBifunctor p a) where
  fmap :: (a -> b) -> WrappedBifunctor p a a -> WrappedBifunctor p a b
fmap a -> b
f = p a b -> WrappedBifunctor p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedBifunctor p a b
WrapBifunctor (p a b -> WrappedBifunctor p a b)
-> (WrappedBifunctor p a a -> p a b)
-> WrappedBifunctor p a a
-> WrappedBifunctor p a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> p a a -> p a b
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second a -> b
f (p a a -> p a b)
-> (WrappedBifunctor p a a -> p a a)
-> WrappedBifunctor p a a
-> p a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedBifunctor p a a -> p a a
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedBifunctor p a b -> p a b
unwrapBifunctor
  {-# INLINE fmap #-}

instance Biapplicative p => Biapplicative (WrappedBifunctor p) where
  bipure :: a -> b -> WrappedBifunctor p a b
bipure a
a b
b = p a b -> WrappedBifunctor p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedBifunctor p a b
WrapBifunctor (a -> b -> p a b
forall (p :: * -> * -> *) a b. Biapplicative p => a -> b -> p a b
bipure a
a b
b)
  {-# INLINE bipure #-}
  WrapBifunctor p (a -> b) (c -> d)
fg <<*>> :: WrappedBifunctor p (a -> b) (c -> d)
-> WrappedBifunctor p a c -> WrappedBifunctor p b d
<<*>> WrapBifunctor p a c
xy = p b d -> WrappedBifunctor p b d
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedBifunctor p a b
WrapBifunctor (p (a -> b) (c -> d)
fg p (a -> b) (c -> d) -> p a c -> p b d
forall (p :: * -> * -> *) a b c d.
Biapplicative p =>
p (a -> b) (c -> d) -> p a c -> p b d
<<*>> p a c
xy)
  {-# INLINE (<<*>>) #-}

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

instance Bifoldable p => Bifoldable (WrappedBifunctor p) where
  bifoldMap :: (a -> m) -> (b -> m) -> WrappedBifunctor p a b -> m
bifoldMap a -> m
f b -> m
g = (a -> m) -> (b -> m) -> p a b -> m
forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap a -> m
f b -> m
g (p a b -> m)
-> (WrappedBifunctor p a b -> p a b) -> WrappedBifunctor p a b -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedBifunctor p a b -> p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedBifunctor p a b -> p a b
unwrapBifunctor
  {-# INLINE bifoldMap #-}

instance Bitraversable p => Traversable (WrappedBifunctor p a) where
  traverse :: (a -> f b) -> WrappedBifunctor p a a -> f (WrappedBifunctor p a b)
traverse a -> f b
f = (p a b -> WrappedBifunctor p a b)
-> f (p a b) -> f (WrappedBifunctor p a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap p a b -> WrappedBifunctor p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedBifunctor p a b
WrapBifunctor (f (p a b) -> f (WrappedBifunctor p a b))
-> (WrappedBifunctor p a a -> f (p a b))
-> WrappedBifunctor p a a
-> f (WrappedBifunctor p a b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f a) -> (a -> f b) -> p a a -> f (p a 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 a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a -> f b
f (p a a -> f (p a b))
-> (WrappedBifunctor p a a -> p a a)
-> WrappedBifunctor p a a
-> f (p a b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedBifunctor p a a -> p a a
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedBifunctor p a b -> p a b
unwrapBifunctor
  {-# INLINE traverse #-}

instance Bitraversable p => Bitraversable (WrappedBifunctor p) where
  bitraverse :: (a -> f c)
-> (b -> f d)
-> WrappedBifunctor p a b
-> f (WrappedBifunctor p c d)
bitraverse a -> f c
f b -> f d
g = (p c d -> WrappedBifunctor p c d)
-> f (p c d) -> f (WrappedBifunctor p c d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap p c d -> WrappedBifunctor p c d
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p a b -> WrappedBifunctor p a b
WrapBifunctor (f (p c d) -> f (WrappedBifunctor p c d))
-> (WrappedBifunctor p a b -> f (p c d))
-> WrappedBifunctor p a b
-> f (WrappedBifunctor p c d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f c) -> (b -> f d) -> p a b -> f (p c 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 b -> f d
g (p a b -> f (p c d))
-> (WrappedBifunctor p a b -> p a b)
-> WrappedBifunctor p a b
-> f (p c d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedBifunctor p a b -> p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
WrappedBifunctor p a b -> p a b
unwrapBifunctor
  {-# INLINE bitraverse #-}