{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
#if __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE DeriveGeneric #-}
#endif
#if __GLASGOW_HASKELL__ >= 704
{-# LANGUAGE Safe #-}
#elif __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE Trustworthy #-}
#endif
#if __GLASGOW_HASKELL__ >= 706
{-# LANGUAGE PolyKinds #-}
#endif
#include "bifunctors-common.h"
module Data.Bifunctor.Flip
( Flip(..)
) where
#if __GLASGOW_HASKELL__ < 710
import Control.Applicative
#endif
import Data.Biapplicative
import Data.Bifoldable
import Data.Bifunctor.Functor
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
newtype Flip p a b = Flip { Flip p a b -> p b a
runFlip :: p b a }
deriving ( Flip p a b -> Flip p a b -> Bool
(Flip p a b -> Flip p a b -> Bool)
-> (Flip p a b -> Flip p a b -> Bool) -> Eq (Flip 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 b a) =>
Flip p a b -> Flip p a b -> Bool
/= :: Flip p a b -> Flip p a b -> Bool
$c/= :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Eq (p b a) =>
Flip p a b -> Flip p a b -> Bool
== :: Flip p a b -> Flip p a b -> Bool
$c== :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Eq (p b a) =>
Flip p a b -> Flip p a b -> Bool
Eq, Eq (Flip p a b)
Eq (Flip p a b)
-> (Flip p a b -> Flip p a b -> Ordering)
-> (Flip p a b -> Flip p a b -> Bool)
-> (Flip p a b -> Flip p a b -> Bool)
-> (Flip p a b -> Flip p a b -> Bool)
-> (Flip p a b -> Flip p a b -> Bool)
-> (Flip p a b -> Flip p a b -> Flip p a b)
-> (Flip p a b -> Flip p a b -> Flip p a b)
-> Ord (Flip p a b)
Flip p a b -> Flip p a b -> Bool
Flip p a b -> Flip p a b -> Ordering
Flip p a b -> Flip p a b -> Flip 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 b a) =>
Eq (Flip p a b)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p b a) =>
Flip p a b -> Flip p a b -> Bool
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p b a) =>
Flip p a b -> Flip p a b -> Ordering
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p b a) =>
Flip p a b -> Flip p a b -> Flip p a b
min :: Flip p a b -> Flip p a b -> Flip p a b
$cmin :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p b a) =>
Flip p a b -> Flip p a b -> Flip p a b
max :: Flip p a b -> Flip p a b -> Flip p a b
$cmax :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p b a) =>
Flip p a b -> Flip p a b -> Flip p a b
>= :: Flip p a b -> Flip p a b -> Bool
$c>= :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p b a) =>
Flip p a b -> Flip p a b -> Bool
> :: Flip p a b -> Flip p a b -> Bool
$c> :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p b a) =>
Flip p a b -> Flip p a b -> Bool
<= :: Flip p a b -> Flip p a b -> Bool
$c<= :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p b a) =>
Flip p a b -> Flip p a b -> Bool
< :: Flip p a b -> Flip p a b -> Bool
$c< :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p b a) =>
Flip p a b -> Flip p a b -> Bool
compare :: Flip p a b -> Flip p a b -> Ordering
$ccompare :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p b a) =>
Flip p a b -> Flip p a b -> Ordering
$cp1Ord :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Ord (p b a) =>
Eq (Flip p a b)
Ord, Int -> Flip p a b -> ShowS
[Flip p a b] -> ShowS
Flip p a b -> String
(Int -> Flip p a b -> ShowS)
-> (Flip p a b -> String)
-> ([Flip p a b] -> ShowS)
-> Show (Flip 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 b a) =>
Int -> Flip p a b -> ShowS
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Show (p b a) =>
[Flip p a b] -> ShowS
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Show (p b a) =>
Flip p a b -> String
showList :: [Flip p a b] -> ShowS
$cshowList :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Show (p b a) =>
[Flip p a b] -> ShowS
show :: Flip p a b -> String
$cshow :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Show (p b a) =>
Flip p a b -> String
showsPrec :: Int -> Flip p a b -> ShowS
$cshowsPrec :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Show (p b a) =>
Int -> Flip p a b -> ShowS
Show, ReadPrec [Flip p a b]
ReadPrec (Flip p a b)
Int -> ReadS (Flip p a b)
ReadS [Flip p a b]
(Int -> ReadS (Flip p a b))
-> ReadS [Flip p a b]
-> ReadPrec (Flip p a b)
-> ReadPrec [Flip p a b]
-> Read (Flip 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 b a) =>
ReadPrec [Flip p a b]
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p b a) =>
ReadPrec (Flip p a b)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p b a) =>
Int -> ReadS (Flip p a b)
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p b a) =>
ReadS [Flip p a b]
readListPrec :: ReadPrec [Flip p a b]
$creadListPrec :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p b a) =>
ReadPrec [Flip p a b]
readPrec :: ReadPrec (Flip p a b)
$creadPrec :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p b a) =>
ReadPrec (Flip p a b)
readList :: ReadS [Flip p a b]
$creadList :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p b a) =>
ReadS [Flip p a b]
readsPrec :: Int -> ReadS (Flip p a b)
$creadsPrec :: forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Read (p b a) =>
Int -> ReadS (Flip p a b)
Read
#if __GLASGOW_HASKELL__ >= 702
, (forall x. Flip p a b -> Rep (Flip p a b) x)
-> (forall x. Rep (Flip p a b) x -> Flip p a b)
-> Generic (Flip p a b)
forall x. Rep (Flip p a b) x -> Flip p a b
forall x. Flip p a b -> Rep (Flip 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 (Flip p a b) x -> Flip p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k) x.
Flip p a b -> Rep (Flip p a b) x
$cto :: forall k k (p :: k -> k -> *) (a :: k) (b :: k) x.
Rep (Flip p a b) x -> Flip p a b
$cfrom :: forall k k (p :: k -> k -> *) (a :: k) (b :: k) x.
Flip p a b -> Rep (Flip p a b) x
Generic
#endif
#if __GLASGOW_HASKELL__ >= 708
, Typeable
#endif
)
#if LIFTED_FUNCTOR_CLASSES
instance (Eq2 p, Eq a) => Eq1 (Flip p a) where
liftEq :: (a -> b -> Bool) -> Flip p a a -> Flip p a b -> Bool
liftEq = (a -> a -> Bool)
-> (a -> b -> Bool) -> Flip p a a -> Flip 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 (Flip p) where
liftEq2 :: (a -> b -> Bool)
-> (c -> d -> Bool) -> Flip p a c -> Flip p b d -> Bool
liftEq2 a -> b -> Bool
f c -> d -> Bool
g (Flip p c a
x) (Flip p d b
y) = (c -> d -> Bool) -> (a -> b -> Bool) -> p c a -> p d b -> Bool
forall (f :: * -> * -> *) a b c d.
Eq2 f =>
(a -> b -> Bool) -> (c -> d -> Bool) -> f a c -> f b d -> Bool
liftEq2 c -> d -> Bool
g a -> b -> Bool
f p c a
x p d b
y
instance (Ord2 p, Ord a) => Ord1 (Flip p a) where
liftCompare :: (a -> b -> Ordering) -> Flip p a a -> Flip p a b -> Ordering
liftCompare = (a -> a -> Ordering)
-> (a -> b -> Ordering) -> Flip p a a -> Flip 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 (Flip p) where
liftCompare2 :: (a -> b -> Ordering)
-> (c -> d -> Ordering) -> Flip p a c -> Flip p b d -> Ordering
liftCompare2 a -> b -> Ordering
f c -> d -> Ordering
g (Flip p c a
x) (Flip p d b
y) = (c -> d -> Ordering)
-> (a -> b -> Ordering) -> p c a -> p d b -> Ordering
forall (f :: * -> * -> *) a b c d.
Ord2 f =>
(a -> b -> Ordering)
-> (c -> d -> Ordering) -> f a c -> f b d -> Ordering
liftCompare2 c -> d -> Ordering
g a -> b -> Ordering
f p c a
x p d b
y
instance (Read2 p, Read a) => Read1 (Flip p a) where
liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Flip p a a)
liftReadsPrec = (Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS a)
-> ReadS [a]
-> Int
-> ReadS (Flip 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 (Flip p) where
liftReadsPrec2 :: (Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS b)
-> ReadS [b]
-> Int
-> ReadS (Flip p a b)
liftReadsPrec2 Int -> ReadS a
rp1 ReadS [a]
rl1 Int -> ReadS b
rp2 ReadS [b]
rl2 Int
p = Bool -> ReadS (Flip p a b) -> ReadS (Flip 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 (Flip p a b) -> ReadS (Flip p a b))
-> ReadS (Flip p a b) -> ReadS (Flip p a b)
forall a b. (a -> b) -> a -> b
$ \String
s0 -> do
(String
"Flip", String
s1) <- ReadS String
lex String
s0
(String
"{", String
s2) <- ReadS String
lex String
s1
(String
"runFlip", String
s3) <- ReadS String
lex String
s2
(p b a
x, String
s4) <- (Int -> ReadS b)
-> ReadS [b]
-> (Int -> ReadS a)
-> ReadS [a]
-> Int
-> ReadS (p b 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 b
rp2 ReadS [b]
rl2 Int -> ReadS a
rp1 ReadS [a]
rl1 Int
0 String
s3
(String
"}", String
s5) <- ReadS String
lex String
s4
(Flip p a b, String) -> [(Flip p a b, String)]
forall (m :: * -> *) a. Monad m => a -> m a
return (p b a -> Flip p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p b a -> Flip p a b
Flip p b a
x, String
s5)
instance (Show2 p, Show a) => Show1 (Flip p a) where
liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Flip p a a -> ShowS
liftShowsPrec = (Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> a -> ShowS)
-> ([a] -> ShowS)
-> Int
-> Flip 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 (Flip p) where
liftShowsPrec2 :: (Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> Flip p a b
-> ShowS
liftShowsPrec2 Int -> a -> ShowS
sp1 [a] -> ShowS
sl1 Int -> b -> ShowS
sp2 [b] -> ShowS
sl2 Int
p (Flip p b a
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
"Flip {runFlip = "
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> (Int -> a -> ShowS)
-> ([a] -> ShowS)
-> Int
-> p b 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 -> b -> ShowS
sp2 [b] -> ShowS
sl2 Int -> a -> ShowS
sp1 [a] -> ShowS
sl1 Int
0 p b a
x
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
'}'
#endif
instance Bifunctor p => Bifunctor (Flip p) where
first :: (a -> b) -> Flip p a c -> Flip p b c
first a -> b
f = p c b -> Flip p b c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p b a -> Flip p a b
Flip (p c b -> Flip p b c)
-> (Flip p a c -> p c b) -> Flip p a c -> Flip p b c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> p c a -> p c b
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second a -> b
f (p c a -> p c b) -> (Flip p a c -> p c a) -> Flip p a c -> p c b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Flip p a c -> p c a
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Flip p a b -> p b a
runFlip
{-# INLINE first #-}
second :: (b -> c) -> Flip p a b -> Flip p a c
second b -> c
f = p c a -> Flip p a c
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p b a -> Flip p a b
Flip (p c a -> Flip p a c)
-> (Flip p a b -> p c a) -> Flip p a b -> Flip p a c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> c) -> p b a -> p c a
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first b -> c
f (p b a -> p c a) -> (Flip p a b -> p b a) -> Flip p a b -> p c a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Flip p a b -> p b a
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Flip p a b -> p b a
runFlip
{-# INLINE second #-}
bimap :: (a -> b) -> (c -> d) -> Flip p a c -> Flip p b d
bimap a -> b
f c -> d
g = p d b -> Flip p b d
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p b a -> Flip p a b
Flip (p d b -> Flip p b d)
-> (Flip p a c -> p d b) -> Flip p a c -> Flip p b d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> d) -> (a -> b) -> p c a -> p d b
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap c -> d
g a -> b
f (p c a -> p d b) -> (Flip p a c -> p c a) -> Flip p a c -> p d b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Flip p a c -> p c a
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Flip p a b -> p b a
runFlip
{-# INLINE bimap #-}
instance Bifunctor p => Functor (Flip p a) where
fmap :: (a -> b) -> Flip p a a -> Flip p a b
fmap a -> b
f = p b a -> Flip p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p b a -> Flip p a b
Flip (p b a -> Flip p a b)
-> (Flip p a a -> p b a) -> Flip p a a -> Flip p a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> p a a -> p b a
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
f (p a a -> p b a) -> (Flip p a a -> p a a) -> Flip p a a -> p b a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Flip p a a -> p a a
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Flip p a b -> p b a
runFlip
{-# INLINE fmap #-}
instance Biapplicative p => Biapplicative (Flip p) where
bipure :: a -> b -> Flip p a b
bipure a
a b
b = p b a -> Flip p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p b a -> Flip p a b
Flip (b -> a -> p b a
forall (p :: * -> * -> *) a b. Biapplicative p => a -> b -> p a b
bipure b
b a
a)
{-# INLINE bipure #-}
Flip p (c -> d) (a -> b)
fg <<*>> :: Flip p (a -> b) (c -> d) -> Flip p a c -> Flip p b d
<<*>> Flip p c a
xy = p d b -> Flip p b d
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p b a -> Flip p a b
Flip (p (c -> d) (a -> b)
fg p (c -> d) (a -> b) -> p c a -> p d b
forall (p :: * -> * -> *) a b c d.
Biapplicative p =>
p (a -> b) (c -> d) -> p a c -> p b d
<<*>> p c a
xy)
{-# INLINE (<<*>>) #-}
instance Bifoldable p => Bifoldable (Flip p) where
bifoldMap :: (a -> m) -> (b -> m) -> Flip p a b -> m
bifoldMap a -> m
f b -> m
g = (b -> m) -> (a -> m) -> p b a -> m
forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap b -> m
g a -> m
f (p b a -> m) -> (Flip p a b -> p b a) -> Flip p a b -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Flip p a b -> p b a
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Flip p a b -> p b a
runFlip
{-# INLINE bifoldMap #-}
instance Bifoldable p => Foldable (Flip p a) where
foldMap :: (a -> m) -> Flip 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 a -> m
f (m -> a -> m
forall a b. a -> b -> a
const m
forall a. Monoid a => a
mempty) (p a a -> m) -> (Flip p a a -> p a a) -> Flip p a a -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Flip p a a -> p a a
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Flip p a b -> p b a
runFlip
{-# INLINE foldMap #-}
instance Bitraversable p => Bitraversable (Flip p) where
bitraverse :: (a -> f c) -> (b -> f d) -> Flip p a b -> f (Flip p c d)
bitraverse a -> f c
f b -> f d
g = (p d c -> Flip p c d) -> f (p d c) -> f (Flip p c d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap p d c -> Flip p c d
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p b a -> Flip p a b
Flip (f (p d c) -> f (Flip p c d))
-> (Flip p a b -> f (p d c)) -> Flip p a b -> f (Flip p c d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> f d) -> (a -> f c) -> p b a -> f (p d 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 b -> f d
g a -> f c
f (p b a -> f (p d c))
-> (Flip p a b -> p b a) -> Flip p a b -> f (p d c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Flip p a b -> p b a
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Flip p a b -> p b a
runFlip
{-# INLINE bitraverse #-}
instance Bitraversable p => Traversable (Flip p a) where
traverse :: (a -> f b) -> Flip p a a -> f (Flip p a b)
traverse a -> f b
f = (p b a -> Flip p a b) -> f (p b a) -> f (Flip p a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap p b a -> Flip p a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p b a -> Flip p a b
Flip (f (p b a) -> f (Flip p a b))
-> (Flip p a a -> f (p b a)) -> Flip p a a -> f (Flip p a b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f b) -> (a -> f a) -> p a a -> f (p b a)
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 b
f a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (p a a -> f (p b a))
-> (Flip p a a -> p a a) -> Flip p a a -> f (p b a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Flip p a a -> p a a
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
Flip p a b -> p b a
runFlip
{-# INLINE traverse #-}
instance BifunctorFunctor Flip where
bifmap :: (p :-> q) -> Flip p :-> Flip q
bifmap p :-> q
f (Flip p b a
p) = q b a -> Flip q a b
forall k k (p :: k -> k -> *) (a :: k) (b :: k).
p b a -> Flip p a b
Flip (p b a -> q b a
p :-> q
f p b a
p)