{-# LANGUAGE AllowAmbiguousTypes #-}

-- | Squares, specialized to profunctors: the counterpart of "Proarrow.Equipment.Squares" in
-- @proarrow-equipment@. Data flows rightward along representable wires; effects flow
-- downward along profunctor wires. Paths of profunctors are read right to left, so
-- @[p, q, r]@ is drawn as @r, q, p@ and has composite @r :.: q :.: p@. Paths of
-- 'Representable' profunctors are read top to bottom.
--
-- 'vId' is the identity for '(===)', and 'hId' is the identity for '(|||)'.
--
-- A square's payload is @'Fold' (p '+++' f) :~> 'Fold' (g '+++' q)@, the fold of each side's
-- concatenated path, instead of @'Fold' f ':.:' 'Fold' p :~> 'Fold' q ':.:' 'Fold' g@.
-- "Proarrow.Path" does the associator\/unitor bookkeeping once, and since @'Nil' '+++' ps@ and
-- @ps '+++' 'Nil'@ both reduce to @ps@, combinators with trivial legs need no unitors.
module Proarrow.Squares where

import Data.Kind (Type)
import Prelude (($))

import Proarrow.Adjunction (Proadjunction)
import Proarrow.Adjunction qualified as Adj
import Proarrow.Category.Instance.Product (interchange, interchangeInv, (:**:) (..))
import Proarrow.Category.Instance.Prof (Prof (..))
import Proarrow.Core (CAT, CategoryOf (..), Profunctor (..), Promonad (..), lmap, rmap, (//), (:~>), (\\), type (+->))
import Proarrow.Optic (Prostrong (..))
import Proarrow.Path
  ( Fold
  , IsPath
  , IsTight
  , Path (..)
  , SPath (..)
  , Tag (..)
  , appendPath
  , concatFold
  , idN
  , singPath
  , splitFold
  , weakenTight
  , whiskerL
  , whiskerR
  , withAssoc
  , withFoldOb
  , withFoldRep
  , withObAppend
  , type (+++)
  )
import Proarrow.Profunctor.Corepresentable (Corepresentable)
import Proarrow.Profunctor.Instance.Composition ((:.:) (..))
import Proarrow.Profunctor.Instance.Identity (Id (..))
import Proarrow.Profunctor.Representable (CorepStar, Representable (..), SameRep, SameRepAt (..))

infixl 6 |||
infixl 5 ===

-- | The kind of a square @p q f g@.
--
-- > h---p---j
-- > |   |   |
-- > f>--@-->g
-- > |   |   |
-- > i---q---k
type Sq :: Path j h -> Path k i -> Path h i -> Path j k -> Type
data Sq p q f g where
  Sq
    :: (IsPath p, IsPath q, IsTight f, IsTight g)
    => Fold (p +++ f) :~> Fold (g +++ q)
    -> Sq p q f g

-- | Transform a square's underlying natural transformation through 'Prof'.
-- All four boundaries may change, as in a universal-property construction.
mapSq
  :: ( 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 :: forall {j :: Kind} {h :: Kind} {i :: Kind} {k :: Kind} {j :: Kind}
       {h :: Kind} {k :: Kind} {i :: Kind} (ps :: Path j h)
       (fs :: Path h i) (gs :: Path j k) (qs :: Path k i)
       (ps' :: Path j h) (qs' :: Path k i) (fs' :: Path h i)
       (gs' :: Path j k).
(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 (Fold (ps +++ fs) ~> Fold (gs +++ qs))
-> Fold (ps' +++ fs') ~> Fold (gs' +++ qs')
f (Sq Fold (ps +++ fs) :~> Fold (gs +++ qs)
n) = (Fold (ps' +++ fs') :~> Fold (gs' +++ qs')) -> Sq ps' qs' fs' gs'
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq (Prof (Fold (ps' +++ fs')) (Fold (gs' +++ qs'))
-> Fold (ps' +++ fs') :~> Fold (gs' +++ qs')
forall {k1 :: Kind} {k :: Kind} (p :: k1 +-> k) (q :: k1 +-> k).
Prof p q -> p :~> q
unProf ((Fold (ps +++ fs) ~> Fold (gs +++ qs))
-> Fold (ps' +++ fs') ~> Fold (gs' +++ qs')
f ((Fold (ps +++ fs) :~> Fold (gs +++ qs))
-> Prof (Fold (ps +++ fs)) (Fold (gs +++ qs))
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (q :: j +-> k).
(Profunctor p, Profunctor q) =>
(p :~> q) -> Prof p q
Prof Fold (ps +++ fs) a b -> Fold (gs +++ qs) a b
Fold (ps +++ fs) :~> Fold (gs +++ qs)
n)))

-- | Construct a square from its pointwise action. The representable legs act on the
-- input objects through '%'; composition and identity wrappers on those legs are handled
-- automatically. The action must be natural in both objects.
--
-- A traversal crossing, with @[]@ effects and @Maybe@ data:
--
-- >>> import Proarrow.Profunctor.Instance.Star (Star, pattern Star, unStar)
-- >>> import Prelude qualified as P
-- >>> type Crossing = Sq (Star [] ::: Nil) (Star [] ::: Nil) (Star P.Maybe ::: Nil) (Star P.Maybe ::: Nil)
-- >>> let crossing = mkSquare (\(Star f) -> Star (P.traverse f)) :: Crossing
-- >>> unStar (runSquare crossing (Star (\x -> [x, P.not x]))) (P.Just P.True)
-- [Just True,Just False]
-- >>> unStar (runSquare crossing (Star (\x -> [x, P.not x]))) P.Nothing
-- [Nothing]
mkSquare
  :: forall ps qs fs gs
   . (IsPath ps, IsPath qs, IsTight fs, IsTight gs)
  => (forall a b. (Ob a, Ob b) => Fold ps a b -> Fold qs (Fold fs % a) (Fold gs % b))
  -> Sq ps qs fs gs
mkSquare :: forall {j :: Kind} {h :: Kind} {k :: Kind} {i :: Kind}
       (ps :: Path j h) (qs :: Path k i) (fs :: Path h i)
       (gs :: Path j k).
(IsPath ps, IsPath qs, IsTight fs, IsTight gs) =>
(forall (a :: h) (b :: j).
 (Ob a, Ob b) =>
 Fold ps a b -> Fold qs (Fold fs % a) (Fold gs % b))
-> Sq ps qs fs gs
mkSquare forall (a :: h) (b :: j).
(Ob a, Ob b) =>
Fold ps a b -> Fold qs (Fold fs % a) (Fold gs % b)
n =
  SPath 'Loose ps
-> (Profunctor (Fold ps) => Sq ps qs fs gs) -> Sq ps qs fs gs
forall {j :: Kind} {k :: Kind} (ps :: Path j k) (r :: Kind).
SPath 'Loose ps -> (Profunctor (Fold ps) => r) -> r
withFoldOb SPath 'Loose ps
sps ((Profunctor (Fold ps) => Sq ps qs fs gs) -> Sq ps qs fs gs)
-> (Profunctor (Fold ps) => Sq ps qs fs gs) -> Sq ps qs fs gs
forall a b. (a -> b) -> a -> b
$
    SPath 'Loose qs
-> (Profunctor (Fold qs) => Sq ps qs fs gs) -> Sq ps qs fs gs
forall {j :: Kind} {k :: Kind} (ps :: Path j k) (r :: Kind).
SPath 'Loose ps -> (Profunctor (Fold ps) => r) -> r
withFoldOb SPath 'Loose qs
sqs ((Profunctor (Fold qs) => Sq ps qs fs gs) -> Sq ps qs fs gs)
-> (Profunctor (Fold qs) => Sq ps qs fs gs) -> Sq ps qs fs gs
forall a b. (a -> b) -> a -> b
$
      SPath 'Tight fs
-> (Representable (Fold fs) => Sq ps qs fs gs) -> Sq ps qs fs gs
forall {j :: Kind} {k :: Kind} (ps :: Path j k) (r :: Kind).
SPath 'Tight ps -> (Representable (Fold ps) => r) -> r
withFoldRep SPath 'Tight fs
tfs ((Representable (Fold fs) => Sq ps qs fs gs) -> Sq ps qs fs gs)
-> (Representable (Fold fs) => Sq ps qs fs gs) -> Sq ps qs fs gs
forall a b. (a -> b) -> a -> b
$
        SPath 'Tight gs
-> (Representable (Fold gs) => Sq ps qs fs gs) -> Sq ps qs fs gs
forall {j :: Kind} {k :: Kind} (ps :: Path j k) (r :: Kind).
SPath 'Tight ps -> (Representable (Fold ps) => r) -> r
withFoldRep SPath 'Tight gs
tgs ((Representable (Fold gs) => Sq ps qs fs gs) -> Sq ps qs fs gs)
-> (Representable (Fold gs) => Sq ps qs fs gs) -> Sq ps qs fs gs
forall a b. (a -> b) -> a -> b
$
          (Fold (ps +++ fs) :~> Fold (gs +++ qs)) -> Sq ps qs fs gs
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq \Fold (ps +++ fs) a b
pf -> case SPath 'Loose ps
-> SPath 'Loose fs -> Fold (ps +++ fs) :~> (Fold fs :.: Fold ps)
forall {i :: Kind} {k1 :: Kind} {k2 :: Kind} (as :: Path i k1)
       (bs :: Path k1 k2).
SPath 'Loose as
-> SPath 'Loose bs -> Fold (as +++ bs) :~> (Fold bs :.: Fold as)
splitFold SPath 'Loose ps
sps SPath 'Loose fs
sfs Fold (ps +++ fs) a b
pf of
            Fold fs a b
f :.: Fold ps b b
p -> Fold ps b b
p Fold ps b b
-> ((Ob b, Ob b) => Fold (gs +++ qs) a b) -> Fold (gs +++ qs) 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
// SPath 'Loose gs
-> SPath 'Loose qs -> (Fold qs :.: Fold gs) :~> Fold (gs +++ qs)
forall {j :: Kind} {b :: Kind} {k :: Kind} (as :: Path j b)
       (bs :: Path b k).
SPath 'Loose as
-> SPath 'Loose bs -> (Fold bs :.: Fold as) :~> Fold (as +++ bs)
concatFold SPath 'Loose gs
sgs SPath 'Loose qs
sqs ((a ~> (Fold fs % b))
-> Fold qs (Fold fs % b) (Fold gs % b) -> Fold qs a (Fold gs % b)
forall (c :: i) (a :: i) (b :: k).
(c ~> a) -> Fold qs a b -> Fold qs c b
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (c :: k) (a :: k)
       (b :: j).
Profunctor p =>
(c ~> a) -> p a b -> p c b
lmap (Fold fs a b -> a ~> (Fold fs % b)
forall (a :: i) (b :: h). Fold fs a b -> a ~> (Fold fs % b)
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (a :: k) (b :: j).
Representable p =>
p a b -> a ~> (p % b)
index Fold fs a b
f) (Fold ps b b -> Fold qs (Fold fs % b) (Fold gs % b)
forall (a :: h) (b :: j).
(Ob a, Ob b) =>
Fold ps a b -> Fold qs (Fold fs % a) (Fold gs % b)
n Fold ps b b
p) Fold qs a (Fold gs % b)
-> Fold gs (Fold gs % b) b -> (:.:) (Fold qs) (Fold gs) 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
:.: forall {j :: Kind} {k :: Kind} (p :: j +-> k) (a :: j).
(Representable p, Ob a) =>
p (p % a) a
forall (p :: j +-> k) (a :: j).
(Representable p, Ob a) =>
p (p % a) a
repUniv @(Fold gs))
  where
    sps :: SPath Loose ps
    sps :: SPath 'Loose ps
sps = SPath 'Loose ps
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    sqs :: SPath Loose qs
    sqs :: SPath 'Loose qs
sqs = SPath 'Loose qs
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    tfs :: SPath Tight fs
    tfs :: SPath 'Tight fs
tfs = SPath 'Tight fs
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    tgs :: SPath Tight gs
    tgs :: SPath 'Tight gs
tgs = SPath 'Tight gs
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    sfs :: SPath 'Loose fs
sfs = SPath 'Tight fs -> SPath 'Loose fs
forall {a :: Kind} {b :: Kind} (ps :: Path a b).
SPath 'Tight ps -> SPath 'Loose ps
weakenTight SPath 'Tight fs
tfs
    sgs :: SPath 'Loose gs
sgs = SPath 'Tight gs -> SPath 'Loose gs
forall {a :: Kind} {b :: Kind} (ps :: Path a b).
SPath 'Tight ps -> SPath 'Loose ps
weakenTight SPath 'Tight gs
tgs

-- | Evaluate a square on a profunctor value. Inverse to 'mkSquare', by naturality and
-- the representability laws. Empty profunctor paths still use the 'Id' wrapper.
runSquare
  :: forall ps qs fs gs a b
   . Sq ps qs fs gs
  -> Fold ps a b
  -> Fold qs (Fold fs % a) (Fold gs % b)
runSquare :: forall {j :: Kind} {j :: Kind} {k :: Kind} {k :: Kind}
       (ps :: Path j j) (qs :: Path k k) (fs :: Path j k) (gs :: Path j k)
       (a :: j) (b :: j).
Sq ps qs fs gs
-> Fold ps a b -> Fold qs (Fold fs % a) (Fold gs % b)
runSquare (Sq Fold (ps +++ fs) :~> Fold (gs +++ qs)
n) Fold ps a b
p =
  SPath 'Loose ps
-> (Profunctor (Fold ps) => Fold qs (Fold fs % a) (Fold gs % b))
-> Fold qs (Fold fs % a) (Fold gs % b)
forall {j :: Kind} {k :: Kind} (ps :: Path j k) (r :: Kind).
SPath 'Loose ps -> (Profunctor (Fold ps) => r) -> r
withFoldOb SPath 'Loose ps
sps ((Profunctor (Fold ps) => Fold qs (Fold fs % a) (Fold gs % b))
 -> Fold qs (Fold fs % a) (Fold gs % b))
-> (Profunctor (Fold ps) => Fold qs (Fold fs % a) (Fold gs % b))
-> Fold qs (Fold fs % a) (Fold gs % b)
forall a b. (a -> b) -> a -> b
$
    SPath 'Loose qs
-> (Profunctor (Fold qs) => Fold qs (Fold fs % a) (Fold gs % b))
-> Fold qs (Fold fs % a) (Fold gs % b)
forall {j :: Kind} {k :: Kind} (ps :: Path j k) (r :: Kind).
SPath 'Loose ps -> (Profunctor (Fold ps) => r) -> r
withFoldOb SPath 'Loose qs
sqs ((Profunctor (Fold qs) => Fold qs (Fold fs % a) (Fold gs % b))
 -> Fold qs (Fold fs % a) (Fold gs % b))
-> (Profunctor (Fold qs) => Fold qs (Fold fs % a) (Fold gs % b))
-> Fold qs (Fold fs % a) (Fold gs % b)
forall a b. (a -> b) -> a -> b
$
      SPath 'Tight fs
-> (Representable (Fold fs) => Fold qs (Fold fs % a) (Fold gs % b))
-> Fold qs (Fold fs % a) (Fold gs % b)
forall {j :: Kind} {k :: Kind} (ps :: Path j k) (r :: Kind).
SPath 'Tight ps -> (Representable (Fold ps) => r) -> r
withFoldRep SPath 'Tight fs
tfs ((Representable (Fold fs) => Fold qs (Fold fs % a) (Fold gs % b))
 -> Fold qs (Fold fs % a) (Fold gs % b))
-> (Representable (Fold fs) => Fold qs (Fold fs % a) (Fold gs % b))
-> Fold qs (Fold fs % a) (Fold gs % b)
forall a b. (a -> b) -> a -> b
$
        SPath 'Tight gs
-> (Representable (Fold gs) => Fold qs (Fold fs % a) (Fold gs % b))
-> Fold qs (Fold fs % a) (Fold gs % b)
forall {j :: Kind} {k :: Kind} (ps :: Path j k) (r :: Kind).
SPath 'Tight ps -> (Representable (Fold ps) => r) -> r
withFoldRep SPath 'Tight gs
tgs ((Representable (Fold gs) => Fold qs (Fold fs % a) (Fold gs % b))
 -> Fold qs (Fold fs % a) (Fold gs % b))
-> (Representable (Fold gs) => Fold qs (Fold fs % a) (Fold gs % b))
-> Fold qs (Fold fs % a) (Fold gs % b)
forall a b. (a -> b) -> a -> b
$
          Fold ps a b
p Fold ps a b
-> ((Ob a, Ob b) => Fold qs (Fold fs % a) (Fold gs % b))
-> Fold qs (Fold fs % a) (Fold gs % 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
// case SPath 'Loose gs
-> SPath 'Loose qs -> Fold (gs +++ qs) :~> (Fold qs :.: Fold gs)
forall {i :: Kind} {k1 :: Kind} {k2 :: Kind} (as :: Path i k1)
       (bs :: Path k1 k2).
SPath 'Loose as
-> SPath 'Loose bs -> Fold (as +++ bs) :~> (Fold bs :.: Fold as)
splitFold SPath 'Loose gs
sgs SPath 'Loose qs
sqs (Fold (ps +++ fs) (Fold fs % a) b
-> Fold (gs +++ qs) (Fold fs % a) b
Fold (ps +++ fs) :~> Fold (gs +++ qs)
n (SPath 'Loose ps
-> SPath 'Loose fs -> (Fold fs :.: Fold ps) :~> Fold (ps +++ fs)
forall {j :: Kind} {b :: Kind} {k :: Kind} (as :: Path j b)
       (bs :: Path b k).
SPath 'Loose as
-> SPath 'Loose bs -> (Fold bs :.: Fold as) :~> Fold (as +++ bs)
concatFold SPath 'Loose ps
sps SPath 'Loose fs
sfs (forall {j :: Kind} {k :: Kind} (p :: j +-> k) (a :: j).
(Representable p, Ob a) =>
p (p % a) a
forall (p :: j +-> k) (a :: j).
(Representable p, Ob a) =>
p (p % a) a
repUniv @(Fold fs) Fold fs (Fold fs % a) a
-> Fold ps a b -> (:.:) (Fold fs) (Fold ps) (Fold fs % 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
:.: Fold ps a b
p))) of
            Fold qs (Fold fs % a) b
q :.: Fold gs b b
g -> (b ~> (Fold gs % b))
-> Fold qs (Fold fs % a) b -> Fold qs (Fold fs % a) (Fold gs % b)
forall (b :: k) (d :: k) (a :: k).
(b ~> d) -> Fold qs a b -> Fold qs a d
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (b :: j) (d :: j)
       (a :: k).
Profunctor p =>
(b ~> d) -> p a b -> p a d
rmap (Fold gs b b -> b ~> (Fold gs % b)
forall (a :: k) (b :: j). Fold gs a b -> a ~> (Fold gs % b)
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (a :: k) (b :: j).
Representable p =>
p a b -> a ~> (p % b)
index Fold gs b b
g) Fold qs (Fold fs % a) b
q
  where
    sps :: SPath Loose ps
    sps :: SPath 'Loose ps
sps = SPath 'Loose ps
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    sqs :: SPath Loose qs
    sqs :: SPath 'Loose qs
sqs = SPath 'Loose qs
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    tfs :: SPath Tight fs
    tfs :: SPath 'Tight fs
tfs = SPath 'Tight fs
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    tgs :: SPath Tight gs
    tgs :: SPath 'Tight gs
tgs = SPath 'Tight gs
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    sfs :: SPath 'Loose fs
sfs = SPath 'Tight fs -> SPath 'Loose fs
forall {a :: Kind} {b :: Kind} (ps :: Path a b).
SPath 'Tight ps -> SPath 'Loose ps
weakenTight SPath 'Tight fs
tfs
    sgs :: SPath 'Loose gs
sgs = SPath 'Tight gs -> SPath 'Loose gs
forall {a :: Kind} {b :: Kind} (ps :: Path a b).
SPath 'Tight ps -> SPath 'Loose ps
weakenTight SPath 'Tight gs
tgs

-- | Run two squares with singleton boundaries independently over product categories.
parallel
  :: ( Profunctor p
     , Profunctor q
     , Representable f
     , Representable g
     , Profunctor p'
     , Profunctor q'
     , Representable f'
     , Representable g'
     )
  => Sq (p ::: Nil) (q ::: Nil) (f ::: Nil) (g ::: Nil)
  -> Sq (p' ::: Nil) (q' ::: Nil) (f' ::: Nil) (g' ::: Nil)
  -> Sq (p :**: p' ::: Nil) (q :**: q' ::: Nil) (f :**: f' ::: Nil) (g :**: g' ::: Nil)
parallel :: forall {j1 :: Kind} {j1 :: Kind} {k1 :: Kind} {k1 :: Kind}
       {j2 :: Kind} {j2 :: Kind} {k2 :: Kind} {k2 :: Kind}
       (p :: j1 +-> j1) (q :: k1 +-> k1) (f :: j1 +-> k1) (g :: j1 +-> k1)
       (p' :: j2 +-> j2) (q' :: k2 +-> k2) (f' :: j2 +-> k2)
       (g' :: j2 +-> k2).
(Profunctor p, Profunctor q, Representable f, Representable g,
 Profunctor p', Profunctor q', Representable f',
 Representable g') =>
Sq (p ::: Nil) (q ::: Nil) (f ::: Nil) (g ::: Nil)
-> Sq (p' ::: Nil) (q' ::: Nil) (f' ::: Nil) (g' ::: Nil)
-> Sq
     ((p :**: p') ::: Nil)
     ((q :**: q') ::: Nil)
     ((f :**: f') ::: Nil)
     ((g :**: g') ::: Nil)
parallel (Sq Fold ((p ::: Nil) +++ (f ::: Nil))
:~> Fold ((g ::: Nil) +++ (q ::: Nil))
n) (Sq Fold ((p' ::: Nil) +++ (f' ::: Nil))
:~> Fold ((g' ::: Nil) +++ (q' ::: Nil))
m) = (Fold (((p :**: p') ::: Nil) +++ ((f :**: f') ::: Nil))
 :~> Fold (((g :**: g') ::: Nil) +++ ((q :**: q') ::: Nil)))
-> Sq
     ((p :**: p') ::: Nil)
     ((q :**: q') ::: Nil)
     ((f :**: f') ::: Nil)
     ((g :**: g') ::: Nil)
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq \Fold (((p :**: p') ::: Nil) +++ ((f :**: f') ::: Nil)) a b
pq -> case (:.:) (f :**: f') (p :**: p') a b
-> (:**:) (f :.: p) (f' :.: p') a b
forall {j1 :: Kind} {k1 :: Kind} {j2 :: Kind} {k2 :: Kind}
       {j3 :: Kind} {j4 :: Kind} (p :: j1 +-> k1) (q :: j2 +-> k2)
       (r :: j3 +-> j1) (s :: j4 +-> j2) (a :: (k1, k2)) (b :: (j3, j4)).
(:.:) (p :**: q) (r :**: s) a b -> (:**:) (p :.: r) (q :.: s) a b
interchange (:.:) (f :**: f') (p :**: p') a b
Fold (((p :**: p') ::: Nil) +++ ((f :**: f') ::: Nil)) a b
pq of
  (:.:) f p a1 b1
p :**: (:.:) f' p' a2 b2
q -> (:**:) (q :.: g) (q' :.: g') '(a1, a2) '(b1, b2)
-> (:.:) (q :**: q') (g :**: g') '(a1, a2) '(b1, b2)
forall {k4 :: Kind} {k5 :: Kind} {j1 :: Kind} {k6 :: Kind}
       {k7 :: Kind} {j2 :: Kind} (p :: k4 +-> k5) (r :: j1 +-> k4)
       (q :: k6 +-> k7) (s :: j2 +-> k6) (a :: (k5, k7)) (b :: (j1, j2)).
(:**:) (p :.: r) (q :.: s) a b -> (:.:) (p :**: q) (r :**: s) a b
interchangeInv (Fold ((p ::: Nil) +++ (f ::: Nil)) a1 b1
-> Fold ((g ::: Nil) +++ (q ::: Nil)) a1 b1
Fold ((p ::: Nil) +++ (f ::: Nil))
:~> Fold ((g ::: Nil) +++ (q ::: Nil))
n (:.:) f p a1 b1
Fold ((p ::: Nil) +++ (f ::: Nil)) a1 b1
p (:.:) q g a1 b1
-> (:.:) q' g' a2 b2
-> (:**:) (q :.: g) (q' :.: g') '(a1, a2) '(b1, b2)
forall {j1 :: Kind} {k1 :: Kind} {j2 :: Kind} {k2 :: Kind}
       (c :: j1 +-> k1) (a1 :: k1) (b1 :: j1) (d :: j2 +-> k2) (a2 :: k2)
       (b2 :: j2).
c a1 b1 -> d a2 b2 -> (:**:) c d '(a1, a2) '(b1, b2)
:**: Fold ((p' ::: Nil) +++ (f' ::: Nil)) a2 b2
-> Fold ((g' ::: Nil) +++ (q' ::: Nil)) a2 b2
Fold ((p' ::: Nil) +++ (f' ::: Nil))
:~> Fold ((g' ::: Nil) +++ (q' ::: Nil))
m (:.:) f' p' a2 b2
Fold ((p' ::: Nil) +++ (f' ::: Nil)) a2 b2
q)

-- | Run two natural-transformation squares independently, retaining empty loose boundaries.
hParallel
  :: (Representable f, Representable g, Representable h, Representable i)
  => Sq Nil Nil (f ::: Nil) (g ::: Nil)
  -> Sq Nil Nil (h ::: Nil) (i ::: Nil)
  -> Sq Nil Nil (f :**: h ::: Nil) (g :**: i ::: Nil)
hParallel :: forall {j1 :: Kind} {k1 :: Kind} {j2 :: Kind} {k2 :: Kind}
       (f :: j1 +-> k1) (g :: j1 +-> k1) (h :: j2 +-> k2)
       (i :: j2 +-> k2).
(Representable f, Representable g, Representable h,
 Representable i) =>
Sq Nil Nil (f ::: Nil) (g ::: Nil)
-> Sq Nil Nil (h ::: Nil) (i ::: Nil)
-> Sq Nil Nil ((f :**: h) ::: Nil) ((g :**: i) ::: Nil)
hParallel (Sq Fold (Nil +++ (f ::: Nil)) :~> Fold ((g ::: Nil) +++ Nil)
n) (Sq Fold (Nil +++ (h ::: Nil)) :~> Fold ((i ::: Nil) +++ Nil)
m) = (Fold (Nil +++ ((f :**: h) ::: Nil))
 :~> Fold (((g :**: i) ::: Nil) +++ Nil))
-> Sq Nil Nil ((f :**: h) ::: Nil) ((g :**: i) ::: Nil)
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq (\(f a1 b1
p :**: h a2 b2
q) -> Fold (Nil +++ (f ::: Nil)) a1 b1
-> Fold ((g ::: Nil) +++ Nil) a1 b1
Fold (Nil +++ (f ::: Nil)) :~> Fold ((g ::: Nil) +++ Nil)
n f a1 b1
Fold (Nil +++ (f ::: Nil)) a1 b1
p g a1 b1 -> i a2 b2 -> (:**:) g i '(a1, a2) '(b1, b2)
forall {j1 :: Kind} {k1 :: Kind} {j2 :: Kind} {k2 :: Kind}
       (c :: j1 +-> k1) (a1 :: k1) (b1 :: j1) (d :: j2 +-> k2) (a2 :: k2)
       (b2 :: j2).
c a1 b1 -> d a2 b2 -> (:**:) c d '(a1, a2) '(b1, b2)
:**: Fold (Nil +++ (h ::: Nil)) a2 b2
-> Fold ((i ::: Nil) +++ Nil) a2 b2
Fold (Nil +++ (h ::: Nil)) :~> Fold ((i ::: Nil) +++ Nil)
m h a2 b2
Fold (Nil +++ (h ::: Nil)) a2 b2
q)

-- | The empty square for an object.
--
-- > K-------K
-- > |       |
-- > |       |
-- > |       |
-- > K-------K
object :: (CategoryOf k) => Sq (Nil :: Path k k) Nil Nil Nil
object :: forall (k :: Kind). CategoryOf k => Sq Nil Nil Nil Nil
object = (Fold (Nil +++ Nil) :~> Fold (Nil +++ Nil)) -> Sq Nil Nil Nil Nil
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq Id a b -> Id a b
Fold (Nil +++ Nil) a b -> Fold (Nil +++ Nil) a b
Fold (Nil +++ Nil) :~> Fold (Nil +++ Nil)
forall {k :: Kind} {k1 :: Kind} (p :: k -> k1 -> Kind) (a :: k)
       (b :: k1).
p a b -> p a b
idN

-- | A square between profunctors, with trivial representable legs.
--
-- > K---p---J
-- > |   |   |
-- > |   @   |
-- > |   |   |
-- > K---q---J
vArr :: (Profunctor p, Profunctor q) => p :~> q -> Sq (p ::: Nil) (q ::: Nil) Nil Nil
vArr :: forall {k :: Kind} {i :: Kind} (p :: k +-> i) (q :: k +-> i).
(Profunctor p, Profunctor q) =>
(p :~> q) -> Sq (p ::: Nil) (q ::: Nil) Nil Nil
vArr = (forall (a :: i) (b :: k). p a b -> q a b)
-> Sq (p ::: Nil) (q ::: Nil) Nil Nil
(Fold ((p ::: Nil) +++ Nil) :~> Fold (Nil +++ (q ::: Nil)))
-> Sq (p ::: Nil) (q ::: Nil) Nil Nil
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq

-- | A vertical identity square.
--
-- > J---p---K
-- > |   |   |
-- > |   |   |
-- > |   |   |
-- > J---p---K
vId :: (Profunctor p) => Sq (p ::: Nil) (p ::: Nil) Nil Nil
vId :: forall {k :: Kind} {i :: Kind} (p :: k +-> i).
Profunctor p =>
Sq (p ::: Nil) (p ::: Nil) Nil Nil
vId = (p :~> p) -> Sq (p ::: Nil) (p ::: Nil) Nil Nil
forall {k :: Kind} {i :: Kind} (p :: k +-> i) (q :: k +-> i).
(Profunctor p, Profunctor q) =>
(p :~> q) -> Sq (p ::: Nil) (q ::: Nil) Nil Nil
vArr p a b -> p a b
p :~> p
forall {k :: Kind} {k1 :: Kind} (p :: k -> k1 -> Kind) (a :: k)
       (b :: k1).
p a b -> p a b
idN

-- | A square between representable profunctors, with trivial profunctor legs.
--
-- > J-------J
-- > |       |
-- > f>--@-->g
-- > |       |
-- > K-------K
hArr :: (Representable f, Representable g) => f :~> g -> Sq Nil Nil (f ::: Nil) (g ::: Nil)
hArr :: forall {j :: Kind} {k :: Kind} (f :: j +-> k) (g :: j +-> k).
(Representable f, Representable g) =>
(f :~> g) -> Sq Nil Nil (f ::: Nil) (g ::: Nil)
hArr = (forall (a :: k) (b :: j). f a b -> g a b)
-> Sq Nil Nil (f ::: Nil) (g ::: Nil)
(Fold (Nil +++ (f ::: Nil)) :~> Fold ((g ::: Nil) +++ Nil))
-> Sq Nil Nil (f ::: Nil) (g ::: Nil)
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq

-- | A horizontal identity square.
--
-- > J-------J
-- > |       |
-- > f>----->f
-- > |       |
-- > K-------K
hId :: (Representable f) => Sq Nil Nil (f ::: Nil) (f ::: Nil)
hId :: forall {j :: Kind} {k :: Kind} (f :: j +-> k).
Representable f =>
Sq Nil Nil (f ::: Nil) (f ::: Nil)
hId = (f :~> f) -> Sq Nil Nil (f ::: Nil) (f ::: Nil)
forall {j :: Kind} {k :: Kind} (f :: j +-> k) (g :: j +-> k).
(Representable f, Representable g) =>
(f :~> g) -> Sq Nil Nil (f ::: Nil) (g ::: Nil)
hArr f a b -> f a b
f :~> f
forall {k :: Kind} {k1 :: Kind} (p :: k -> k1 -> Kind) (a :: k)
       (b :: k1).
p a b -> p a b
idN

-- | Re-encode equivalent horizontal functor paths with the same object action.
-- Naturality requires the represented functors to agree on arrows as well.
-- The reverse re-encoding is its inverse, by the representability laws.
hReencode
  :: forall {j} {k} (fs :: Path j k) (gs :: Path j k)
   . (IsTight fs, IsTight gs, SameRep (Fold fs) (Fold gs))
  => Sq Nil Nil fs gs
hReencode :: forall {j :: Kind} {k :: Kind} (fs :: Path j k) (gs :: Path j k).
(IsTight fs, IsTight gs, SameRep (Fold fs) (Fold gs)) =>
Sq Nil Nil fs gs
hReencode =
  SPath 'Tight fs
-> (Representable (Fold fs) => Sq Nil Nil fs gs)
-> Sq Nil Nil fs gs
forall {j :: Kind} {k :: Kind} (ps :: Path j k) (r :: Kind).
SPath 'Tight ps -> (Representable (Fold ps) => r) -> r
withFoldRep (SPath 'Tight fs
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath :: SPath Tight fs) ((Representable (Fold fs) => Sq Nil Nil fs gs) -> Sq Nil Nil fs gs)
-> (Representable (Fold fs) => Sq Nil Nil fs gs)
-> Sq Nil Nil fs gs
forall a b. (a -> b) -> a -> b
$
    SPath 'Tight gs
-> (Representable (Fold gs) => Sq Nil Nil fs gs)
-> Sq Nil Nil fs gs
forall {j :: Kind} {k :: Kind} (ps :: Path j k) (r :: Kind).
SPath 'Tight ps -> (Representable (Fold ps) => r) -> r
withFoldRep (SPath 'Tight gs
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath :: SPath Tight gs) ((Representable (Fold gs) => Sq Nil Nil fs gs) -> Sq Nil Nil fs gs)
-> (Representable (Fold gs) => Sq Nil Nil fs gs)
-> Sq Nil Nil fs gs
forall a b. (a -> b) -> a -> b
$
      (Fold (Nil +++ fs) :~> Fold (gs +++ Nil)) -> Sq Nil Nil fs gs
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq (\(Fold fs a b
p :: Fold fs a b) -> Fold fs a b
p Fold fs a b -> ((Ob a, Ob b) => Fold gs a b) -> Fold gs 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
// forall {j :: Kind} {k :: Kind} (p :: j +-> k) (q :: j +-> k)
       (a :: j) (r :: Kind).
SameRepAt p q a =>
(((p % a) ~ (q % a)) => r) -> r
forall (p :: j +-> k) (q :: j +-> k) (a :: j) (r :: Kind).
SameRepAt p q a =>
(((p % a) ~ (q % a)) => r) -> r
withSameRepAt @(Fold fs) @(Fold gs) @b ((a ~> (Fold gs % b)) -> Fold gs a b
forall (b :: j) (a :: k).
Ob b =>
(a ~> (Fold gs % b)) -> Fold gs a b
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (b :: j) (a :: k).
(Representable p, Ob b) =>
(a ~> (p % b)) -> p a b
tabulate (Fold fs a b -> a ~> (Fold fs % b)
forall (a :: k) (b :: j). Fold fs a b -> a ~> (Fold fs % b)
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (a :: k) (b :: j).
Representable p =>
p a b -> a ~> (p % b)
index Fold fs a b
p)))

-- | Horizontal composition, with the left square first. Profunctor paths concatenate
-- from right to left, matching the order of profunctor composition.
--
-- > H--p--L--r--M       H--r+p--M
-- > |     |     |       |       |
-- > f--@--g--@--e   =   f---@---e
-- > |     |     |       |       |
-- > I--q--J--s--K       I--s+q--K
(|||) :: forall ps qs fs gs rs ss es. Sq ps qs fs gs -> Sq rs ss gs es -> Sq (rs +++ ps) (ss +++ qs) fs es
Sq Fold (ps +++ fs) :~> Fold (gs +++ qs)
l ||| :: forall {b :: Kind} {h :: Kind} {b :: Kind} {i :: Kind} {j :: Kind}
       {k :: Kind} (ps :: Path b h) (qs :: Path b i) (fs :: Path h i)
       (gs :: Path b b) (rs :: Path j b) (ss :: Path k b)
       (es :: Path j k).
Sq ps qs fs gs
-> Sq rs ss gs es -> Sq (rs +++ ps) (ss +++ qs) fs es
||| Sq Fold (rs +++ gs) :~> Fold (es +++ ss)
r =
  forall {j :: Kind} {b :: Kind} {k :: Kind} (t :: Tag)
       (ps :: Path j b) (qs :: Path b k) (r :: Kind).
IsOb t qs =>
SPath t ps -> (IsOb t (ps +++ qs) => r) -> r
forall (t :: Tag) (ps :: Path j b) (qs :: Path b h) (r :: Kind).
IsOb t qs =>
SPath t ps -> (IsOb t (ps +++ qs) => r) -> r
withObAppend @Loose @rs @ps SPath 'Loose rs
srs ((IsOb 'Loose (rs +++ ps) => Sq (rs +++ ps) (ss +++ qs) fs es)
 -> Sq (rs +++ ps) (ss +++ qs) fs es)
-> (IsOb 'Loose (rs +++ ps) => Sq (rs +++ ps) (ss +++ qs) fs es)
-> Sq (rs +++ ps) (ss +++ qs) fs es
forall a b. (a -> b) -> a -> b
$
    forall {j :: Kind} {b :: Kind} {k :: Kind} (t :: Tag)
       (ps :: Path j b) (qs :: Path b k) (r :: Kind).
IsOb t qs =>
SPath t ps -> (IsOb t (ps +++ qs) => r) -> r
forall (t :: Tag) (ps :: Path k b) (qs :: Path b i) (r :: Kind).
IsOb t qs =>
SPath t ps -> (IsOb t (ps +++ qs) => r) -> r
withObAppend @Loose @ss @qs SPath 'Loose ss
sss ((IsOb 'Loose (ss +++ qs) => Sq (rs +++ ps) (ss +++ qs) fs es)
 -> Sq (rs +++ ps) (ss +++ qs) fs es)
-> (IsOb 'Loose (ss +++ qs) => Sq (rs +++ ps) (ss +++ qs) fs es)
-> Sq (rs +++ ps) (ss +++ qs) fs es
forall a b. (a -> b) -> a -> b
$
      forall {a1 :: Kind} {a2 :: Kind} {b :: Kind} {c :: Kind}
       (ps :: Path a1 a2) (qs :: Path a2 b) (rs :: Path b c) (t :: Tag)
       (r :: Kind).
IsOb t ps =>
(Assoc ps qs rs => r) -> r
forall (ps :: Path j k) (qs :: Path k b) (rs :: Path b i)
       (t :: Tag) (r :: Kind).
IsOb t ps =>
(Assoc ps qs rs => r) -> r
withAssoc @es @ss @qs @Tight ((Assoc es ss qs => Sq (rs +++ ps) (ss +++ qs) fs es)
 -> Sq (rs +++ ps) (ss +++ qs) fs es)
-> (Assoc es ss qs => Sq (rs +++ ps) (ss +++ qs) fs es)
-> Sq (rs +++ ps) (ss +++ qs) fs es
forall a b. (a -> b) -> a -> b
$
        forall {a1 :: Kind} {a2 :: Kind} {b :: Kind} {c :: Kind}
       (ps :: Path a1 a2) (qs :: Path a2 b) (rs :: Path b c) (t :: Tag)
       (r :: Kind).
IsOb t ps =>
(Assoc ps qs rs => r) -> r
forall (ps :: Path j b) (qs :: Path b h) (rs :: Path h i)
       (t :: Tag) (r :: Kind).
IsOb t ps =>
(Assoc ps qs rs => r) -> r
withAssoc @rs @ps @fs @Loose ((Assoc rs ps fs => Sq (rs +++ ps) (ss +++ qs) fs es)
 -> Sq (rs +++ ps) (ss +++ qs) fs es)
-> (Assoc rs ps fs => Sq (rs +++ ps) (ss +++ qs) fs es)
-> Sq (rs +++ ps) (ss +++ qs) fs es
forall a b. (a -> b) -> a -> b
$
          forall {a1 :: Kind} {a2 :: Kind} {b :: Kind} {c :: Kind}
       (ps :: Path a1 a2) (qs :: Path a2 b) (rs :: Path b c) (t :: Tag)
       (r :: Kind).
IsOb t ps =>
(Assoc ps qs rs => r) -> r
forall (ps :: Path j b) (qs :: Path b b) (rs :: Path b i)
       (t :: Tag) (r :: Kind).
IsOb t ps =>
(Assoc ps qs rs => r) -> r
withAssoc @rs @gs @qs @Loose ((Assoc rs gs qs => Sq (rs +++ ps) (ss +++ qs) fs es)
 -> Sq (rs +++ ps) (ss +++ qs) fs es)
-> (Assoc rs gs qs => Sq (rs +++ ps) (ss +++ qs) fs es)
-> Sq (rs +++ ps) (ss +++ qs) fs es
forall a b. (a -> b) -> a -> b
$
            (Fold ((rs +++ ps) +++ fs) :~> Fold (es +++ (ss +++ qs)))
-> Sq (rs +++ ps) (ss +++ qs) fs es
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq ((Fold ((rs +++ ps) +++ fs) :~> Fold (es +++ (ss +++ qs)))
 -> Sq (rs +++ ps) (ss +++ qs) fs es)
-> (Fold ((rs +++ ps) +++ fs) :~> Fold (es +++ (ss +++ qs)))
-> Sq (rs +++ ps) (ss +++ qs) fs es
forall a b. (a -> b) -> a -> b
$
              SPath 'Loose (rs +++ gs)
-> SPath 'Loose (es +++ ss)
-> SPath 'Loose qs
-> (Fold (rs +++ gs) :~> Fold (es +++ ss))
-> Fold ((rs +++ gs) +++ qs) :~> Fold ((es +++ ss) +++ qs)
forall {j :: Kind} {b :: Kind} {k :: Kind} (xs :: Path j b)
       (ys :: Path j b) (zs :: Path b k).
SPath 'Loose xs
-> SPath 'Loose ys
-> SPath 'Loose zs
-> (Fold xs :~> Fold ys)
-> Fold (xs +++ zs) :~> Fold (ys +++ zs)
whiskerR (SPath 'Loose rs -> SPath 'Loose gs -> SPath 'Loose (rs +++ gs)
forall {a :: Kind} {b1 :: Kind} {b2 :: Kind} (t :: Tag)
       (ps :: Path a b1) (qs :: Path b1 b2).
SPath t ps -> SPath t qs -> SPath t (ps +++ qs)
appendPath SPath 'Loose rs
srs SPath 'Loose gs
sgs) (SPath 'Loose es -> SPath 'Loose ss -> SPath 'Loose (es +++ ss)
forall {a :: Kind} {b1 :: Kind} {b2 :: Kind} (t :: Tag)
       (ps :: Path a b1) (qs :: Path b1 b2).
SPath t ps -> SPath t qs -> SPath t (ps +++ qs)
appendPath SPath 'Loose es
ses SPath 'Loose ss
sss) SPath 'Loose qs
sqs Fold (rs +++ gs) a b -> Fold (es +++ ss) a b
Fold (rs +++ gs) :~> Fold (es +++ ss)
r
                (Fold ((rs +++ gs) +++ qs) a b -> Fold (es +++ (ss +++ qs)) a b)
-> (Fold (rs +++ (ps +++ fs)) a b -> Fold ((rs +++ gs) +++ qs) a b)
-> Fold (rs +++ (ps +++ fs)) a b
-> Fold (es +++ (ss +++ qs)) a b
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
. SPath 'Loose rs
-> SPath 'Loose (ps +++ fs)
-> SPath 'Loose (gs +++ qs)
-> (Fold (ps +++ fs) :~> Fold (gs +++ qs))
-> Fold (rs +++ (ps +++ fs)) :~> Fold (rs +++ (gs +++ qs))
forall {j :: Kind} {b :: Kind} {k :: Kind} (xs :: Path j b)
       (ys :: Path b k) (zs :: Path b k).
SPath 'Loose xs
-> SPath 'Loose ys
-> SPath 'Loose zs
-> (Fold ys :~> Fold zs)
-> Fold (xs +++ ys) :~> Fold (xs +++ zs)
whiskerL SPath 'Loose rs
srs (SPath 'Loose ps -> SPath 'Loose fs -> SPath 'Loose (ps +++ fs)
forall {a :: Kind} {b1 :: Kind} {b2 :: Kind} (t :: Tag)
       (ps :: Path a b1) (qs :: Path b1 b2).
SPath t ps -> SPath t qs -> SPath t (ps +++ qs)
appendPath SPath 'Loose ps
sps SPath 'Loose fs
sfs) (SPath 'Loose gs -> SPath 'Loose qs -> SPath 'Loose (gs +++ qs)
forall {a :: Kind} {b1 :: Kind} {b2 :: Kind} (t :: Tag)
       (ps :: Path a b1) (qs :: Path b1 b2).
SPath t ps -> SPath t qs -> SPath t (ps +++ qs)
appendPath SPath 'Loose gs
sgs SPath 'Loose qs
sqs) Fold (ps +++ fs) a b -> Fold (gs +++ qs) a b
Fold (ps +++ fs) :~> Fold (gs +++ qs)
l
  where
    srs :: SPath Loose rs
    srs :: SPath 'Loose rs
srs = SPath 'Loose rs
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    sss :: SPath Loose ss
    sss :: SPath 'Loose ss
sss = SPath 'Loose ss
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    sps :: SPath Loose ps
    sps :: SPath 'Loose ps
sps = SPath 'Loose ps
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    sqs :: SPath Loose qs
    sqs :: SPath 'Loose qs
sqs = SPath 'Loose qs
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    sfs :: SPath Loose fs
    sfs :: SPath 'Loose fs
sfs = SPath 'Tight fs -> SPath 'Loose fs
forall {a :: Kind} {b :: Kind} (ps :: Path a b).
SPath 'Tight ps -> SPath 'Loose ps
weakenTight SPath 'Tight fs
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    sgs :: SPath Loose gs
    sgs :: SPath 'Loose gs
sgs = SPath 'Tight gs -> SPath 'Loose gs
forall {a :: Kind} {b :: Kind} (ps :: Path a b).
SPath 'Tight ps -> SPath 'Loose ps
weakenTight SPath 'Tight gs
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    ses :: SPath Loose es
    ses :: SPath 'Loose es
ses = SPath 'Tight es -> SPath 'Loose es
forall {a :: Kind} {b :: Kind} (ps :: Path a b).
SPath 'Tight ps -> SPath 'Loose ps
weakenTight SPath 'Tight es
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath

-- | Vertical composition, with the top square first.
--
-- > L---p---M       L---p---M
-- > |       |       |       |
-- > d---@---e       |       |
-- > |       |       |       |
-- > H---q---J   =  d+f--@--e+g
-- > |       |       |       |
-- > f---@---g       |       |
-- > |       |       |       |
-- > I---r---K       I---r---K
(===) :: forall ps qs rs ds es fs gs. Sq ps qs ds es -> Sq qs rs fs gs -> Sq ps rs (ds +++ fs) (es +++ gs)
Sq Fold (ps +++ ds) :~> Fold (es +++ qs)
top === :: forall {a :: Kind} {a :: Kind} {b :: Kind} {b :: Kind} {c :: Kind}
       {c :: Kind} (ps :: Path a a) (qs :: Path b b) (rs :: Path c c)
       (ds :: Path a b) (es :: Path a b) (fs :: Path b c)
       (gs :: Path b c).
Sq ps qs ds es
-> Sq qs rs fs gs -> Sq ps rs (ds +++ fs) (es +++ gs)
=== Sq Fold (qs +++ fs) :~> Fold (gs +++ rs)
bot =
  forall {j :: Kind} {b :: Kind} {k :: Kind} (t :: Tag)
       (ps :: Path j b) (qs :: Path b k) (r :: Kind).
IsOb t qs =>
SPath t ps -> (IsOb t (ps +++ qs) => r) -> r
forall (t :: Tag) (ps :: Path a b) (qs :: Path b c) (r :: Kind).
IsOb t qs =>
SPath t ps -> (IsOb t (ps +++ qs) => r) -> r
withObAppend @Tight @ds @fs SPath 'Tight ds
tds ((IsOb 'Tight (ds +++ fs) => Sq ps rs (ds +++ fs) (es +++ gs))
 -> Sq ps rs (ds +++ fs) (es +++ gs))
-> (IsOb 'Tight (ds +++ fs) => Sq ps rs (ds +++ fs) (es +++ gs))
-> Sq ps rs (ds +++ fs) (es +++ gs)
forall a b. (a -> b) -> a -> b
$
    forall {j :: Kind} {b :: Kind} {k :: Kind} (t :: Tag)
       (ps :: Path j b) (qs :: Path b k) (r :: Kind).
IsOb t qs =>
SPath t ps -> (IsOb t (ps +++ qs) => r) -> r
forall (t :: Tag) (ps :: Path a b) (qs :: Path b c) (r :: Kind).
IsOb t qs =>
SPath t ps -> (IsOb t (ps +++ qs) => r) -> r
withObAppend @Tight @es @gs SPath 'Tight es
tes ((IsOb 'Tight (es +++ gs) => Sq ps rs (ds +++ fs) (es +++ gs))
 -> Sq ps rs (ds +++ fs) (es +++ gs))
-> (IsOb 'Tight (es +++ gs) => Sq ps rs (ds +++ fs) (es +++ gs))
-> Sq ps rs (ds +++ fs) (es +++ gs)
forall a b. (a -> b) -> a -> b
$
      forall {a1 :: Kind} {a2 :: Kind} {b :: Kind} {c :: Kind}
       (ps :: Path a1 a2) (qs :: Path a2 b) (rs :: Path b c) (t :: Tag)
       (r :: Kind).
IsOb t ps =>
(Assoc ps qs rs => r) -> r
forall (ps :: Path a a) (qs :: Path a b) (rs :: Path b c)
       (t :: Tag) (r :: Kind).
IsOb t ps =>
(Assoc ps qs rs => r) -> r
withAssoc @ps @ds @fs @Loose ((Assoc ps ds fs => Sq ps rs (ds +++ fs) (es +++ gs))
 -> Sq ps rs (ds +++ fs) (es +++ gs))
-> (Assoc ps ds fs => Sq ps rs (ds +++ fs) (es +++ gs))
-> Sq ps rs (ds +++ fs) (es +++ gs)
forall a b. (a -> b) -> a -> b
$
        forall {a1 :: Kind} {a2 :: Kind} {b :: Kind} {c :: Kind}
       (ps :: Path a1 a2) (qs :: Path a2 b) (rs :: Path b c) (t :: Tag)
       (r :: Kind).
IsOb t ps =>
(Assoc ps qs rs => r) -> r
forall (ps :: Path a b) (qs :: Path b b) (rs :: Path b c)
       (t :: Tag) (r :: Kind).
IsOb t ps =>
(Assoc ps qs rs => r) -> r
withAssoc @es @qs @fs @Tight ((Assoc es qs fs => Sq ps rs (ds +++ fs) (es +++ gs))
 -> Sq ps rs (ds +++ fs) (es +++ gs))
-> (Assoc es qs fs => Sq ps rs (ds +++ fs) (es +++ gs))
-> Sq ps rs (ds +++ fs) (es +++ gs)
forall a b. (a -> b) -> a -> b
$
          forall {a1 :: Kind} {a2 :: Kind} {b :: Kind} {c :: Kind}
       (ps :: Path a1 a2) (qs :: Path a2 b) (rs :: Path b c) (t :: Tag)
       (r :: Kind).
IsOb t ps =>
(Assoc ps qs rs => r) -> r
forall (ps :: Path a b) (qs :: Path b c) (rs :: Path c c)
       (t :: Tag) (r :: Kind).
IsOb t ps =>
(Assoc ps qs rs => r) -> r
withAssoc @es @gs @rs @Tight ((Assoc es gs rs => Sq ps rs (ds +++ fs) (es +++ gs))
 -> Sq ps rs (ds +++ fs) (es +++ gs))
-> (Assoc es gs rs => Sq ps rs (ds +++ fs) (es +++ gs))
-> Sq ps rs (ds +++ fs) (es +++ gs)
forall a b. (a -> b) -> a -> b
$
            (Fold (ps +++ (ds +++ fs)) :~> Fold ((es +++ gs) +++ rs))
-> Sq ps rs (ds +++ fs) (es +++ gs)
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq ((Fold (ps +++ (ds +++ fs)) :~> Fold ((es +++ gs) +++ rs))
 -> Sq ps rs (ds +++ fs) (es +++ gs))
-> (Fold (ps +++ (ds +++ fs)) :~> Fold ((es +++ gs) +++ rs))
-> Sq ps rs (ds +++ fs) (es +++ gs)
forall a b. (a -> b) -> a -> b
$
              SPath 'Loose es
-> SPath 'Loose (qs +++ fs)
-> SPath 'Loose (gs +++ rs)
-> (Fold (qs +++ fs) :~> Fold (gs +++ rs))
-> Fold (es +++ (qs +++ fs)) :~> Fold (es +++ (gs +++ rs))
forall {j :: Kind} {b :: Kind} {k :: Kind} (xs :: Path j b)
       (ys :: Path b k) (zs :: Path b k).
SPath 'Loose xs
-> SPath 'Loose ys
-> SPath 'Loose zs
-> (Fold ys :~> Fold zs)
-> Fold (xs +++ ys) :~> Fold (xs +++ zs)
whiskerL SPath 'Loose es
ses (SPath 'Loose qs -> SPath 'Loose fs -> SPath 'Loose (qs +++ fs)
forall {a :: Kind} {b1 :: Kind} {b2 :: Kind} (t :: Tag)
       (ps :: Path a b1) (qs :: Path b1 b2).
SPath t ps -> SPath t qs -> SPath t (ps +++ qs)
appendPath SPath 'Loose qs
sqs SPath 'Loose fs
sfs) (SPath 'Loose gs -> SPath 'Loose rs -> SPath 'Loose (gs +++ rs)
forall {a :: Kind} {b1 :: Kind} {b2 :: Kind} (t :: Tag)
       (ps :: Path a b1) (qs :: Path b1 b2).
SPath t ps -> SPath t qs -> SPath t (ps +++ qs)
appendPath SPath 'Loose gs
sgs SPath 'Loose rs
srs) Fold (qs +++ fs) a b -> Fold (gs +++ rs) a b
Fold (qs +++ fs) :~> Fold (gs +++ rs)
bot
                (Fold (es +++ (qs +++ fs)) a b -> Fold (es +++ (gs +++ rs)) a b)
-> (Fold (ps +++ (ds +++ fs)) a b -> Fold (es +++ (qs +++ fs)) a b)
-> Fold (ps +++ (ds +++ fs)) a b
-> Fold (es +++ (gs +++ rs)) a b
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
. SPath 'Loose (ps +++ ds)
-> SPath 'Loose (es +++ qs)
-> SPath 'Loose fs
-> (Fold (ps +++ ds) :~> Fold (es +++ qs))
-> Fold ((ps +++ ds) +++ fs) :~> Fold ((es +++ qs) +++ fs)
forall {j :: Kind} {b :: Kind} {k :: Kind} (xs :: Path j b)
       (ys :: Path j b) (zs :: Path b k).
SPath 'Loose xs
-> SPath 'Loose ys
-> SPath 'Loose zs
-> (Fold xs :~> Fold ys)
-> Fold (xs +++ zs) :~> Fold (ys +++ zs)
whiskerR (SPath 'Loose ps -> SPath 'Loose ds -> SPath 'Loose (ps +++ ds)
forall {a :: Kind} {b1 :: Kind} {b2 :: Kind} (t :: Tag)
       (ps :: Path a b1) (qs :: Path b1 b2).
SPath t ps -> SPath t qs -> SPath t (ps +++ qs)
appendPath SPath 'Loose ps
sps SPath 'Loose ds
sds) (SPath 'Loose es -> SPath 'Loose qs -> SPath 'Loose (es +++ qs)
forall {a :: Kind} {b1 :: Kind} {b2 :: Kind} (t :: Tag)
       (ps :: Path a b1) (qs :: Path b1 b2).
SPath t ps -> SPath t qs -> SPath t (ps +++ qs)
appendPath SPath 'Loose es
ses SPath 'Loose qs
sqs) SPath 'Loose fs
sfs Fold (ps +++ ds) a b -> Fold (es +++ qs) a b
Fold (ps +++ ds) :~> Fold (es +++ qs)
top
  where
    tds :: SPath Tight ds
    tds :: SPath 'Tight ds
tds = SPath 'Tight ds
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    tes :: SPath Tight es
    tes :: SPath 'Tight es
tes = SPath 'Tight es
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    sps :: SPath Loose ps
    sps :: SPath 'Loose ps
sps = SPath 'Loose ps
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    sqs :: SPath Loose qs
    sqs :: SPath 'Loose qs
sqs = SPath 'Loose qs
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    srs :: SPath Loose rs
    srs :: SPath 'Loose rs
srs = SPath 'Loose rs
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    sds :: SPath Loose ds
    sds :: SPath 'Loose ds
sds = SPath 'Tight ds -> SPath 'Loose ds
forall {a :: Kind} {b :: Kind} (ps :: Path a b).
SPath 'Tight ps -> SPath 'Loose ps
weakenTight SPath 'Tight ds
tds
    ses :: SPath Loose es
    ses :: SPath 'Loose es
ses = SPath 'Tight es -> SPath 'Loose es
forall {a :: Kind} {b :: Kind} (ps :: Path a b).
SPath 'Tight ps -> SPath 'Loose ps
weakenTight SPath 'Tight es
tes
    sfs :: SPath Loose fs
    sfs :: SPath 'Loose fs
sfs = SPath 'Tight fs -> SPath 'Loose fs
forall {a :: Kind} {b :: Kind} (ps :: Path a b).
SPath 'Tight ps -> SPath 'Loose ps
weakenTight SPath 'Tight fs
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath
    sgs :: SPath Loose gs
    sgs :: SPath 'Loose gs
sgs = SPath 'Tight gs -> SPath 'Loose gs
forall {a :: Kind} {b :: Kind} (ps :: Path a b).
SPath 'Tight ps -> SPath 'Loose ps
weakenTight SPath 'Tight gs
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath

-- | Bend a representable profunctor from the left edge to its companion on the bottom edge.
--
-- > J-------J
-- > |       |
-- > f>--\   |
-- > |   v   |
-- > K---f---J
toBottom :: (Representable f) => Sq Nil (f ::: Nil) (f ::: Nil) Nil
toBottom :: forall {h :: Kind} {k :: Kind} (f :: h +-> k).
Representable f =>
Sq Nil (f ::: Nil) (f ::: Nil) Nil
toBottom = (Fold (Nil +++ (f ::: Nil)) :~> Fold (Nil +++ (f ::: Nil)))
-> Sq Nil (f ::: Nil) (f ::: Nil) Nil
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq f a b -> f a b
Fold (Nil +++ (f ::: Nil)) a b -> Fold (Nil +++ (f ::: Nil)) a b
Fold (Nil +++ (f ::: Nil)) :~> Fold (Nil +++ (f ::: Nil))
forall {k :: Kind} {k1 :: Kind} (p :: k -> k1 -> Kind) (a :: k)
       (b :: k1).
p a b -> p a b
idN

-- | Bend a representable profunctor from the left edge to its conjoint on the top edge.
--
-- > J---f---K
-- > |   ^   |
-- > f>--/   |
-- > |       |
-- > K-------K
toTop :: forall f f'. (Proadjunction f f', Representable f) => Sq (f' ::: Nil) Nil (f ::: Nil) Nil
toTop :: forall {j :: Kind} {i :: Kind} (f :: j +-> i) (f' :: i +-> j).
(Proadjunction f f', Representable f) =>
Sq (f' ::: Nil) Nil (f ::: Nil) Nil
toTop = (Fold ((f' ::: Nil) +++ (f ::: Nil)) :~> Fold (Nil +++ Nil))
-> Sq (f' ::: Nil) Nil (f ::: Nil) Nil
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq (forall {j :: Kind} {k1 :: Kind} (p :: j +-> k1) (q :: k1 +-> j).
Proadjunction p q =>
(p :.: q) :~> Id
forall (p :: j +-> i) (q :: i +-> j).
Proadjunction p q =>
(p :.: q) :~> Id
counitNat @f @f')

-- | Bend a companion from the top edge back to a representable profunctor on the right edge.
--
-- > K---f---J
-- > |   v   |
-- > |   \-->f
-- > |       |
-- > K-------K
fromTop :: (Representable f) => Sq (f ::: Nil) Nil Nil (f ::: Nil)
fromTop :: forall {j :: Kind} {k :: Kind} (f :: j +-> k).
Representable f =>
Sq (f ::: Nil) Nil Nil (f ::: Nil)
fromTop = (Fold ((f ::: Nil) +++ Nil) :~> Fold ((f ::: Nil) +++ Nil))
-> Sq (f ::: Nil) Nil Nil (f ::: Nil)
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq f a b -> f a b
Fold ((f ::: Nil) +++ Nil) a b -> Fold ((f ::: Nil) +++ Nil) a b
Fold ((f ::: Nil) +++ Nil) :~> Fold ((f ::: Nil) +++ Nil)
forall {k :: Kind} {k1 :: Kind} (p :: k -> k1 -> Kind) (a :: k)
       (b :: k1).
p a b -> p a b
idN

-- | Bend a conjoint from the bottom edge back to a representable profunctor on the right edge.
--
-- > J-------J
-- > |       |
-- > |   /-->f
-- > |   ^   |
-- > J---f---K
fromBottom :: forall f f'. (Proadjunction f f', Representable f) => Sq Nil (f' ::: Nil) Nil (f ::: Nil)
fromBottom :: forall {j :: Kind} {k :: Kind} (f :: j +-> k) (f' :: k +-> j).
(Proadjunction f f', Representable f) =>
Sq Nil (f' ::: Nil) Nil (f ::: Nil)
fromBottom = (Fold (Nil +++ Nil) :~> Fold ((f ::: Nil) +++ (f' ::: Nil)))
-> Sq Nil (f' ::: Nil) Nil (f ::: Nil)
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq (forall {k1 :: Kind} {j :: Kind} (p :: k1 +-> j) (q :: j +-> k1).
Proadjunction p q =>
Id :~> (q :.: p)
forall (p :: j +-> k) (q :: k +-> j).
Proadjunction p q =>
Id :~> (q :.: p)
unitNat @f @f')

unitNat :: forall p q. (Proadjunction p q) => Id :~> q :.: p
unitNat :: forall {k1 :: Kind} {j :: Kind} (p :: k1 +-> j) (q :: j +-> k1).
Proadjunction p q =>
Id :~> (q :.: p)
unitNat (Id a ~> b
f) = (a ~> b) -> (:.:) q p a a -> (:.:) q p a b
forall (b :: k1) (d :: k1) (a :: k1).
(b ~> d) -> (:.:) q p a b -> (:.:) q p a d
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (b :: j) (d :: j)
       (a :: k).
Profunctor p =>
(b ~> d) -> p a b -> p a d
rmap a ~> b
f (forall {j :: Kind} {k :: Kind} (p :: j +-> k) (q :: k +-> j)
       (a :: j).
(Proadjunction p q, Ob a) =>
(:.:) q p a a
forall (p :: k1 +-> j) (q :: j +-> k1) (a :: k1).
(Proadjunction p q, Ob a) =>
(:.:) q p a a
Adj.unit @p @q) ((Ob a, Ob b) => (:.:) q p a b) -> (a ~> b) -> (:.:) q p a b
forall (a :: k1) (b :: k1) (r :: Kind).
((Ob a, Ob b) => r) -> (a ~> b) -> r
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (a :: k) (b :: j)
       (r :: Kind).
Profunctor p =>
((Ob a, Ob b) => r) -> p a b -> r
\\ a ~> b
f

counitNat :: forall p q. (Proadjunction p q) => p :.: q :~> Id
counitNat :: forall {j :: Kind} {k1 :: Kind} (p :: j +-> k1) (q :: k1 +-> j).
Proadjunction p q =>
(p :.: q) :~> Id
counitNat (:.:) p q a b
pq = (a ~> b) -> Id a b
forall (k :: Kind) (a :: k) (b :: k). (a ~> b) -> Id a b
Id ((:.:) p q a b -> a ~> b
(p :.: q) :~> (~>)
forall {j :: Kind} {k :: Kind} (p :: j +-> k) (q :: k +-> j).
Proadjunction p q =>
(p :.: q) :~> (~>)
Adj.counit (:.:) p q a b
pq)

-- > K-------K
-- > |       |
-- > I>--@   |
-- > |       |
-- > K-------K
hUnitor :: forall k. (CategoryOf k) => Sq Nil Nil ((Id :: CAT k) ::: Nil) Nil
hUnitor :: forall (k :: Kind). CategoryOf k => Sq Nil Nil (Id ::: Nil) Nil
hUnitor = forall {h :: Kind} {i :: Kind} (fs :: Path h i).
IsTight fs =>
Sq Nil Nil (Fold fs ::: Nil) fs
forall (fs :: Path k k).
IsTight fs =>
Sq Nil Nil (Fold fs ::: Nil) fs
hSplitAll @Nil

-- > K-------K
-- > |       |
-- > |   @-->I
-- > |       |
-- > K-------K
hUnitorInv :: forall k. (CategoryOf k) => Sq Nil Nil Nil ((Id :: CAT k) ::: Nil)
hUnitorInv :: forall (k :: Kind). CategoryOf k => Sq Nil Nil Nil (Id ::: Nil)
hUnitorInv = forall {j :: Kind} {k :: Kind} (fs :: Path j k).
IsTight fs =>
Sq Nil Nil fs (Fold fs ::: Nil)
forall (fs :: Path k k).
IsTight fs =>
Sq Nil Nil fs (Fold fs ::: Nil)
hCombineAll @Nil

-- > I---------I
-- > f>---\    |
-- > |    @->gof
-- > g>---/    |
-- > K---------K
hCombine :: forall f g. (Representable f, Representable g) => Sq Nil Nil (f ::: g ::: Nil) (g :.: f ::: Nil)
hCombine :: forall {j :: Kind} {j :: Kind} {k :: Kind} (f :: j +-> j)
       (g :: j +-> k).
(Representable f, Representable g) =>
Sq Nil Nil (f ::: (g ::: Nil)) ((g :.: f) ::: Nil)
hCombine = forall {j :: Kind} {k :: Kind} (fs :: Path j k).
IsTight fs =>
Sq Nil Nil fs (Fold fs ::: Nil)
forall (fs :: Path j k).
IsTight fs =>
Sq Nil Nil fs (Fold fs ::: Nil)
hCombineAll @(f ::: g ::: Nil)

-- > I---------I
-- > |    /--->f
-- > gof>-@    |
-- > |    \--->g
-- > K---------K
hSplit :: forall f g. (Representable f, Representable g) => Sq Nil Nil (g :.: f ::: Nil) (f ::: g ::: Nil)
hSplit :: forall {j :: Kind} {j :: Kind} {k :: Kind} (f :: j +-> j)
       (g :: j +-> k).
(Representable f, Representable g) =>
Sq Nil Nil ((g :.: f) ::: Nil) (f ::: (g ::: Nil))
hSplit = forall {h :: Kind} {i :: Kind} (fs :: Path h i).
IsTight fs =>
Sq Nil Nil (Fold fs ::: Nil) fs
forall (fs :: Path j k).
IsTight fs =>
Sq Nil Nil (Fold fs ::: Nil) fs
hSplitAll @(f ::: g ::: Nil)

-- | Combine the corepresenting functors of two profunctors into the
-- corepresenting functor of their composite. 'CorepStar' reverses composition.
hCombineCorep
  :: (Corepresentable p, Corepresentable q)
  => Sq Nil Nil (CorepStar p ::: CorepStar q ::: Nil) (CorepStar (p :.: q) ::: Nil)
hCombineCorep :: forall {j :: Kind} {j :: Kind} {k :: Kind} (p :: j +-> j)
       (q :: k +-> j).
(Corepresentable p, Corepresentable q) =>
Sq
  Nil
  Nil
  (CorepStar p ::: (CorepStar q ::: Nil))
  (CorepStar (p :.: q) ::: Nil)
hCombineCorep = Sq
  Nil
  Nil
  (CorepStar p ::: (CorepStar q ::: Nil))
  (CorepStar (p :.: q) ::: Nil)
forall {j :: Kind} {k :: Kind} (fs :: Path j k) (gs :: Path j k).
(IsTight fs, IsTight gs, SameRep (Fold fs) (Fold gs)) =>
Sq Nil Nil fs gs
hReencode

-- | Split the corepresenting functor of a composite. Inverse to 'hCombineCorep'.
hSplitCorep
  :: (Corepresentable p, Corepresentable q)
  => Sq Nil Nil (CorepStar (p :.: q) ::: Nil) (CorepStar p ::: CorepStar q ::: Nil)
hSplitCorep :: forall {j :: Kind} {j :: Kind} {k :: Kind} (p :: j +-> j)
       (q :: k +-> j).
(Corepresentable p, Corepresentable q) =>
Sq
  Nil
  Nil
  (CorepStar (p :.: q) ::: Nil)
  (CorepStar p ::: (CorepStar q ::: Nil))
hSplitCorep = Sq
  Nil
  Nil
  (CorepStar (p :.: q) ::: Nil)
  (CorepStar p ::: (CorepStar q ::: Nil))
forall {j :: Kind} {k :: Kind} (fs :: Path j k) (gs :: Path j k).
(IsTight fs, IsTight gs, SameRep (Fold fs) (Fold gs)) =>
Sq Nil Nil fs gs
hReencode

-- | Combine a path of representable profunctors into one composed representable profunctor.
--
-- > J---------J
-- > f>---\    |
-- > |    @--->F
-- > g>---/    |
-- > K---------K
hCombineAll :: forall fs. (IsTight fs) => Sq Nil Nil fs (Fold fs ::: Nil)
hCombineAll :: forall {j :: Kind} {k :: Kind} (fs :: Path j k).
IsTight fs =>
Sq Nil Nil fs (Fold fs ::: Nil)
hCombineAll = SPath 'Tight fs
-> (Representable (Fold fs) => Sq Nil Nil fs (Fold fs ::: Nil))
-> Sq Nil Nil fs (Fold fs ::: Nil)
forall {j :: Kind} {k :: Kind} (ps :: Path j k) (r :: Kind).
SPath 'Tight ps -> (Representable (Fold ps) => r) -> r
withFoldRep SPath 'Tight fs
tfs ((Fold (Nil +++ fs) :~> Fold ((Fold fs ::: Nil) +++ Nil))
-> Sq Nil Nil fs (Fold fs ::: Nil)
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq Fold fs a b -> Fold fs a b
Fold (Nil +++ fs) a b -> Fold ((Fold fs ::: Nil) +++ Nil) a b
Fold (Nil +++ fs) :~> Fold ((Fold fs ::: Nil) +++ Nil)
forall {k :: Kind} {k1 :: Kind} (p :: k -> k1 -> Kind) (a :: k)
       (b :: k1).
p a b -> p a b
idN)
  where
    tfs :: SPath Tight fs
    tfs :: SPath 'Tight fs
tfs = SPath 'Tight fs
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath

-- | Split one composed representable profunctor into a path of representable profunctors.
--
-- > J---------J
-- > |    /--->f
-- > F>---@    |
-- > |    \--->g
-- > K---------K
hSplitAll :: forall fs. (IsTight fs) => Sq Nil Nil (Fold fs ::: Nil) fs
hSplitAll :: forall {h :: Kind} {i :: Kind} (fs :: Path h i).
IsTight fs =>
Sq Nil Nil (Fold fs ::: Nil) fs
hSplitAll = SPath 'Tight fs
-> (Representable (Fold fs) => Sq Nil Nil (Fold fs ::: Nil) fs)
-> Sq Nil Nil (Fold fs ::: Nil) fs
forall {j :: Kind} {k :: Kind} (ps :: Path j k) (r :: Kind).
SPath 'Tight ps -> (Representable (Fold ps) => r) -> r
withFoldRep SPath 'Tight fs
tfs ((Fold (Nil +++ (Fold fs ::: Nil)) :~> Fold (fs +++ Nil))
-> Sq Nil Nil (Fold fs ::: Nil) fs
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq Fold fs a b -> Fold fs a b
Fold (Nil +++ (Fold fs ::: Nil)) a b -> Fold (fs +++ Nil) a b
Fold (Nil +++ (Fold fs ::: Nil)) :~> Fold (fs +++ Nil)
forall {k :: Kind} {k1 :: Kind} (p :: k -> k1 -> Kind) (a :: k)
       (b :: k1).
p a b -> p a b
idN)
  where
    tfs :: SPath Tight fs
    tfs :: SPath 'Tight fs
tfs = SPath 'Tight fs
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath

-- > K---I---K
-- > |   |   |
-- > |   @   |
-- > |       |
-- > K-------K
vUnitor :: forall k. (CategoryOf k) => Sq ((Id :: CAT k) ::: Nil) Nil Nil Nil
vUnitor :: forall (k :: Kind). CategoryOf k => Sq (Id ::: Nil) Nil Nil Nil
vUnitor = forall {k :: Kind} {i :: Kind} (ps :: Path k i).
IsPath ps =>
Sq (Fold ps ::: Nil) ps Nil Nil
forall (ps :: Path k k).
IsPath ps =>
Sq (Fold ps ::: Nil) ps Nil Nil
vSplitAll @Nil

-- > K-------K
-- > |       |
-- > |   @   |
-- > |   |   |
-- > K---I---K
vUnitorInv :: forall k. (CategoryOf k) => Sq Nil ((Id :: CAT k) ::: Nil) Nil Nil
vUnitorInv :: forall (k :: Kind). CategoryOf k => Sq Nil (Id ::: Nil) Nil Nil
vUnitorInv = forall {k :: Kind} {i :: Kind} (ps :: Path k i).
IsPath ps =>
Sq ps (Fold ps ::: Nil) Nil Nil
forall (ps :: Path k k).
IsPath ps =>
Sq ps (Fold ps ::: Nil) Nil Nil
vCombineAll @Nil

-- > K-q---p-J
-- > |  \ /  |
-- > |   @   |
-- > |   |   |
-- > K--qop--J
vCombine :: forall p q. (Profunctor p, Profunctor q) => Sq (p ::: q ::: Nil) (q :.: p ::: Nil) Nil Nil
vCombine :: forall {k :: Kind} {j :: Kind} {i :: Kind} (p :: k +-> j)
       (q :: j +-> i).
(Profunctor p, Profunctor q) =>
Sq (p ::: (q ::: Nil)) ((q :.: p) ::: Nil) Nil Nil
vCombine = forall {k :: Kind} {i :: Kind} (ps :: Path k i).
IsPath ps =>
Sq ps (Fold ps ::: Nil) Nil Nil
forall (ps :: Path k i).
IsPath ps =>
Sq ps (Fold ps ::: Nil) Nil Nil
vCombineAll @(p ::: q ::: Nil)

-- > K--qop--J
-- > |   |   |
-- > |   @   |
-- > |  / \  |
-- > K-q---p-J
vSplit :: forall p q. (Profunctor p, Profunctor q) => Sq (q :.: p ::: Nil) (p ::: q ::: Nil) Nil Nil
vSplit :: forall {k :: Kind} {j :: Kind} {i :: Kind} (p :: k +-> j)
       (q :: j +-> i).
(Profunctor p, Profunctor q) =>
Sq ((q :.: p) ::: Nil) (p ::: (q ::: Nil)) Nil Nil
vSplit = forall {k :: Kind} {i :: Kind} (ps :: Path k i).
IsPath ps =>
Sq (Fold ps ::: Nil) ps Nil Nil
forall (ps :: Path k i).
IsPath ps =>
Sq (Fold ps ::: Nil) ps Nil Nil
vSplitAll @(p ::: q ::: Nil)

-- | Combine a path of profunctors into one composed profunctor.
--
-- > K-q---p-J
-- > |  \ /  |
-- > |   @   |
-- > |   |   |
-- > K---F---J
vCombineAll :: forall ps. (IsPath ps) => Sq ps (Fold ps ::: Nil) Nil Nil
vCombineAll :: forall {k :: Kind} {i :: Kind} (ps :: Path k i).
IsPath ps =>
Sq ps (Fold ps ::: Nil) Nil Nil
vCombineAll = SPath 'Loose ps
-> (Profunctor (Fold ps) => Sq ps (Fold ps ::: Nil) Nil Nil)
-> Sq ps (Fold ps ::: Nil) Nil Nil
forall {j :: Kind} {k :: Kind} (ps :: Path j k) (r :: Kind).
SPath 'Loose ps -> (Profunctor (Fold ps) => r) -> r
withFoldOb SPath 'Loose ps
sp ((Fold (ps +++ Nil) :~> Fold (Nil +++ (Fold ps ::: Nil)))
-> Sq ps (Fold ps ::: Nil) Nil Nil
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq Fold ps a b -> Fold ps a b
Fold (ps +++ Nil) a b -> Fold (Nil +++ (Fold ps ::: Nil)) a b
Fold (ps +++ Nil) :~> Fold (Nil +++ (Fold ps ::: Nil))
forall {k :: Kind} {k1 :: Kind} (p :: k -> k1 -> Kind) (a :: k)
       (b :: k1).
p a b -> p a b
idN)
  where
    sp :: SPath Loose ps
    sp :: SPath 'Loose ps
sp = SPath 'Loose ps
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath

-- | Split one composed profunctor into a path of profunctors.
--
-- > K---F---J
-- > |   |   |
-- > |   @   |
-- > |  / \  |
-- > K-q---p-J
vSplitAll :: forall ps. (IsPath ps) => Sq (Fold ps ::: Nil) ps Nil Nil
vSplitAll :: forall {k :: Kind} {i :: Kind} (ps :: Path k i).
IsPath ps =>
Sq (Fold ps ::: Nil) ps Nil Nil
vSplitAll = SPath 'Loose ps
-> (Profunctor (Fold ps) => Sq (Fold ps ::: Nil) ps Nil Nil)
-> Sq (Fold ps ::: Nil) ps Nil Nil
forall {j :: Kind} {k :: Kind} (ps :: Path j k) (r :: Kind).
SPath 'Loose ps -> (Profunctor (Fold ps) => r) -> r
withFoldOb SPath 'Loose ps
sp ((Fold ((Fold ps ::: Nil) +++ Nil) :~> Fold (Nil +++ ps))
-> Sq (Fold ps ::: Nil) ps Nil Nil
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq Fold ps a b -> Fold ps a b
Fold ((Fold ps ::: Nil) +++ Nil) a b -> Fold (Nil +++ ps) a b
Fold ((Fold ps ::: Nil) +++ Nil) :~> Fold (Nil +++ ps)
forall {k :: Kind} {k1 :: Kind} (p :: k -> k1 -> Kind) (a :: k)
       (b :: k1).
p a b -> p a b
idN)
  where
    sp :: SPath Loose ps
    sp :: SPath 'Loose ps
sp = SPath 'Loose ps
forall (j :: Kind) (k :: Kind) (t :: Tag) (ps :: Path j k).
IsOb t ps =>
SPath t ps
singPath

-- | The unit of an adjunction.
--
-- > J-------J
-- > |       |
-- > | /-@-\ |
-- > | |   | |
-- > J-q---p-J
unit :: forall p q. (Proadjunction p q) => Sq Nil (p ::: q ::: Nil) Nil Nil
unit :: forall {i :: Kind} {j :: Kind} (p :: i +-> j) (q :: j +-> i).
Proadjunction p q =>
Sq Nil (p ::: (q ::: Nil)) Nil Nil
unit = (Fold (Nil +++ Nil) :~> Fold (Nil +++ (p ::: (q ::: Nil))))
-> Sq Nil (p ::: (q ::: Nil)) Nil Nil
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq (forall {k1 :: Kind} {j :: Kind} (p :: k1 +-> j) (q :: j +-> k1).
Proadjunction p q =>
Id :~> (q :.: p)
forall (p :: i +-> j) (q :: j +-> i).
Proadjunction p q =>
Id :~> (q :.: p)
unitNat @p @q)

-- | The counit of an adjunction.
--
-- > K-p---q-K
-- > | |   | |
-- > | \-@-/ |
-- > |       |
-- > K-------K
counit :: forall p q. (Proadjunction p q) => Sq (q ::: p ::: Nil) Nil Nil Nil
counit :: forall {j :: Kind} {i :: Kind} (p :: j +-> i) (q :: i +-> j).
Proadjunction p q =>
Sq (q ::: (p ::: Nil)) Nil Nil Nil
counit = (Fold ((q ::: (p ::: Nil)) +++ Nil) :~> Fold (Nil +++ Nil))
-> Sq (q ::: (p ::: Nil)) Nil Nil Nil
forall {j :: Kind} {b :: Kind} {b :: Kind} {k :: Kind}
       (p :: Path j b) (q :: Path b k) (f :: Path b k) (g :: Path j b).
(IsPath p, IsPath q, IsTight f, IsTight g) =>
(Fold (p +++ f) :~> Fold (g +++ q)) -> Sq p q f g
Sq (forall {j :: Kind} {k1 :: Kind} (p :: j +-> k1) (q :: k1 +-> j).
Proadjunction p q =>
(p :.: q) :~> Id
forall (p :: j +-> i) (q :: i +-> j).
Proadjunction p q =>
(p :.: q) :~> Id
counitNat @p @q)

-- | A square introducing an effect @r@ between representable data shapes @f@ and @g@,
-- with no incoming effect. Optics consume and produce squares of this same shape.
--
-- > X-----------X
-- > |           |
-- > f>----@---->g
-- > |     |     |
-- > J-----r-----K
type InputSquare :: (k +-> j) -> (x +-> j) -> (x +-> k) -> Type
type InputSquare r f g = Sq Nil (r ::: Nil) (f ::: Nil) (g ::: Nil)

-- | Absorb a general witness pair around an effect with 'proact'. All three incoming
-- profunctors are vertical or diagonal wires. No representability is required of @p@ or @q@.
--
-- > J--p--r--q--K
-- > |   \ | /   |
-- > |    @@@    |
-- > |     |     |
-- > J-----r-----K
proSquare
  :: forall {j} {k} w (r :: k +-> j) (p :: j +-> j) (q :: k +-> k)
   . (Prostrong w r, w p q, Profunctor p, Profunctor q)
  => Sq (q ::: r ::: p ::: Nil) (r ::: Nil) Nil Nil
proSquare :: forall {j :: Kind} {k :: Kind} (w :: FLAVOR k j) (r :: k +-> j)
       (p :: j +-> j) (q :: k +-> k).
(Prostrong w r, w p q, Profunctor p, Profunctor q) =>
Sq (q ::: (r ::: (p ::: Nil))) (r ::: Nil) Nil Nil
proSquare =
  forall {k :: Kind} {i :: Kind} (ps :: Path k i).
IsPath ps =>
Sq ps (Fold ps ::: Nil) Nil Nil
forall (ps :: Path k j).
IsPath ps =>
Sq ps (Fold ps ::: Nil) Nil Nil
vCombineAll @(q ::: r ::: p ::: Nil)
    Sq (q ::: (r ::: (p ::: Nil))) (((p :.: r) :.: q) ::: Nil) Nil Nil
-> Sq (((p :.: r) :.: q) ::: Nil) (r ::: Nil) Nil Nil
-> Sq
     (q ::: (r ::: (p ::: Nil))) (r ::: Nil) (Nil +++ Nil) (Nil +++ Nil)
forall {a :: Kind} {a :: Kind} {b :: Kind} {b :: Kind} {c :: Kind}
       {c :: Kind} (ps :: Path a a) (qs :: Path b b) (rs :: Path c c)
       (ds :: Path a b) (es :: Path a b) (fs :: Path b c)
       (gs :: Path b c).
Sq ps qs ds es
-> Sq qs rs fs gs -> Sq ps rs (ds +++ fs) (es +++ gs)
=== (((p :.: r) :.: q) :~> r)
-> Sq (((p :.: r) :.: q) ::: Nil) (r ::: Nil) Nil Nil
forall {k :: Kind} {i :: Kind} (p :: k +-> i) (q :: k +-> i).
(Profunctor p, Profunctor q) =>
(p :~> q) -> Sq (p ::: Nil) (q ::: Nil) Nil Nil
vArr (forall {j :: Kind} {k :: Kind} (w :: FLAVOR j k) (p :: j +-> k)
       (f :: k +-> k) (g :: j +-> j).
(Prostrong w p, w f g, Profunctor f, Profunctor g) =>
((f :.: p) :.: g) :~> p
forall (w :: FLAVOR k j) (p :: k +-> j) (f :: j +-> j)
       (g :: k +-> k).
(Prostrong w p, w f g, Profunctor f, Profunctor g) =>
((f :.: p) :.: g) :~> p
proact @w @r @p @q)

-- | An optic between representable data shapes, programmed by composing squares.
-- Its legs @s :~> p :.: a@ and @b :~> q :.: t@ introduce the residual profunctors
-- @p@ and @q@, which are absorbed with the input effect by 'proSquare'. All four
-- data shapes share an index category. Constant shapes from the terminal category
-- recover optics between individual objects.
--
-- Wire names appear on borders; each contiguous run of @\@@ marks one transformation. The top central
-- square is the input, the left square unpacks, and the right square rebuilds. The
-- lower square absorbs their three outgoing effects. Residual profunctors stay
-- vertical or diagonal; only representable data wires run horizontally:
--
-- > X-----+-----+-----X
-- > |     |     |     |
-- > s>-@->a>-@->b>-@->t
-- > |  |  |  |  |  |  |
-- > +--p--+--r--+--q--+
-- > |   \    |    /   |
-- > |    @@@@@@@@@    |
-- > |        |        |
-- > J--------r--------K
--
-- The outer boundary is another input-shaped square, now with data legs @s@ and @t@,
-- so it can be used as the input to another optic.
opticSquare
  :: forall {j} {k} {x} w (r :: k +-> j) (p :: j +-> j) (q :: k +-> k) (s :: x +-> j) (t :: x +-> k) (a :: x +-> j) (b :: x +-> k)
   . (Prostrong w r, w p q, Profunctor p, Profunctor q)
  => InputSquare p s a -> InputSquare q b t -> InputSquare r a b -> InputSquare r s t
opticSquare :: forall {j :: Kind} {k :: Kind} {x :: Kind} (w :: FLAVOR k j)
       (r :: k +-> j) (p :: j +-> j) (q :: k +-> k) (s :: x +-> j)
       (t :: x +-> k) (a :: x +-> j) (b :: x +-> k).
(Prostrong w r, w p q, Profunctor p, Profunctor q) =>
InputSquare p s a
-> InputSquare q b t -> InputSquare r a b -> InputSquare r s t
opticSquare InputSquare p s a
unpack InputSquare q b t
rebuild InputSquare r a b
input =
  InputSquare p s a
unpack InputSquare p s a
-> InputSquare r a b
-> Sq
     (Nil +++ Nil) ((r ::: Nil) +++ (p ::: Nil)) (s ::: Nil) (b ::: Nil)
forall {b :: Kind} {h :: Kind} {b :: Kind} {i :: Kind} {j :: Kind}
       {k :: Kind} (ps :: Path b h) (qs :: Path b i) (fs :: Path h i)
       (gs :: Path b b) (rs :: Path j b) (ss :: Path k b)
       (es :: Path j k).
Sq ps qs fs gs
-> Sq rs ss gs es -> Sq (rs +++ ps) (ss +++ qs) fs es
||| InputSquare r a b
input Sq Nil (r ::: (p ::: Nil)) (s ::: Nil) (b ::: Nil)
-> InputSquare q b t
-> Sq
     (Nil +++ Nil)
     ((q ::: Nil) +++ (r ::: (p ::: Nil)))
     (s ::: Nil)
     (t ::: Nil)
forall {b :: Kind} {h :: Kind} {b :: Kind} {i :: Kind} {j :: Kind}
       {k :: Kind} (ps :: Path b h) (qs :: Path b i) (fs :: Path h i)
       (gs :: Path b b) (rs :: Path j b) (ss :: Path k b)
       (es :: Path j k).
Sq ps qs fs gs
-> Sq rs ss gs es -> Sq (rs +++ ps) (ss +++ qs) fs es
||| InputSquare q b t
rebuild
    Sq Nil (q ::: (r ::: (p ::: Nil))) (s ::: Nil) (t ::: Nil)
-> Sq (q ::: (r ::: (p ::: Nil))) (r ::: Nil) Nil Nil
-> Sq Nil (r ::: Nil) ((s ::: Nil) +++ Nil) ((t ::: Nil) +++ Nil)
forall {a :: Kind} {a :: Kind} {b :: Kind} {b :: Kind} {c :: Kind}
       {c :: Kind} (ps :: Path a a) (qs :: Path b b) (rs :: Path c c)
       (ds :: Path a b) (es :: Path a b) (fs :: Path b c)
       (gs :: Path b c).
Sq ps qs ds es
-> Sq qs rs fs gs -> Sq ps rs (ds +++ fs) (es +++ gs)
=== forall {j :: Kind} {k :: Kind} (w :: FLAVOR k j) (r :: k +-> j)
       (p :: j +-> j) (q :: k +-> k).
(Prostrong w r, w p q, Profunctor p, Profunctor q) =>
Sq (q ::: (r ::: (p ::: Nil))) (r ::: Nil) Nil Nil
forall (w :: FLAVOR k j) (r :: k +-> j) (p :: j +-> j)
       (q :: k +-> k).
(Prostrong w r, w p q, Profunctor p, Profunctor q) =>
Sq (q ::: (r ::: (p ::: Nil))) (r ::: Nil) Nil Nil
proSquare @w