{-# LANGUAGE CPP #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Data.Profunctor.Unsafe
(
Profunctor(..)
) where
import Control.Arrow
import Control.Category
import Control.Comonad (Cokleisli(..))
import Control.Monad (liftM)
import Data.Bifunctor.Biff (Biff(..))
import Data.Bifunctor.Clown (Clown(..))
import Data.Bifunctor.Joker (Joker(..))
import Data.Bifunctor.Product (Product(..))
import Data.Bifunctor.Sum (Sum(..))
import Data.Bifunctor.Tannen (Tannen(..))
import Data.Coerce (Coercible, coerce)
#if __GLASGOW_HASKELL__ < 710
import Data.Functor
#endif
import Data.Functor.Contravariant (Contravariant(..))
import Data.Tagged
import Prelude hiding (id,(.))
infixr 9 #.
infixl 8 .#
class Profunctor p where
dimap :: (a -> b) -> (c -> d) -> p b c -> p a d
dimap a -> b
f c -> d
g = (a -> b) -> p b d -> p a d
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap a -> b
f (p b d -> p a d) -> (p b c -> p b d) -> p b c -> p a d
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (c -> d) -> p b c -> p b d
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap c -> d
g
{-# INLINE dimap #-}
lmap :: (a -> b) -> p b c -> p a c
lmap a -> b
f = (a -> b) -> (c -> c) -> p b c -> p a c
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap a -> b
f c -> c
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
{-# INLINE lmap #-}
rmap :: (b -> c) -> p a b -> p a c
rmap = (a -> a) -> (b -> c) -> p a b -> p a c
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap a -> a
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
{-# INLINE rmap #-}
(#.) :: forall a b c q. Coercible c b => q b c -> p a b -> p a c
(#.) = \q b c
_ -> \p a b
p -> p a b
p p a b -> p a c -> p a c
`seq` (b -> c) -> p a b -> p a c
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap ((c -> c) -> b -> c
coerce (c -> c
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id :: c -> c) :: b -> c) p a b
p
{-# INLINE (#.) #-}
(.#) :: forall a b c q. Coercible b a => p b c -> q a b -> p a c
(.#) = \p b c
p -> p b c
p p b c -> (q a b -> p a c) -> q a b -> p a c
`seq` \q a b
_ -> (a -> b) -> p b c -> p a c
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap ((b -> b) -> a -> b
coerce (b -> b
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id :: b -> b) :: a -> b) p b c
p
{-# INLINE (.#) #-}
{-# MINIMAL dimap | (lmap, rmap) #-}
instance Profunctor (->) where
dimap :: (a -> b) -> (c -> d) -> (b -> c) -> a -> d
dimap a -> b
ab c -> d
cd b -> c
bc = c -> d
cd (c -> d) -> (a -> c) -> a -> d
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. b -> c
bc (b -> c) -> (a -> b) -> a -> c
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. a -> b
ab
{-# INLINE dimap #-}
lmap :: (a -> b) -> (b -> c) -> a -> c
lmap = ((b -> c) -> (a -> b) -> a -> c) -> (a -> b) -> (b -> c) -> a -> c
forall a b c. (a -> b -> c) -> b -> a -> c
flip (b -> c) -> (a -> b) -> a -> c
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
(.)
{-# INLINE lmap #-}
rmap :: (b -> c) -> (a -> b) -> a -> c
rmap = (b -> c) -> (a -> b) -> a -> c
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
(.)
{-# INLINE rmap #-}
#. :: q b c -> (a -> b) -> a -> c
(#.) q b c
_ = (b -> b) -> a -> b
coerce (\b
x -> b
x :: b) :: forall a b. Coercible b a => a -> b
.# :: (b -> c) -> q a b -> a -> c
(.#) b -> c
pbc q a b
_ = (b -> c) -> a -> c
coerce b -> c
pbc
{-# INLINE (#.) #-}
{-# INLINE (.#) #-}
instance Profunctor Tagged where
dimap :: (a -> b) -> (c -> d) -> Tagged b c -> Tagged a d
dimap a -> b
_ c -> d
f (Tagged c
s) = d -> Tagged a d
forall k (s :: k) b. b -> Tagged s b
Tagged (c -> d
f c
s)
{-# INLINE dimap #-}
lmap :: (a -> b) -> Tagged b c -> Tagged a c
lmap a -> b
_ = Tagged b c -> Tagged a c
forall k1 k2 (s :: k1) b (t :: k2). Tagged s b -> Tagged t b
retag
{-# INLINE lmap #-}
rmap :: (b -> c) -> Tagged a b -> Tagged a c
rmap = (b -> c) -> Tagged a b -> Tagged a c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
{-# INLINE rmap #-}
#. :: q b c -> Tagged a b -> Tagged a c
(#.) q b c
_ = (b -> b) -> a -> b
coerce (\b
x -> b
x :: b) :: forall a b. Coercible b a => a -> b
{-# INLINE (#.) #-}
Tagged c
s .# :: Tagged b c -> q a b -> Tagged a c
.# q a b
_ = c -> Tagged a c
forall k (s :: k) b. b -> Tagged s b
Tagged c
s
{-# INLINE (.#) #-}
instance Monad m => Profunctor (Kleisli m) where
dimap :: (a -> b) -> (c -> d) -> Kleisli m b c -> Kleisli m a d
dimap a -> b
f c -> d
g (Kleisli b -> m c
h) = (a -> m d) -> Kleisli m a d
forall (m :: * -> *) a b. (a -> m b) -> Kleisli m a b
Kleisli ((c -> d) -> m c -> m d
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM c -> d
g (m c -> m d) -> (a -> m c) -> a -> m d
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. b -> m c
h (b -> m c) -> (a -> b) -> a -> m c
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. a -> b
f)
{-# INLINE dimap #-}
lmap :: (a -> b) -> Kleisli m b c -> Kleisli m a c
lmap a -> b
k (Kleisli b -> m c
f) = (a -> m c) -> Kleisli m a c
forall (m :: * -> *) a b. (a -> m b) -> Kleisli m a b
Kleisli (b -> m c
f (b -> m c) -> (a -> b) -> a -> m c
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. a -> b
k)
{-# INLINE lmap #-}
rmap :: (b -> c) -> Kleisli m a b -> Kleisli m a c
rmap b -> c
k (Kleisli a -> m b
f) = (a -> m c) -> Kleisli m a c
forall (m :: * -> *) a b. (a -> m b) -> Kleisli m a b
Kleisli ((b -> c) -> m b -> m c
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM b -> c
k (m b -> m c) -> (a -> m b) -> a -> m c
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. a -> m b
f)
{-# INLINE rmap #-}
.# :: Kleisli m b c -> q a b -> Kleisli m a c
(.#) Kleisli m b c
pbc q a b
_ = Kleisli m b c -> Kleisli m a c
coerce Kleisli m b c
pbc
{-# INLINE (.#) #-}
instance Functor w => Profunctor (Cokleisli w) where
dimap :: (a -> b) -> (c -> d) -> Cokleisli w b c -> Cokleisli w a d
dimap a -> b
f c -> d
g (Cokleisli w b -> c
h) = (w a -> d) -> Cokleisli w a d
forall k (w :: k -> *) (a :: k) b. (w a -> b) -> Cokleisli w a b
Cokleisli (c -> d
g (c -> d) -> (w a -> c) -> w a -> d
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. w b -> c
h (w b -> c) -> (w a -> w b) -> w a -> c
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (a -> b) -> w a -> w b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f)
{-# INLINE dimap #-}
lmap :: (a -> b) -> Cokleisli w b c -> Cokleisli w a c
lmap a -> b
k (Cokleisli w b -> c
f) = (w a -> c) -> Cokleisli w a c
forall k (w :: k -> *) (a :: k) b. (w a -> b) -> Cokleisli w a b
Cokleisli (w b -> c
f (w b -> c) -> (w a -> w b) -> w a -> c
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (a -> b) -> w a -> w b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
k)
{-# INLINE lmap #-}
rmap :: (b -> c) -> Cokleisli w a b -> Cokleisli w a c
rmap b -> c
k (Cokleisli w a -> b
f) = (w a -> c) -> Cokleisli w a c
forall k (w :: k -> *) (a :: k) b. (w a -> b) -> Cokleisli w a b
Cokleisli (b -> c
k (b -> c) -> (w a -> b) -> w a -> c
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. w a -> b
f)
{-# INLINE rmap #-}
#. :: q b c -> Cokleisli w a b -> Cokleisli w a c
(#.) q b c
_ = (b -> b) -> a -> b
coerce (\b
x -> b
x :: b) :: forall a b. Coercible b a => a -> b
{-# INLINE (#.) #-}
instance Contravariant f => Profunctor (Clown f) where
lmap :: (a -> b) -> Clown f b c -> Clown f a c
lmap a -> b
f (Clown f b
fa) = f a -> Clown f a c
forall k k1 (f :: k -> *) (a :: k) (b :: k1). f a -> Clown f a b
Clown ((a -> b) -> f b -> f a
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
contramap a -> b
f f b
fa)
{-# INLINE lmap #-}
rmap :: (b -> c) -> Clown f a b -> Clown f a c
rmap b -> c
_ (Clown f a
fa) = f a -> Clown f a c
forall k k1 (f :: k -> *) (a :: k) (b :: k1). f a -> Clown f a b
Clown f a
fa
{-# INLINE rmap #-}
dimap :: (a -> b) -> (c -> d) -> Clown f b c -> Clown f a d
dimap a -> b
f c -> d
_ (Clown f b
fa) = f a -> Clown f a d
forall k k1 (f :: k -> *) (a :: k) (b :: k1). f a -> Clown f a b
Clown ((a -> b) -> f b -> f a
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
contramap a -> b
f f b
fa)
{-# INLINE dimap #-}
instance Functor f => Profunctor (Joker f) where
lmap :: (a -> b) -> Joker f b c -> Joker f a c
lmap a -> b
_ (Joker f c
fb) = f c -> Joker f a c
forall k k1 (g :: k -> *) (a :: k1) (b :: k). g b -> Joker g a b
Joker f c
fb
{-# INLINE lmap #-}
rmap :: (b -> c) -> Joker f a b -> Joker f a c
rmap b -> c
g (Joker f b
fb) = f c -> Joker f a c
forall k k1 (g :: k -> *) (a :: k1) (b :: k). g b -> Joker g a b
Joker ((b -> c) -> f b -> f c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> c
g f b
fb)
{-# INLINE rmap #-}
dimap :: (a -> b) -> (c -> d) -> Joker f b c -> Joker f a d
dimap a -> b
_ c -> d
g (Joker f c
fb) = f d -> Joker f a d
forall k k1 (g :: k -> *) (a :: k1) (b :: k). g b -> Joker g a b
Joker ((c -> d) -> f c -> f d
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap c -> d
g f c
fb)
{-# INLINE dimap #-}
instance (Profunctor p, Functor f, Functor g) => Profunctor (Biff p f g) where
lmap :: (a -> b) -> Biff p f g b c -> Biff p f g a c
lmap a -> b
f (Biff p (f b) (g c)
p) = p (f a) (g c) -> Biff p f g a c
forall k k1 k2 k3 (p :: k -> k1 -> *) (f :: k2 -> k)
(g :: k3 -> k1) (a :: k2) (b :: k3).
p (f a) (g b) -> Biff p f g a b
Biff ((f a -> f b) -> p (f b) (g c) -> p (f a) (g c)
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap ((a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) p (f b) (g c)
p)
rmap :: (b -> c) -> Biff p f g a b -> Biff p f g a c
rmap b -> c
g (Biff p (f a) (g b)
p) = p (f a) (g c) -> Biff p f g a c
forall k k1 k2 k3 (p :: k -> k1 -> *) (f :: k2 -> k)
(g :: k3 -> k1) (a :: k2) (b :: k3).
p (f a) (g b) -> Biff p f g a b
Biff ((g b -> g c) -> p (f a) (g b) -> p (f a) (g c)
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap ((b -> c) -> g b -> g c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> c
g) p (f a) (g b)
p)
dimap :: (a -> b) -> (c -> d) -> Biff p f g b c -> Biff p f g a d
dimap a -> b
f c -> d
g (Biff p (f b) (g c)
p) = p (f a) (g d) -> Biff p f g a d
forall k k1 k2 k3 (p :: k -> k1 -> *) (f :: k2 -> k)
(g :: k3 -> k1) (a :: k2) (b :: k3).
p (f a) (g b) -> Biff p f g a b
Biff ((f a -> f b) -> (g c -> g d) -> p (f b) (g c) -> p (f a) (g d)
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap ((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 b) (g c)
p)
instance (Profunctor p, Profunctor q) => Profunctor (Product p q) where
lmap :: (a -> b) -> Product p q b c -> Product p q a c
lmap a -> b
f (Pair p b c
p q b c
q) = p a c -> q a c -> Product p q a c
forall k k1 (f :: k -> k1 -> *) (g :: k -> k1 -> *) (a :: k)
(b :: k1).
f a b -> g a b -> Product f g a b
Pair ((a -> b) -> p b c -> p a c
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap a -> b
f p b c
p) ((a -> b) -> q b c -> q a c
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap a -> b
f q b c
q)
{-# INLINE lmap #-}
rmap :: (b -> c) -> Product p q a b -> Product p q a c
rmap b -> c
g (Pair p a b
p q a b
q) = p a c -> q a c -> Product p q a c
forall k k1 (f :: k -> k1 -> *) (g :: k -> k1 -> *) (a :: k)
(b :: k1).
f a b -> g a b -> Product f g a b
Pair ((b -> c) -> p a b -> p a c
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap b -> c
g p a b
p) ((b -> c) -> q a b -> q a c
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap b -> c
g q a b
q)
{-# INLINE rmap #-}
dimap :: (a -> b) -> (c -> d) -> Product p q b c -> Product p q a d
dimap a -> b
f c -> d
g (Pair p b c
p q b c
q) = p a d -> q a d -> Product p q a d
forall k k1 (f :: k -> k1 -> *) (g :: k -> k1 -> *) (a :: k)
(b :: k1).
f a b -> g a b -> Product f g a b
Pair ((a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap a -> b
f c -> d
g p b c
p) ((a -> b) -> (c -> d) -> q b c -> q a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap a -> b
f c -> d
g q b c
q)
{-# INLINE dimap #-}
#. :: q b c -> Product p q a b -> Product p q a c
(#.) q b c
f (Pair p a b
p q a b
q) = p a c -> q a c -> Product p q a c
forall k k1 (f :: k -> k1 -> *) (g :: k -> k1 -> *) (a :: k)
(b :: k1).
f a b -> g a b -> Product f g a b
Pair (q b c
f q b c -> p a b -> p a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. p a b
p) (q b c
f q b c -> q a b -> q a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. q a b
q)
{-# INLINE (#.) #-}
.# :: Product p q b c -> q a b -> Product p q a c
(.#) (Pair p b c
p q b c
q) q a b
f = p a c -> q a c -> Product p q a c
forall k k1 (f :: k -> k1 -> *) (g :: k -> k1 -> *) (a :: k)
(b :: k1).
f a b -> g a b -> Product f g a b
Pair (p b c
p p b c -> q a b -> p a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# q a b
f) (q b c
q q b c -> q a b -> q a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# q a b
f)
{-# INLINE (.#) #-}
instance (Profunctor p, Profunctor q) => Profunctor (Sum p q) where
lmap :: (a -> b) -> Sum p q b c -> Sum p q a c
lmap a -> b
f (L2 p b c
x) = p a c -> Sum p q a c
forall k k1 (p :: k -> k1 -> *) (q :: k -> k1 -> *) (a :: k)
(b :: k1).
p a b -> Sum p q a b
L2 ((a -> b) -> p b c -> p a c
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap a -> b
f p b c
x)
lmap a -> b
f (R2 q b c
y) = q a c -> Sum p q a c
forall k k1 (p :: k -> k1 -> *) (q :: k -> k1 -> *) (a :: k)
(b :: k1).
q a b -> Sum p q a b
R2 ((a -> b) -> q b c -> q a c
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap a -> b
f q b c
y)
{-# INLINE lmap #-}
rmap :: (b -> c) -> Sum p q a b -> Sum p q a c
rmap b -> c
g (L2 p a b
x) = p a c -> Sum p q a c
forall k k1 (p :: k -> k1 -> *) (q :: k -> k1 -> *) (a :: k)
(b :: k1).
p a b -> Sum p q a b
L2 ((b -> c) -> p a b -> p a c
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap b -> c
g p a b
x)
rmap b -> c
g (R2 q a b
y) = q a c -> Sum p q a c
forall k k1 (p :: k -> k1 -> *) (q :: k -> k1 -> *) (a :: k)
(b :: k1).
q a b -> Sum p q a b
R2 ((b -> c) -> q a b -> q a c
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap b -> c
g q a b
y)
{-# INLINE rmap #-}
dimap :: (a -> b) -> (c -> d) -> Sum p q b c -> Sum p q a d
dimap a -> b
f c -> d
g (L2 p b c
x) = p a d -> Sum p q a d
forall k k1 (p :: k -> k1 -> *) (q :: k -> k1 -> *) (a :: k)
(b :: k1).
p a b -> Sum p q a b
L2 ((a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap a -> b
f c -> d
g p b c
x)
dimap a -> b
f c -> d
g (R2 q b c
y) = q a d -> Sum p q a d
forall k k1 (p :: k -> k1 -> *) (q :: k -> k1 -> *) (a :: k)
(b :: k1).
q a b -> Sum p q a b
R2 ((a -> b) -> (c -> d) -> q b c -> q a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap a -> b
f c -> d
g q b c
y)
{-# INLINE dimap #-}
q b c
f #. :: q b c -> Sum p q a b -> Sum p q a c
#. L2 p a b
x = p a c -> Sum p q a c
forall k k1 (p :: k -> k1 -> *) (q :: k -> k1 -> *) (a :: k)
(b :: k1).
p a b -> Sum p q a b
L2 (q b c
f q b c -> p a b -> p a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. p a b
x)
q b c
f #. R2 q a b
y = q a c -> Sum p q a c
forall k k1 (p :: k -> k1 -> *) (q :: k -> k1 -> *) (a :: k)
(b :: k1).
q a b -> Sum p q a b
R2 (q b c
f q b c -> q a b -> q a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. q a b
y)
{-# INLINE (#.) #-}
L2 p b c
x .# :: Sum p q b c -> q a b -> Sum p q a c
.# q a b
f = p a c -> Sum p q a c
forall k k1 (p :: k -> k1 -> *) (q :: k -> k1 -> *) (a :: k)
(b :: k1).
p a b -> Sum p q a b
L2 (p b c
x p b c -> q a b -> p a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# q a b
f)
R2 q b c
y .# q a b
f = q a c -> Sum p q a c
forall k k1 (p :: k -> k1 -> *) (q :: k -> k1 -> *) (a :: k)
(b :: k1).
q a b -> Sum p q a b
R2 (q b c
y q b c -> q a b -> q a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# q a b
f)
{-# INLINE (.#) #-}
instance (Functor f, Profunctor p) => Profunctor (Tannen f p) where
lmap :: (a -> b) -> Tannen f p b c -> Tannen f p a c
lmap a -> b
f (Tannen f (p b c)
h) = f (p a c) -> Tannen f p a c
forall k k1 k2 (f :: k -> *) (p :: k1 -> k2 -> k) (a :: k1)
(b :: k2).
f (p a b) -> Tannen f p a b
Tannen ((a -> b) -> p b c -> p a c
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap a -> b
f (p b c -> p a c) -> f (p b c) -> f (p a c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (p b c)
h)
{-# INLINE lmap #-}
rmap :: (b -> c) -> Tannen f p a b -> Tannen f p a c
rmap b -> c
g (Tannen f (p a b)
h) = f (p a c) -> Tannen f p a c
forall k k1 k2 (f :: k -> *) (p :: k1 -> k2 -> k) (a :: k1)
(b :: k2).
f (p a b) -> Tannen f p a b
Tannen ((b -> c) -> p a b -> p a c
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap b -> c
g (p a b -> p a c) -> f (p a b) -> f (p a c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (p a b)
h)
{-# INLINE rmap #-}
dimap :: (a -> b) -> (c -> d) -> Tannen f p b c -> Tannen f p a d
dimap a -> b
f c -> d
g (Tannen f (p b c)
h) = f (p a d) -> Tannen f p a d
forall k k1 k2 (f :: k -> *) (p :: k1 -> k2 -> k) (a :: k1)
(b :: k2).
f (p a b) -> Tannen f p a b
Tannen ((a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap a -> b
f c -> d
g (p b c -> p a d) -> f (p b c) -> f (p a d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (p b c)
h)
{-# INLINE dimap #-}
#. :: q b c -> Tannen f p a b -> Tannen f p a c
(#.) q b c
f (Tannen f (p a b)
h) = f (p a c) -> Tannen f p a c
forall k k1 k2 (f :: k -> *) (p :: k1 -> k2 -> k) (a :: k1)
(b :: k2).
f (p a b) -> Tannen f p a b
Tannen ((q b c
f q b c -> p a b -> p a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#.) (p a b -> p a c) -> f (p a b) -> f (p a c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (p a b)
h)
{-# INLINE (#.) #-}
.# :: Tannen f p b c -> q a b -> Tannen f p a c
(.#) (Tannen f (p b c)
h) q a b
f = f (p a c) -> Tannen f p a c
forall k k1 k2 (f :: k -> *) (p :: k1 -> k2 -> k) (a :: k1)
(b :: k2).
f (p a b) -> Tannen f p a b
Tannen ((p b c -> q a b -> p a c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# q a b
f) (p b c -> p a c) -> f (p b c) -> f (p a c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (p b c)
h)
{-# INLINE (.#) #-}