{-# LANGUAGE AllowAmbiguousTypes #-}

-- | Kan extensions and lifts as squares. Pointwise constructions have only
-- horizontal functor wires; corepresentable encodings use 'CorepStar'. Their
-- pointwiseness is supplied by the underlying profunctor universal properties.
module Proarrow.Squares.Kan where

import Proarrow.Category.Instance.Prof (Prof (..))
import Proarrow.Core (Profunctor, Promonad (..), (//), (:~>))
import Proarrow.Path (Path (..))
import Proarrow.Profunctor.Corepresentable (Corepresentable (..))
import Proarrow.Profunctor.Instance.Composition ((:.:) (..))
import Proarrow.Profunctor.Instance.Ran qualified as R
import Proarrow.Profunctor.Instance.Rift qualified as L
import Proarrow.Profunctor.Representable (CorepStar (..), Representable (..), mapCorepStar)
import Proarrow.Squares (Sq (..), fromBottom, mapSq, (===))

-- | Evaluate a profunctor right Kan extension. All three wires are vertical.
--
-- > K---r---j---I
-- > |   \   /   |
-- > |     @     |
-- > |     |     |
-- > K-----p-----I
ran :: (Profunctor j, Profunctor p) => Sq (j ::: j R.|> p ::: Nil) (p ::: Nil) Nil Nil
ran :: forall {k :: Kind} {j :: Kind} {i :: Kind} (j :: k +-> j)
       (p :: k +-> i).
(Profunctor j, Profunctor p) =>
Sq (j ::: ((j |> p) ::: Nil)) (p ::: Nil) Nil Nil
ran = (Fold ((j ::: ((j |> p) ::: Nil)) +++ Nil)
 :~> Fold (Nil +++ (p ::: Nil)))
-> Sq (j ::: ((j |> p) ::: Nil)) (p ::: Nil) Nil Nil
forall {j :: Kind} {h :: Kind} {k :: Kind} {i :: Kind}
       (p :: Path j h) (q :: Path k i) (f :: Path h i) (g :: Path j k).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq (Prof ((j |> p) :.: j) p -> ((j |> p) :.: j) :~> p
forall {k1 :: Kind} {k :: Kind} (p :: k1 +-> k) (q :: k1 +-> k).
Prof p q -> p :~> q
unProf ((j |> p) :.: j) ~> p
Prof ((j |> p) :.: j) p
forall {i :: Kind} {j1 :: Kind} {k :: Kind} (j2 :: i +-> j1)
       (p :: i +-> k).
(Profunctor j2, Profunctor p) =>
((j2 |> p) :.: j2) ~> p
R.runRanProf)

-- | Factor a square through the right Kan extension.
--
-- The dotted inner square is the input; the solid outer square is the result.
--
-- > K-------g-----------A
-- > |       |           |
-- > |   K...+...j...I   |
-- > |   :   \   /   :   |
-- > |   :     @     :   |
-- > |   :     |     :   |
-- > |   K.....p.....I   |
-- > |                   |
-- > K---------r---------A
--
-- Here @r = j |> p@.
ranUniv
  :: (Profunctor j, Profunctor p, Profunctor g)
  => Sq (j ::: g ::: Nil) (p ::: Nil) Nil Nil
  -> Sq (g ::: Nil) (j R.|> p ::: Nil) Nil Nil
ranUniv :: forall {i :: Kind} {k :: Kind} {i :: Kind} (j :: i +-> k)
       (p :: i +-> i) (g :: k +-> i).
(Profunctor j, Profunctor p, Profunctor g) =>
Sq (j ::: (g ::: Nil)) (p ::: Nil) Nil Nil
-> Sq (g ::: Nil) ((j |> p) ::: Nil) Nil Nil
ranUniv = ((Fold ((j ::: (g ::: Nil)) +++ Nil) ~> Fold (Nil +++ (p ::: Nil)))
 -> Fold ((g ::: Nil) +++ Nil) ~> Fold (Nil +++ ((j |> p) ::: Nil)))
-> Sq (j ::: (g ::: Nil)) (p ::: Nil) Nil Nil
-> Sq (g ::: Nil) ((j |> p) ::: Nil) Nil Nil
forall {j1 :: Kind} {h1 :: Kind} {i1 :: Kind} {k1 :: Kind}
       {j2 :: Kind} {h2 :: Kind} {k2 :: Kind} {i2 :: Kind}
       (ps :: Path j1 h1) (fs :: Path h1 i1) (gs :: Path j1 k1)
       (qs :: Path k1 i1) (ps' :: Path j2 h2) (qs' :: Path k2 i2)
       (fs' :: Path h2 i2) (gs' :: Path j2 k2).
(Profunctor (Fold (ps +++ fs)), Profunctor (Fold (gs +++ qs)),
 IsPath ps', IsPath qs', IsTight fs', IsTight gs') =>
((Fold (ps +++ fs) ~> Fold (gs +++ qs))
 -> Fold (ps' +++ fs') ~> Fold (gs' +++ qs'))
-> Sq ps qs fs gs -> Sq ps' qs' fs' gs'
mapSq ((g :.: j) ~> p) -> g ~> (j |> p)
(Fold ((j ::: (g ::: Nil)) +++ Nil) ~> Fold (Nil +++ (p ::: Nil)))
-> Fold ((g ::: Nil) +++ Nil) ~> Fold (Nil +++ ((j |> p) ::: Nil))
forall {i :: Kind} {j1 :: Kind} {k :: Kind} (j2 :: i +-> j1)
       (g :: j1 +-> k) (p :: k -> i -> Kind).
(Profunctor j2, Profunctor g) =>
((g :.: j2) ~> p) -> g ~> (j2 |> p)
R.ranUniv

-- | Evaluate a profunctor right Kan lift.
--
-- > I---j---r---K
-- > |   \   /   |
-- > |     @     |
-- > |     |     |
-- > I-----p-----K
rift :: (Profunctor j, Profunctor p) => Sq (p L.<| j ::: j ::: Nil) (p ::: Nil) Nil Nil
rift :: forall {j :: Kind} {i :: Kind} {k :: Kind} (j :: j +-> i)
       (p :: k +-> i).
(Profunctor j, Profunctor p) =>
Sq ((p <| j) ::: (j ::: Nil)) (p ::: Nil) Nil Nil
rift = (Fold (((p <| j) ::: (j ::: Nil)) +++ Nil)
 :~> Fold (Nil +++ (p ::: Nil)))
-> Sq ((p <| j) ::: (j ::: Nil)) (p ::: Nil) Nil Nil
forall {j :: Kind} {h :: Kind} {k :: Kind} {i :: Kind}
       (p :: Path j h) (q :: Path k i) (f :: Path h i) (g :: Path j k).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq (Prof (j :.: (p <| j)) p -> (j :.: (p <| j)) :~> p
forall {k1 :: Kind} {k :: Kind} (p :: k1 +-> k) (q :: k1 +-> k).
Prof p q -> p :~> q
unProf (j :.: (p <| j)) ~> p
Prof (j :.: (p <| j)) p
forall {k :: Kind} {i1 :: Kind} {i2 :: Kind} (j :: k +-> i1)
       (p :: i2 +-> i1).
(Profunctor j, Profunctor p) =>
(j :.: (p <| j)) ~> p
L.runRiftProf)

-- | Factor a square through the right Kan lift.
--
-- The dotted inner square is the input; the solid outer square is the result.
--
-- > A-----------g-------K
-- > |           |       |
-- > |   I...j...+...K   |
-- > |   :   \   /   :   |
-- > |   :     @     :   |
-- > |   :     |     :   |
-- > |   I.....p.....K   |
-- > |                   |
-- > A---------r---------K
--
-- Here @r = p <| j@.
riftUniv
  :: (Profunctor j, Profunctor p, Profunctor g)
  => Sq (g ::: j ::: Nil) (p ::: Nil) Nil Nil
  -> Sq (g ::: Nil) (p L.<| j ::: Nil) Nil Nil
riftUniv :: forall {i :: Kind} {i :: Kind} {k :: Kind} (j :: i +-> i)
       (p :: k +-> i) (g :: k +-> i).
(Profunctor j, Profunctor p, Profunctor g) =>
Sq (g ::: (j ::: Nil)) (p ::: Nil) Nil Nil
-> Sq (g ::: Nil) ((p <| j) ::: Nil) Nil Nil
riftUniv = ((Fold ((g ::: (j ::: Nil)) +++ Nil) ~> Fold (Nil +++ (p ::: Nil)))
 -> Fold ((g ::: Nil) +++ Nil) ~> Fold (Nil +++ ((p <| j) ::: Nil)))
-> Sq (g ::: (j ::: Nil)) (p ::: Nil) Nil Nil
-> Sq (g ::: Nil) ((p <| j) ::: Nil) Nil Nil
forall {j1 :: Kind} {h1 :: Kind} {i1 :: Kind} {k1 :: Kind}
       {j2 :: Kind} {h2 :: Kind} {k2 :: Kind} {i2 :: Kind}
       (ps :: Path j1 h1) (fs :: Path h1 i1) (gs :: Path j1 k1)
       (qs :: Path k1 i1) (ps' :: Path j2 h2) (qs' :: Path k2 i2)
       (fs' :: Path h2 i2) (gs' :: Path j2 k2).
(Profunctor (Fold (ps +++ fs)), Profunctor (Fold (gs +++ qs)),
 IsPath ps', IsPath qs', IsTight fs', IsTight gs') =>
((Fold (ps +++ fs) ~> Fold (gs +++ qs))
 -> Fold (ps' +++ fs') ~> Fold (gs' +++ qs'))
-> Sq ps qs fs gs -> Sq ps' qs' fs' gs'
mapSq ((j :.: g) ~> p) -> g ~> (p <| j)
(Fold ((g ::: (j ::: Nil)) +++ Nil) ~> Fold (Nil +++ (p ::: Nil)))
-> Fold ((g ::: Nil) +++ Nil) ~> Fold (Nil +++ ((p <| j) ::: Nil))
forall {k :: Kind} {i :: Kind} {j1 :: Kind} (j2 :: k +-> i)
       (g :: j1 +-> k) (p :: i -> j1 -> Kind).
(Profunctor j2, Profunctor g) =>
((j2 :.: g) ~> p) -> g ~> (p <| j2)
L.riftUniv

-- | Pointwise Ran: @r . j => p@, with all three functors horizontal.
--
-- > I-----------I
-- > j>---\      |
-- > |     @---->p
-- > r>---/      |
-- > K-----------K
pwRan :: (R.PointwiseRightKanExtension j p) => Sq Nil Nil (j ::: j R.|> p ::: Nil) (p ::: Nil)
pwRan :: forall {j :: Kind} {j :: Kind} {k :: Kind} (j :: j +-> j)
       (p :: j +-> k).
PointwiseRightKanExtension j p =>
Sq Nil Nil (j ::: ((j |> p) ::: Nil)) (p ::: Nil)
pwRan = (Fold (Nil +++ (j ::: ((j |> p) ::: Nil)))
 :~> Fold ((p ::: Nil) +++ Nil))
-> Sq Nil Nil (j ::: ((j |> p) ::: Nil)) (p ::: Nil)
forall {j :: Kind} {h :: Kind} {k :: Kind} {i :: Kind}
       (p :: Path j h) (q :: Path k i) (f :: Path h i) (g :: Path j k).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq (Prof ((j |> p) :.: j) p -> ((j |> p) :.: j) :~> p
forall {k1 :: Kind} {k :: Kind} (p :: k1 +-> k) (q :: k1 +-> k).
Prof p q -> p :~> q
unProf ((j |> p) :.: j) ~> p
Prof ((j |> p) :.: j) p
forall {i :: Kind} {j1 :: Kind} {k :: Kind} (j2 :: i +-> j1)
       (p :: i +-> k).
(Profunctor j2, Profunctor p) =>
((j2 |> p) :.: j2) ~> p
R.runRanProf)

-- | The universal property of pointwise Ran.
--
-- The dotted inner square is the input; the solid outer square is the result.
--
-- > A-------------------A
-- > |                   |
-- > |   I...........I   |
-- > |   j>---\      :   |
-- > |   :     @---->p   r
-- > g>-------/      :   |
-- > |   K...........K   |
-- > |                   |
-- > K-------------------K
--
-- Here @r = j |> p@.
pwRanUniv
  :: (R.PointwiseRightKanExtension j p, Representable g)
  => Sq Nil Nil (j ::: g ::: Nil) (p ::: Nil)
  -> Sq Nil Nil (g ::: Nil) (j R.|> p ::: Nil)
pwRanUniv :: forall {i :: Kind} {j :: Kind} {k :: Kind} (j :: i +-> j)
       (p :: i +-> k) (g :: j +-> k).
(PointwiseRightKanExtension j p, Representable g) =>
Sq Nil Nil (j ::: (g ::: Nil)) (p ::: Nil)
-> Sq Nil Nil (g ::: Nil) ((j |> p) ::: Nil)
pwRanUniv = ((Fold (Nil +++ (j ::: (g ::: Nil))) ~> Fold ((p ::: Nil) +++ Nil))
 -> Fold (Nil +++ (g ::: Nil)) ~> Fold (((j |> p) ::: Nil) +++ Nil))
-> Sq Nil Nil (j ::: (g ::: Nil)) (p ::: Nil)
-> Sq Nil Nil (g ::: Nil) ((j |> p) ::: Nil)
forall {j1 :: Kind} {h1 :: Kind} {i1 :: Kind} {k1 :: Kind}
       {j2 :: Kind} {h2 :: Kind} {k2 :: Kind} {i2 :: Kind}
       (ps :: Path j1 h1) (fs :: Path h1 i1) (gs :: Path j1 k1)
       (qs :: Path k1 i1) (ps' :: Path j2 h2) (qs' :: Path k2 i2)
       (fs' :: Path h2 i2) (gs' :: Path j2 k2).
(Profunctor (Fold (ps +++ fs)), Profunctor (Fold (gs +++ qs)),
 IsPath ps', IsPath qs', IsTight fs', IsTight gs') =>
((Fold (ps +++ fs) ~> Fold (gs +++ qs))
 -> Fold (ps' +++ fs') ~> Fold (gs' +++ qs'))
-> Sq ps qs fs gs -> Sq ps' qs' fs' gs'
mapSq ((g :.: j) ~> p) -> g ~> (j |> p)
(Fold (Nil +++ (j ::: (g ::: Nil))) ~> Fold ((p ::: Nil) +++ Nil))
-> Fold (Nil +++ (g ::: Nil)) ~> Fold (((j |> p) ::: Nil) +++ Nil)
forall {i :: Kind} {j1 :: Kind} {k :: Kind} (j2 :: i +-> j1)
       (g :: j1 +-> k) (p :: k -> i -> Kind).
(Profunctor j2, Profunctor g) =>
((g :.: j2) ~> p) -> g ~> (j2 |> p)
R.ranUniv

-- | Pointwise Rift: @j . r => p@, with all three functors horizontal.
--
-- > J-----------J
-- > r>---\      |
-- > |     @---->p
-- > j>---/      |
-- > I-----------I
pwRift :: (L.PointwiseRightKanLift j p) => Sq Nil Nil (p L.<| j ::: j ::: Nil) (p ::: Nil)
pwRift :: forall {j :: Kind} {k :: Kind} {j :: Kind} (j :: j +-> k)
       (p :: j +-> k).
PointwiseRightKanLift j p =>
Sq Nil Nil ((p <| j) ::: (j ::: Nil)) (p ::: Nil)
pwRift = (Fold (Nil +++ ((p <| j) ::: (j ::: Nil)))
 :~> Fold ((p ::: Nil) +++ Nil))
-> Sq Nil Nil ((p <| j) ::: (j ::: Nil)) (p ::: Nil)
forall {j :: Kind} {h :: Kind} {k :: Kind} {i :: Kind}
       (p :: Path j h) (q :: Path k i) (f :: Path h i) (g :: Path j k).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq (Prof (j :.: (p <| j)) p -> (j :.: (p <| j)) :~> p
forall {k1 :: Kind} {k :: Kind} (p :: k1 +-> k) (q :: k1 +-> k).
Prof p q -> p :~> q
unProf (j :.: (p <| j)) ~> p
Prof (j :.: (p <| j)) p
forall {k :: Kind} {i1 :: Kind} {i2 :: Kind} (j :: k +-> i1)
       (p :: i2 +-> i1).
(Profunctor j, Profunctor p) =>
(j :.: (p <| j)) ~> p
L.runRiftProf)

-- | The universal property of pointwise Rift.
--
-- The dotted inner square is the input; the solid outer square is the result.
--
-- > J-------------------J
-- > |                   |
-- > |   J...........J   |
-- > g>-------\      :   |
-- > |   :     @---->p   r
-- > |   j>---/      :   |
-- > |   I...........I   |
-- > |                   |
-- > K-------------------K
--
-- Here @r = p <| j@.
pwRiftUniv
  :: (L.PointwiseRightKanLift j p, Representable g)
  => Sq Nil Nil (g ::: j ::: Nil) (p ::: Nil)
  -> Sq Nil Nil (g ::: Nil) (p L.<| j ::: Nil)
pwRiftUniv :: forall {k :: Kind} {i :: Kind} {j :: Kind} (j :: k +-> i)
       (p :: j +-> i) (g :: j +-> k).
(PointwiseRightKanLift j p, Representable g) =>
Sq Nil Nil (g ::: (j ::: Nil)) (p ::: Nil)
-> Sq Nil Nil (g ::: Nil) ((p <| j) ::: Nil)
pwRiftUniv = ((Fold (Nil +++ (g ::: (j ::: Nil))) ~> Fold ((p ::: Nil) +++ Nil))
 -> Fold (Nil +++ (g ::: Nil)) ~> Fold (((p <| j) ::: Nil) +++ Nil))
-> Sq Nil Nil (g ::: (j ::: Nil)) (p ::: Nil)
-> Sq Nil Nil (g ::: Nil) ((p <| j) ::: Nil)
forall {j1 :: Kind} {h1 :: Kind} {i1 :: Kind} {k1 :: Kind}
       {j2 :: Kind} {h2 :: Kind} {k2 :: Kind} {i2 :: Kind}
       (ps :: Path j1 h1) (fs :: Path h1 i1) (gs :: Path j1 k1)
       (qs :: Path k1 i1) (ps' :: Path j2 h2) (qs' :: Path k2 i2)
       (fs' :: Path h2 i2) (gs' :: Path j2 k2).
(Profunctor (Fold (ps +++ fs)), Profunctor (Fold (gs +++ qs)),
 IsPath ps', IsPath qs', IsTight fs', IsTight gs') =>
((Fold (ps +++ fs) ~> Fold (gs +++ qs))
 -> Fold (ps' +++ fs') ~> Fold (gs' +++ qs'))
-> Sq ps qs fs gs -> Sq ps' qs' fs' gs'
mapSq ((j :.: g) ~> p) -> g ~> (p <| j)
(Fold (Nil +++ (g ::: (j ::: Nil))) ~> Fold ((p ::: Nil) +++ Nil))
-> Fold (Nil +++ (g ::: Nil)) ~> Fold (((p <| j) ::: Nil) +++ Nil)
forall {k :: Kind} {i :: Kind} {j1 :: Kind} (j2 :: k +-> i)
       (g :: j1 +-> k) (p :: i -> j1 -> Kind).
(Profunctor j2, Profunctor g) =>
((j2 :.: g) ~> p) -> g ~> (p <| j2)
L.riftUniv

-- | Mate a transformation between corepresentable diagrams into a square.
-- Used for weighted colimits and for mating pointwise Lan and Lift.
corepSquare
  :: (Profunctor j, Corepresentable p, Corepresentable d)
  => (j :.: p :~> d)
  -> Sq (j ::: Nil) Nil (CorepStar d ::: Nil) (CorepStar p ::: Nil)
corepSquare :: forall {j :: Kind} {j :: Kind} {k :: Kind} (j :: j +-> j)
       (p :: k +-> j) (d :: k +-> j).
(Profunctor j, Corepresentable p, Corepresentable d) =>
((j :.: p) :~> d)
-> Sq (j ::: Nil) Nil (CorepStar d ::: Nil) (CorepStar p ::: Nil)
corepSquare (j :.: p) :~> d
n = (Fold ((j ::: Nil) +++ (CorepStar d ::: Nil))
 :~> Fold ((CorepStar p ::: Nil) +++ Nil))
-> Sq (j ::: Nil) Nil (CorepStar d ::: Nil) (CorepStar p ::: Nil)
forall {j :: Kind} {h :: Kind} {k :: Kind} {i :: Kind}
       (p :: Path j h) (q :: Path k i) (f :: Path h i) (g :: Path j k).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq (\(CorepStar a ~> (d %% b)
f :.: j b b
j) -> j b b
j j b b -> ((Ob b, Ob b) => CorepStar p a b) -> CorepStar p a b
forall {k1 :: Kind} {k2 :: Kind} (p :: k1 +-> k2) (a :: k2)
       (b :: k1) (r :: Kind).
Profunctor p =>
p a b -> ((Ob a, Ob b) => r) -> r
// (a ~> (p %% b)) -> CorepStar p a b
forall {j :: Kind} {k :: Kind} (b :: j) (a :: k) (p :: k +-> j).
Ob b =>
(a ~> (p %% b)) -> CorepStar p a b
CorepStar (d b (p %% b) -> (d %% b) ~> (p %% b)
forall (a :: j) (b :: k). d a b -> (d %% a) ~> b
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (a :: k) (b :: j).
Corepresentable p =>
p a b -> (p %% a) ~> b
coindex ((:.:) j p b (p %% b) -> d b (p %% b)
(j :.: p) :~> d
n (j b b
j j b b -> p b (p %% b) -> (:.:) j p b (p %% b)
forall {j :: Kind} {k :: Kind} {i :: Kind} (b :: j) (a :: k)
       (c :: i) (p :: j +-> k) (q :: i +-> j).
p a b -> q b c -> (:.:) p q a c
:.: p b (p %% b)
forall (a :: j). Ob a => p a (p %% a)
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (a :: k).
(Corepresentable p, Ob a) =>
p a (p %% a)
corepUniv)) ((d %% b) ~> (p %% b)) -> (a ~> (d %% b)) -> a ~> (p %% b)
forall (b :: k) (c :: k) (a :: k). (b ~> c) -> (a ~> b) -> a ~> c
forall {k :: Kind} (p :: CAT k) (b :: k) (c :: k) (a :: k).
Promonad p =>
p b c -> p a b -> p a c
. a ~> (d %% b)
f))

-- | Recover the transformation from its corepresentable mate.
corepSquareInv
  :: forall j p d
   . (Profunctor j, Corepresentable p, Corepresentable d)
  => Sq (j ::: Nil) Nil (CorepStar d ::: Nil) (CorepStar p ::: Nil)
  -> j :.: p :~> d
corepSquareInv :: forall {j :: Kind} {k :: Kind} {k1 :: Kind} (j :: j +-> k)
       (p :: k1 +-> j) (d :: k1 +-> k).
(Profunctor j, Corepresentable p, Corepresentable d) =>
Sq (j ::: Nil) Nil (CorepStar d ::: Nil) (CorepStar p ::: Nil)
-> (j :.: p) :~> d
corepSquareInv (Sq Fold ((j ::: Nil) +++ (CorepStar d ::: Nil))
:~> Fold ((CorepStar p ::: Nil) +++ Nil)
n) = Prof (j :.: p) d -> (j :.: p) :~> d
forall {k1 :: Kind} {k :: Kind} (p :: k1 +-> k) (q :: k1 +-> k).
Prof p q -> p :~> q
unProf (Prof (CorepStar d :.: j) (CorepStar p) -> Prof (j :.: p) d
forall {j :: Kind} {k :: Kind} {j :: Kind} (j :: j +-> k)
       (p :: j +-> j) (d :: j +-> k).
(Profunctor j, Corepresentable p, Corepresentable d) =>
Prof (CorepStar d :.: j) (CorepStar p) -> Prof (j :.: p) d
corepMateInv (((CorepStar d :.: j) :~> CorepStar p)
-> Prof (CorepStar d :.: j) (CorepStar p)
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (q :: j +-> k).
(Profunctor p, Profunctor q) =>
(p :~> q) -> Prof p q
Prof (:.:) (CorepStar d) j a b -> CorepStar p a b
Fold ((j ::: Nil) +++ (CorepStar d ::: Nil)) a b
-> Fold ((CorepStar p ::: Nil) +++ Nil) a b
(CorepStar d :.: j) :~> CorepStar p
Fold ((j ::: Nil) +++ (CorepStar d ::: Nil))
:~> Fold ((CorepStar p ::: Nil) +++ Nil)
n))

-- | Undo the corepresentable mate of @j :.: p ~> d@. The weight @j@ may be
-- an arbitrary profunctor, as in a weighted colimit.
corepMateInv
  :: forall j p d
   . (Profunctor j, Corepresentable p, Corepresentable d)
  => Prof (CorepStar d :.: j) (CorepStar p)
  -> Prof (j :.: p) d
corepMateInv :: forall {j :: Kind} {k :: Kind} {j :: Kind} (j :: j +-> k)
       (p :: j +-> j) (d :: j +-> k).
(Profunctor j, Corepresentable p, Corepresentable d) =>
Prof (CorepStar d :.: j) (CorepStar p) -> Prof (j :.: p) d
corepMateInv (Prof (CorepStar d :.: j) :~> CorepStar p
n) = ((j :.: p) :~> d) -> Prof (j :.: p) d
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (q :: j +-> k).
(Profunctor p, Profunctor q) =>
(p :~> q) -> Prof p q
Prof (\(j a b
j :.: p b b
p) -> j a b
j j a b -> ((Ob a, Ob b) => d a b) -> d a b
forall {k1 :: Kind} {k2 :: Kind} (p :: k1 +-> k2) (a :: k2)
       (b :: k1) (r :: Kind).
Profunctor p =>
p a b -> ((Ob a, Ob b) => r) -> r
// ((d %% a) ~> b) -> d a b
forall (a :: k) (b :: j). Ob a => ((d %% a) ~> b) -> d a b
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (a :: k) (b :: j).
(Corepresentable p, Ob a) =>
((p %% a) ~> b) -> p a b
cotabulate (p b b -> (p %% b) ~> b
forall (a :: j) (b :: j). p a b -> (p %% a) ~> b
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (a :: k) (b :: j).
Corepresentable p =>
p a b -> (p %% a) ~> b
coindex p b b
p ((p %% b) ~> b) -> ((d %% a) ~> (p %% b)) -> (d %% a) ~> b
forall (b :: j) (c :: j) (a :: j). (b ~> c) -> (a ~> b) -> a ~> c
forall {k :: Kind} (p :: CAT k) (b :: k) (c :: k) (a :: k).
Promonad p =>
p b c -> p a b -> p a c
. CorepStar p (d %% a) b -> (d %% a) ~> (CorepStar p % b)
forall (a :: j) (b :: j). CorepStar p a b -> a ~> (CorepStar p % b)
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (a :: k) (b :: j).
Representable p =>
p a b -> a ~> (p % b)
index ((:.:) (CorepStar d) j (d %% a) b -> CorepStar p (d %% a) b
(CorepStar d :.: j) :~> CorepStar p
n (CorepStar d (d %% a) a
CorepStar d (CorepStar d % a) a
forall (a :: k). Ob a => CorepStar d (CorepStar d % a) a
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (a :: j).
(Representable p, Ob a) =>
p (p % a) a
repUniv CorepStar d (d %% a) a -> j a b -> (:.:) (CorepStar d) j (d %% a) b
forall {j :: Kind} {k :: Kind} {i :: Kind} (b :: j) (a :: k)
       (c :: i) (p :: j +-> k) (q :: i +-> j).
p a b -> q b c -> (:.:) p q a c
:.: j a b
j))))

-- | Recover a transformation between corepresentable profunctors from its
-- mate between horizontal functor paths. Mating reverses composition order.
corepComposeSquareInv
  :: forall p q d
   . (Corepresentable p, Corepresentable q, Corepresentable d)
  => Sq Nil Nil (CorepStar d ::: Nil) (CorepStar p ::: CorepStar q ::: Nil)
  -> p :.: q :~> d
corepComposeSquareInv :: forall {j :: Kind} {k :: Kind} {k1 :: Kind} (p :: j +-> k)
       (q :: k1 +-> j) (d :: k1 +-> k).
(Corepresentable p, Corepresentable q, Corepresentable d) =>
Sq
  Nil
  Nil
  (CorepStar d ::: Nil)
  (CorepStar p ::: (CorepStar q ::: Nil))
-> (p :.: q) :~> d
corepComposeSquareInv (Sq Fold (Nil +++ (CorepStar d ::: Nil))
:~> Fold ((CorepStar p ::: (CorepStar q ::: Nil)) +++ Nil)
n) = Prof (p :.: q) d -> (p :.: q) :~> d
forall {k1 :: Kind} {k :: Kind} (p :: k1 +-> k) (q :: k1 +-> k).
Prof p q -> p :~> q
unProf (Prof (CorepStar d) (CorepStar q :.: CorepStar p)
-> Prof (p :.: q) d
forall {j :: Kind} {k :: Kind} {j :: Kind} (p :: j +-> k)
       (q :: j +-> j) (d :: j +-> k).
(Corepresentable p, Corepresentable q, Corepresentable d) =>
Prof (CorepStar d) (CorepStar q :.: CorepStar p)
-> Prof (p :.: q) d
corepComposeMateInv ((CorepStar d :~> (CorepStar q :.: CorepStar p))
-> Prof (CorepStar d) (CorepStar q :.: CorepStar p)
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (q :: j +-> k).
(Profunctor p, Profunctor q) =>
(p :~> q) -> Prof p q
Prof CorepStar d a b -> (:.:) (CorepStar q) (CorepStar p) a b
Fold (Nil +++ (CorepStar d ::: Nil)) a b
-> Fold ((CorepStar p ::: (CorepStar q ::: Nil)) +++ Nil) a b
CorepStar d :~> (CorepStar q :.: CorepStar p)
Fold (Nil +++ (CorepStar d ::: Nil))
:~> Fold ((CorepStar p ::: (CorepStar q ::: Nil)) +++ Nil)
n))

-- | Undo mating between corepresentable composites and their representing
-- functors. The order of composition is reversed.
corepComposeMateInv
  :: forall p q d
   . (Corepresentable p, Corepresentable q, Corepresentable d)
  => Prof (CorepStar d) (CorepStar q :.: CorepStar p)
  -> Prof (p :.: q) d
corepComposeMateInv :: forall {j :: Kind} {k :: Kind} {j :: Kind} (p :: j +-> k)
       (q :: j +-> j) (d :: j +-> k).
(Corepresentable p, Corepresentable q, Corepresentable d) =>
Prof (CorepStar d) (CorepStar q :.: CorepStar p)
-> Prof (p :.: q) d
corepComposeMateInv (Prof CorepStar d :~> (CorepStar q :.: CorepStar p)
n) = ((p :.: q) :~> d) -> Prof (p :.: q) d
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (q :: j +-> k).
(Profunctor p, Profunctor q) =>
(p :~> q) -> Prof p q
Prof \((:.:) p q a b
pq :: (p :.: q) a b) ->
  (:.:) p q a b
pq (:.:) p q a b -> ((Ob a, Ob b) => d a b) -> d a b
forall {k1 :: Kind} {k2 :: Kind} (p :: k1 +-> k2) (a :: k2)
       (b :: k1) (r :: Kind).
Profunctor p =>
p a b -> ((Ob a, Ob b) => r) -> r
// ((d %% a) ~> b) -> d a b
forall (a :: k) (b :: j). Ob a => ((d %% a) ~> b) -> d a b
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (a :: k) (b :: j).
(Corepresentable p, Ob a) =>
((p %% a) ~> b) -> p a b
cotabulate ((:.:) p q a b -> ((p :.: q) %% a) ~> b
forall (a :: k) (b :: j). (:.:) p q a b -> ((p :.: q) %% a) ~> b
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (a :: k) (b :: j).
Corepresentable p =>
p a b -> (p %% a) ~> b
coindex (:.:) p q a b
pq ((q %% (p %% a)) ~> b)
-> ((d %% a) ~> (q %% (p %% a))) -> (d %% a) ~> b
forall (b :: j) (c :: j) (a :: j). (b ~> c) -> (a ~> b) -> a ~> c
forall {k :: Kind} (p :: CAT k) (b :: k) (c :: k) (a :: k).
Promonad p =>
p b c -> p a b -> p a c
. (:.:) (CorepStar q) (CorepStar p) (d %% a) a
-> (d %% a) ~> ((CorepStar q :.: CorepStar p) % a)
forall (a :: j) (b :: k).
(:.:) (CorepStar q) (CorepStar p) a b
-> a ~> ((CorepStar q :.: CorepStar p) % b)
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (a :: k) (b :: j).
Representable p =>
p a b -> a ~> (p % b)
index (CorepStar d (d %% a) a
-> (:.:) (CorepStar q) (CorepStar p) (d %% a) a
CorepStar d :~> (CorepStar q :.: CorepStar p)
n (forall {j :: Kind} {k :: Kind} (p :: j +-> k) (a :: j).
(Representable p, Ob a) =>
p (p % a) a
forall (p :: k +-> j) (a :: k).
(Representable p, Ob a) =>
p (p % a) a
repUniv @(CorepStar d) @a)))

-- | Pointwise Lan: @p => l . j@, with all three functors horizontal.
--
-- > I-----------I
-- > |      /--->j
-- > p>----@     |
-- > |      \--->l
-- > K-----------K
pwLan
  :: (L.PointwiseLeftKanExtension j p)
  => Sq Nil Nil (CorepStar p ::: Nil) (CorepStar j ::: CorepStar (p L.<| j) ::: Nil)
pwLan :: forall {j :: Kind} {i :: Kind} {k :: Kind} (j :: j +-> i)
       (p :: k +-> i).
PointwiseLeftKanExtension j p =>
Sq
  Nil
  Nil
  (CorepStar p ::: Nil)
  (CorepStar j ::: (CorepStar (p <| j) ::: Nil))
pwLan = Sq Nil (j ::: Nil) Nil (CorepStar j ::: Nil)
forall {j :: Kind} {k :: Kind} (f :: j +-> k) (f' :: k +-> j).
(Proadjunction f f', Representable f) =>
Sq Nil (f' ::: Nil) Nil (f ::: Nil)
fromBottom Sq Nil (j ::: Nil) Nil (CorepStar j ::: Nil)
-> Sq
     (j ::: Nil) Nil (CorepStar p ::: Nil) (CorepStar (p <| j) ::: Nil)
-> Sq
     Nil
     Nil
     (Nil +++ (CorepStar p ::: Nil))
     ((CorepStar j ::: Nil) +++ (CorepStar (p <| j) ::: Nil))
forall {a1 :: Kind} {a2 :: Kind} {b1 :: Kind} {b2 :: Kind}
       {c1 :: Kind} {c2 :: Kind} (ps :: Path a1 a2) (qs :: Path b1 b2)
       (rs :: Path c1 c2) (ds :: Path a2 b2) (es :: Path a1 b1)
       (fs :: Path b2 c2) (gs :: Path b1 c1).
Sq ps qs ds es
-> Sq qs rs fs gs -> Sq ps rs (ds +++ fs) (es +++ gs)
=== ((j :.: (p <| j)) :~> p)
-> Sq
     (j ::: Nil) Nil (CorepStar p ::: Nil) (CorepStar (p <| j) ::: Nil)
forall {j :: Kind} {j :: Kind} {k :: Kind} (j :: j +-> j)
       (p :: k +-> j) (d :: k +-> j).
(Profunctor j, Corepresentable p, Corepresentable d) =>
((j :.: p) :~> d)
-> Sq (j ::: Nil) Nil (CorepStar d ::: Nil) (CorepStar p ::: Nil)
corepSquare (Prof (j :.: (p <| j)) p -> (j :.: (p <| j)) :~> p
forall {k1 :: Kind} {k :: Kind} (p :: k1 +-> k) (q :: k1 +-> k).
Prof p q -> p :~> q
unProf (j :.: (p <| j)) ~> p
Prof (j :.: (p <| j)) p
forall {k :: Kind} {i1 :: Kind} {i2 :: Kind} (j :: k +-> i1)
       (p :: i2 +-> i1).
(Profunctor j, Profunctor p) =>
(j :.: (p <| j)) ~> p
L.runRiftProf)

-- | The universal property of pointwise Lan. Mating reverses the
-- transformation between the corepresentable profunctors.
--
-- The dotted inner square is the input; the solid outer square is the result.
--
-- > A-------------------A
-- > |                   |
-- > |   I...........I   |
-- > |   :      /--->j   |
-- > l   p>----@     :   |
-- > |   :      \------->g
-- > |   K...........K   |
-- > |                   |
-- > K-------------------K
--
-- Here @l@ is the corepresenting functor of @p <| j@.
pwLanUniv
  :: (L.PointwiseLeftKanExtension j p, Corepresentable g)
  => Sq Nil Nil (CorepStar p ::: Nil) (CorepStar j ::: CorepStar g ::: Nil)
  -> Sq Nil Nil (CorepStar (p L.<| j) ::: Nil) (CorepStar g ::: Nil)
pwLanUniv :: forall {j :: Kind} {i :: Kind} {k :: Kind} (j :: j +-> i)
       (p :: k +-> i) (g :: k +-> j).
(PointwiseLeftKanExtension j p, Corepresentable g) =>
Sq
  Nil
  Nil
  (CorepStar p ::: Nil)
  (CorepStar j ::: (CorepStar g ::: Nil))
-> Sq Nil Nil (CorepStar (p <| j) ::: Nil) (CorepStar g ::: Nil)
pwLanUniv = ((Fold (Nil +++ (CorepStar p ::: Nil))
  ~> Fold ((CorepStar j ::: (CorepStar g ::: Nil)) +++ Nil))
 -> Fold (Nil +++ (CorepStar (p <| j) ::: Nil))
    ~> Fold ((CorepStar g ::: Nil) +++ Nil))
-> Sq
     Nil
     Nil
     (CorepStar p ::: Nil)
     (CorepStar j ::: (CorepStar g ::: Nil))
-> Sq Nil Nil (CorepStar (p <| j) ::: Nil) (CorepStar g ::: Nil)
forall {j1 :: Kind} {h1 :: Kind} {i1 :: Kind} {k1 :: Kind}
       {j2 :: Kind} {h2 :: Kind} {k2 :: Kind} {i2 :: Kind}
       (ps :: Path j1 h1) (fs :: Path h1 i1) (gs :: Path j1 k1)
       (qs :: Path k1 i1) (ps' :: Path j2 h2) (qs' :: Path k2 i2)
       (fs' :: Path h2 i2) (gs' :: Path j2 k2).
(Profunctor (Fold (ps +++ fs)), Profunctor (Fold (gs +++ qs)),
 IsPath ps', IsPath qs', IsTight fs', IsTight gs') =>
((Fold (ps +++ fs) ~> Fold (gs +++ qs))
 -> Fold (ps' +++ fs') ~> Fold (gs' +++ qs'))
-> Sq ps qs fs gs -> Sq ps' qs' fs' gs'
mapSq ((g ~> (p <| j)) -> CorepStar (p <| j) ~> CorepStar g
Prof g (p <| j) -> Prof (CorepStar (p <| j)) (CorepStar g)
forall {k :: Kind} {j :: Kind} (p :: k +-> j) (q :: k +-> j).
(Corepresentable p, Corepresentable q) =>
(p ~> q) -> CorepStar q ~> CorepStar p
mapCorepStar (Prof g (p <| j) -> Prof (CorepStar (p <| j)) (CorepStar g))
-> (Prof (CorepStar p) (CorepStar g :.: CorepStar j)
    -> Prof g (p <| j))
-> Prof (CorepStar p) (CorepStar g :.: CorepStar j)
-> Prof (CorepStar (p <| j)) (CorepStar g)
forall (b :: Kind) (c :: Kind) (a :: Kind).
(b -> c) -> (a -> b) -> a -> c
forall {k :: Kind} (p :: CAT k) (b :: k) (c :: k) (a :: k).
Promonad p =>
p b c -> p a b -> p a c
. ((j :.: g) ~> p) -> g ~> (p <| j)
Prof (j :.: g) p -> Prof g (p <| j)
forall {k :: Kind} {i :: Kind} {j1 :: Kind} (j2 :: k +-> i)
       (g :: j1 +-> k) (p :: i -> j1 -> Kind).
(Profunctor j2, Profunctor g) =>
((j2 :.: g) ~> p) -> g ~> (p <| j2)
L.riftUniv (Prof (j :.: g) p -> Prof g (p <| j))
-> (Prof (CorepStar p) (CorepStar g :.: CorepStar j)
    -> Prof (j :.: g) p)
-> Prof (CorepStar p) (CorepStar g :.: CorepStar j)
-> Prof g (p <| j)
forall (b :: Kind) (c :: Kind) (a :: Kind).
(b -> c) -> (a -> b) -> a -> c
forall {k :: Kind} (p :: CAT k) (b :: k) (c :: k) (a :: k).
Promonad p =>
p b c -> p a b -> p a c
. Prof (CorepStar p) (CorepStar g :.: CorepStar j)
-> Prof (j :.: g) p
forall {j :: Kind} {k :: Kind} {j :: Kind} (p :: j +-> k)
       (q :: j +-> j) (d :: j +-> k).
(Corepresentable p, Corepresentable q, Corepresentable d) =>
Prof (CorepStar d) (CorepStar q :.: CorepStar p)
-> Prof (p :.: q) d
corepComposeMateInv)

-- | Pointwise Lift: @p => j . l@, with all three functors horizontal.
--
-- > K-----------K
-- > |      /--->l
-- > p>----@     |
-- > |      \--->j
-- > I-----------I
pwLift
  :: (R.PointwiseLeftKanLift j p)
  => Sq Nil Nil (CorepStar p ::: Nil) (CorepStar (j R.|> p) ::: CorepStar j ::: Nil)
pwLift :: forall {k :: Kind} {j :: Kind} {j :: Kind} (j :: k +-> j)
       (p :: k +-> j).
PointwiseLeftKanLift j p =>
Sq
  Nil
  Nil
  (CorepStar p ::: Nil)
  (CorepStar (j |> p) ::: (CorepStar j ::: Nil))
pwLift = Sq Nil ((j |> p) ::: Nil) Nil (CorepStar (j |> p) ::: Nil)
forall {j :: Kind} {k :: Kind} (f :: j +-> k) (f' :: k +-> j).
(Proadjunction f f', Representable f) =>
Sq Nil (f' ::: Nil) Nil (f ::: Nil)
fromBottom Sq Nil ((j |> p) ::: Nil) Nil (CorepStar (j |> p) ::: Nil)
-> Sq
     ((j |> p) ::: Nil) Nil (CorepStar p ::: Nil) (CorepStar j ::: Nil)
-> Sq
     Nil
     Nil
     (Nil +++ (CorepStar p ::: Nil))
     ((CorepStar (j |> p) ::: Nil) +++ (CorepStar j ::: Nil))
forall {a1 :: Kind} {a2 :: Kind} {b1 :: Kind} {b2 :: Kind}
       {c1 :: Kind} {c2 :: Kind} (ps :: Path a1 a2) (qs :: Path b1 b2)
       (rs :: Path c1 c2) (ds :: Path a2 b2) (es :: Path a1 b1)
       (fs :: Path b2 c2) (gs :: Path b1 c1).
Sq ps qs ds es
-> Sq qs rs fs gs -> Sq ps rs (ds +++ fs) (es +++ gs)
=== (((j |> p) :.: j) :~> p)
-> Sq
     ((j |> p) ::: Nil) Nil (CorepStar p ::: Nil) (CorepStar j ::: Nil)
forall {j :: Kind} {j :: Kind} {k :: Kind} (j :: j +-> j)
       (p :: k +-> j) (d :: k +-> j).
(Profunctor j, Corepresentable p, Corepresentable d) =>
((j :.: p) :~> d)
-> Sq (j ::: Nil) Nil (CorepStar d ::: Nil) (CorepStar p ::: Nil)
corepSquare (Prof ((j |> p) :.: j) p -> ((j |> p) :.: j) :~> p
forall {k1 :: Kind} {k :: Kind} (p :: k1 +-> k) (q :: k1 +-> k).
Prof p q -> p :~> q
unProf ((j |> p) :.: j) ~> p
Prof ((j |> p) :.: j) p
forall {i :: Kind} {j1 :: Kind} {k :: Kind} (j2 :: i +-> j1)
       (p :: i +-> k).
(Profunctor j2, Profunctor p) =>
((j2 |> p) :.: j2) ~> p
R.runRanProf)

-- | The universal property of pointwise Lift.
--
-- The dotted inner square is the input; the solid outer square is the result.
--
-- > K-------------------K
-- > |                   |
-- > |   K...........K   |
-- > |   :      /------->g
-- > l   p>----@     :   |
-- > |   :      \--->j   |
-- > |   I...........I   |
-- > |                   |
-- > J-------------------J
--
-- Here @l@ is the corepresenting functor of @j |> p@.
pwLiftUniv
  :: (R.PointwiseLeftKanLift j p, Corepresentable g)
  => Sq Nil Nil (CorepStar p ::: Nil) (CorepStar g ::: CorepStar j ::: Nil)
  -> Sq Nil Nil (CorepStar (j R.|> p) ::: Nil) (CorepStar g ::: Nil)
pwLiftUniv :: forall {i :: Kind} {k :: Kind} {j :: Kind} (j :: i +-> k)
       (p :: i +-> j) (g :: k +-> j).
(PointwiseLeftKanLift j p, Corepresentable g) =>
Sq
  Nil
  Nil
  (CorepStar p ::: Nil)
  (CorepStar g ::: (CorepStar j ::: Nil))
-> Sq Nil Nil (CorepStar (j |> p) ::: Nil) (CorepStar g ::: Nil)
pwLiftUniv = ((Fold (Nil +++ (CorepStar p ::: Nil))
  ~> Fold ((CorepStar g ::: (CorepStar j ::: Nil)) +++ Nil))
 -> Fold (Nil +++ (CorepStar (j |> p) ::: Nil))
    ~> Fold ((CorepStar g ::: Nil) +++ Nil))
-> Sq
     Nil
     Nil
     (CorepStar p ::: Nil)
     (CorepStar g ::: (CorepStar j ::: Nil))
-> Sq Nil Nil (CorepStar (j |> p) ::: Nil) (CorepStar g ::: Nil)
forall {j1 :: Kind} {h1 :: Kind} {i1 :: Kind} {k1 :: Kind}
       {j2 :: Kind} {h2 :: Kind} {k2 :: Kind} {i2 :: Kind}
       (ps :: Path j1 h1) (fs :: Path h1 i1) (gs :: Path j1 k1)
       (qs :: Path k1 i1) (ps' :: Path j2 h2) (qs' :: Path k2 i2)
       (fs' :: Path h2 i2) (gs' :: Path j2 k2).
(Profunctor (Fold (ps +++ fs)), Profunctor (Fold (gs +++ qs)),
 IsPath ps', IsPath qs', IsTight fs', IsTight gs') =>
((Fold (ps +++ fs) ~> Fold (gs +++ qs))
 -> Fold (ps' +++ fs') ~> Fold (gs' +++ qs'))
-> Sq ps qs fs gs -> Sq ps' qs' fs' gs'
mapSq ((g ~> (j |> p)) -> CorepStar (j |> p) ~> CorepStar g
Prof g (j |> p) -> Prof (CorepStar (j |> p)) (CorepStar g)
forall {k :: Kind} {j :: Kind} (p :: k +-> j) (q :: k +-> j).
(Corepresentable p, Corepresentable q) =>
(p ~> q) -> CorepStar q ~> CorepStar p
mapCorepStar (Prof g (j |> p) -> Prof (CorepStar (j |> p)) (CorepStar g))
-> (Prof (CorepStar p) (CorepStar j :.: CorepStar g)
    -> Prof g (j |> p))
-> Prof (CorepStar p) (CorepStar j :.: CorepStar g)
-> Prof (CorepStar (j |> p)) (CorepStar g)
forall (b :: Kind) (c :: Kind) (a :: Kind).
(b -> c) -> (a -> b) -> a -> c
forall {k :: Kind} (p :: CAT k) (b :: k) (c :: k) (a :: k).
Promonad p =>
p b c -> p a b -> p a c
. ((g :.: j) ~> p) -> g ~> (j |> p)
Prof (g :.: j) p -> Prof g (j |> p)
forall {i :: Kind} {j1 :: Kind} {k :: Kind} (j2 :: i +-> j1)
       (g :: j1 +-> k) (p :: k -> i -> Kind).
(Profunctor j2, Profunctor g) =>
((g :.: j2) ~> p) -> g ~> (j2 |> p)
R.ranUniv (Prof (g :.: j) p -> Prof g (j |> p))
-> (Prof (CorepStar p) (CorepStar j :.: CorepStar g)
    -> Prof (g :.: j) p)
-> Prof (CorepStar p) (CorepStar j :.: CorepStar g)
-> Prof g (j |> p)
forall (b :: Kind) (c :: Kind) (a :: Kind).
(b -> c) -> (a -> b) -> a -> c
forall {k :: Kind} (p :: CAT k) (b :: k) (c :: k) (a :: k).
Promonad p =>
p b c -> p a b -> p a c
. Prof (CorepStar p) (CorepStar j :.: CorepStar g)
-> Prof (g :.: j) p
forall {j :: Kind} {k :: Kind} {j :: Kind} (p :: j +-> k)
       (q :: j +-> j) (d :: j +-> k).
(Corepresentable p, Corepresentable q, Corepresentable d) =>
Prof (CorepStar d) (CorepStar q :.: CorepStar p)
-> Prof (p :.: q) d
corepComposeMateInv)