1+ {-# LANGUAGE AllowAmbiguousTypes #-}
2+
13module Proarrow.Category.Bicategory.Adj where
24
5+ import Data.Kind (Constraint , Type )
6+ import Prelude (type (~ ))
7+
38import Proarrow.Category.Bicategory
4- ( Bicategory (.. )
9+ ( Adjunction_ (.. )
10+ , Bicategory (.. )
511 , Comonad (.. )
6- , IsPath (.. )
712 , Monad (.. )
8- , Path (.. )
9- , SPath (.. )
10- , withUnital
11- , type (+++ )
1213 )
14+ import Proarrow.Category.Bicategory qualified as Bi
15+ import Proarrow.Category.Bicategory.Strictified (Assoc , Path (.. ), type (+++ ))
16+ import Proarrow.Category.Equipment (Cotight , CotightAdjoint , Equipment (.. ), IsOb , Tight , TightAdjoint , WithObO2 (.. ))
1317import Proarrow.Category.Instance.Simplex (Nat (.. ), Simplex (.. ))
14- import Proarrow.Core (CAT , CategoryOf (.. ), Is , Profunctor (.. ), Promonad (.. ), UN , dimapDefault )
18+ import Proarrow.Core (CAT , CategoryOf (.. ), Is , Profunctor (.. ), Promonad (.. ), UN , dimapDefault , obj )
1519import Proarrow.Object (src , tgt )
1620
1721type data AB = A | B
@@ -33,9 +37,25 @@ data Adj ps qs where
3337 AdjCup :: Adj (AK ps ) qs -> Adj (AK (R ::: L ::: ps )) qs
3438 AdjCap :: Adj ps (AK qs ) -> Adj ps (AK (L ::: R ::: qs ))
3539
36- class IsRL rl where rOrL :: Adj (AK ps ) (AK qs ) -> Adj (AK (rl ::: ps )) (AK (rl ::: qs ))
37- instance IsRL L where rOrL = AdjL
38- instance IsRL R where rOrL = AdjR
40+ type SAdj :: Path ABK i j -> Type
41+ data SAdj p where
42+ SNil :: SAdj Nil
43+ SL :: (IsLRPath ps ) => SAdj (L ::: ps )
44+ SR :: (IsLRPath ps ) => SAdj (R ::: ps )
45+
46+ type IsLRPath :: forall {i } {j }. Path ABK i j -> Constraint
47+ class (ps +++ Nil ~ ps , forall i h (qs :: Path ABK k h ) (rs :: Path ABK h i ). Assoc ps qs rs ) => IsLRPath (ps :: Path ABK j k ) where
48+ singPath :: SAdj ps
49+ withIsPath2 :: (IsLRPath qs ) => ((IsLRPath (ps +++ qs )) => r ) -> r
50+ instance IsLRPath Nil where
51+ singPath = SNil
52+ withIsPath2 r = r
53+ instance (IsLRPath ps ) => IsLRPath (L ::: ps ) where
54+ singPath = SL
55+ withIsPath2 @ qs r = withIsPath2 @ ps @ qs r
56+ instance (IsLRPath ps ) => IsLRPath (R ::: ps ) where
57+ singPath = SR
58+ withIsPath2 @ qs r = withIsPath2 @ ps @ qs r
3959
4060instance Profunctor (Adj :: CAT (ADJK a b )) where
4161 dimap = dimapDefault
@@ -45,12 +65,12 @@ instance Profunctor (Adj :: CAT (ADJK a b)) where
4565 r \\ AdjCup f = r \\ f
4666 r \\ AdjCap f = r \\ f
4767instance Promonad (Adj :: CAT (ADJK a b )) where
48- id :: forall (ps :: ADJK a b ). (Ob ps ) => Adj ps ps
49- id = go (singPath @ (UN AK ps ))
68+ id @ ps = go (singPath @ (UN AK ps ))
5069 where
51- go :: forall ps' . SPath ps' -> Adj (AK ps' ) (AK ps' )
70+ go :: forall ps' . SAdj ps' -> Adj (AK ps' ) (AK ps' )
5271 go SNil = AdjNil
53- go (SCons @ rl p ps) = rOrL @ rl (go ps) \\ p
72+ go SL = AdjL id
73+ go SR = AdjR id
5474 AdjNil . f = f
5575 f . AdjNil = f
5676 AdjR f . AdjR g = AdjR (f . g)
@@ -64,28 +84,32 @@ instance Promonad (Adj :: CAT (ADJK a b)) where
6484
6585instance CategoryOf (ADJK a b ) where
6686 type (~> ) = Adj
67- type Ob ps = (Is AK ps )
87+ type Ob ps = (Is AK ps , IsLRPath ( UN AK ps ) )
6888
6989-- | The walking adjunction
7090instance Bicategory ADJK where
71- type Ob0 ADJK a = (IsRL a )
7291 type I = AK Nil
73- type ps `O ` qs = AK (UN AK ps +++ UN AK qs )
92+ type ps `O ` qs = AK (UN AK qs +++ UN AK ps )
93+ withOb2 @ ps @ qs k = withIsPath2 @ (UN AK qs ) @ (UN AK ps ) k
94+ withOb0s r = r
7495 r \\\ AdjNil = r
7596 r \\\ AdjR f = r \\\ f
7697 r \\\ AdjL f = r \\\ f
7798 r \\\ AdjCup f = r \\\ f
7899 r \\\ AdjCap f = r \\\ f
79100 o :: forall {a } {b } (ps :: ADJK a b ) qs rs ss . (ps ~> qs ) -> (rs ~> ss ) -> (ps `O ` rs ) ~> (qs `O ` ss )
80- o = o
81- -- AdjNil `o` f = f \\ f
82- -- f `o` AdjNil = f -- withUnital @(UN AK ps) (withUnital @(UN AK qs) f) \\ f
83- -- AdjR f `o` g = AdjR (f `o` g)
84- -- AdjL f `o` g = AdjL (f `o` g)
85- -- AdjCup f `o` g = AdjCup (f `o` g)
86- -- AdjCap f `o` g = AdjCap (f `o` g)
87- leftUnitor AdjNil = AdjNil
88- leftUnitor (AdjR f) = AdjR f
101+ AdjNil `o` f = f \\ f
102+ f `o` AdjNil = f \\ f
103+ f `o` AdjR g = AdjR (f `o` g)
104+ f `o` AdjL g = AdjL (f `o` g)
105+ f `o` AdjCup g = AdjCup (f `o` g)
106+ f `o` AdjCap g = AdjCap (f `o` g)
107+ leftUnitor = id
108+ leftUnitorInv = id
109+ rightUnitor = id
110+ rightUnitorInv = id
111+ associator @ p @ q @ r = obj @ p `o` obj @ q `o` obj @ r
112+ associatorInv @ p @ q @ r = obj @ p `o` obj @ q `o` obj @ r
89113
90114type family RepLR (n :: Nat ) :: Path ABK A A where
91115 RepLR Z = Nil
@@ -141,51 +165,65 @@ toSimplexOp (AdjR f) = go f id
141165 go (AdjL g) xny = xny (X (Y (toSimplexOp g)))
142166 go (AdjCap g) xny = go g (xny . X )
143167
144- instance Monad (AK (L ::: R ::: Nil )) where
145- eta = AdjCap AdjNil
146- mu = AdjL (AdjCup (AdjR AdjNil ))
168+ instance Adjunction_ (AK Nil ) (AK Nil ) where
169+ adj = Bi. Adj AdjNil AdjNil
147170
148- -- instance Comonad (R ::: L ::: Nil) where
149- -- epsilon = AdjCup AdjNil
150- -- delta = AdjR (AdjCap (AdjL AdjNil))
171+ instance Adjunction_ (AK (L ::: Nil )) (AK (R ::: Nil )) where
172+ adj = Bi. Adj {adjUnit = AdjCap AdjNil , adjCounit = AdjCup AdjNil }
151173
152- type ARRK :: CAT AB
153- type data ARRK a b where
154- IDA :: ARRK A A
155- A2B :: ARRK A B
156- IDB :: ARRK B B
174+ instance Adjunction_ (AK (L ::: R ::: L ::: Nil )) (AK (R ::: L ::: R ::: Nil )) where
175+ adj = Bi. Adj {adjUnit = AdjCap (AdjCap (AdjCap AdjNil )), adjCounit = AdjCup (AdjCup (AdjCup AdjNil ))}
157176
158- type Arr :: CAT ( ARRK i j )
159- data Arr a b where
160- ArrId :: ( Ob a ) => Arr a a
177+ instance Monad ( AK ( L ::: R ::: Nil )) where
178+ eta = AdjCap AdjNil
179+ mu = AdjL ( AdjCup ( AdjR AdjNil ))
161180
162- instance Profunctor (Arr :: CAT (ARRK i j )) where
163- dimap = dimapDefault
164- r \\ ArrId = r
165- instance Promonad (Arr :: CAT (ARRK i j )) where
166- id = ArrId
167- ArrId . ArrId = ArrId
168- instance CategoryOf (ARRK i j ) where
169- type (~> ) = Arr
170- type Ob a = ()
171-
172- instance Bicategory ARRK where
173- type Ob0 ARRK a = ()
174- r \\\ ArrId = r
175- ArrId `o` ArrId = _
176-
177- type family Arr2Adj (ps :: Path ARRK a b ) :: Path ADJK a b
178- type instance Arr2Adj (IDA ::: ps ) = Arr2Adj ps
179- type instance Arr2Adj (IDB ::: ps ) = Arr2Adj ps
180- type instance Arr2Adj (A2B ::: ps ) = AK (L ::: Nil ) ::: Arr2Adj ps
181-
182- -- type AdjSq :: DOUBLE ADJK ARRK
183- -- data AdjSq ps qs fs gs where
184- -- AdjSq :: ps +++ Arr2Adj gs ~> Arr2Adj fs +++ qs -> AdjSq ps qs fs gs
185- -- instance Double ADJK ARRK where
186- -- type Sq ADJK ARRK = AdjSq
187- -- object = AdjSq id
188- -- hArr f = AdjSq f
189- -- AdjSq f ||| AdjSq g = AdjSq (f `o` g)
190- -- vArr ArrId = AdjSq id
191- -- AdjSq f === AdjSq g = AdjSq (f `o` g)
181+ instance Comonad (AK (R ::: L ::: Nil )) where
182+ epsilon = AdjCup AdjNil
183+ delta = AdjR (AdjCap (AdjL AdjNil ))
184+
185+ type SNilOrL :: Path ABK i j -> Type
186+ data SNilOrL p where
187+ SNilL :: SNilOrL Nil
188+ SLL :: SNilOrL (L ::: Nil )
189+ type SNilOrR :: Path ABK i j -> Type
190+ data SNilOrR p where
191+ SNilR :: SNilOrR Nil
192+ SRR :: SNilOrR (R ::: Nil )
193+
194+ type IsTight :: forall {i } {j }. Path ABK i j -> Constraint
195+ class (IsLRPath ps , IsCotight (CotightAdj ps ), Adjunction_ (AK ps ) (AK (CotightAdj ps ))) => IsTight (ps :: Path ABK i j ) where
196+ type CotightAdj (ps :: Path ABK i j ) :: Path ABK j i
197+ isNilOrL :: SNilOrL ps
198+ instance IsTight Nil where
199+ type CotightAdj Nil = Nil
200+ isNilOrL = SNilL
201+ instance IsTight (L ::: Nil ) where
202+ type CotightAdj (L ::: Nil ) = R ::: Nil
203+ isNilOrL = SLL
204+ type IsCotight :: forall {i } {j }. Path ABK i j -> Constraint
205+ class (IsLRPath ps , IsTight (TightAdj ps ), Adjunction_ (AK (TightAdj ps )) (AK ps )) => IsCotight (ps :: Path ABK i j ) where
206+ type TightAdj (ps :: Path ABK i j ) :: Path ABK j i
207+ isNilOrR :: SNilOrR ps
208+ instance IsCotight Nil where
209+ type TightAdj Nil = Nil
210+ isNilOrR = SNilR
211+ instance IsCotight (R ::: Nil ) where
212+ type TightAdj (R ::: Nil ) = L ::: Nil
213+ isNilOrR = SRR
214+
215+ type instance IsOb Tight (AK ps ) = IsTight ps
216+ type instance IsOb Cotight (AK ps ) = IsCotight ps
217+ type instance TightAdjoint (AK ps ) = AK (TightAdj ps )
218+ type instance CotightAdjoint (AK ps ) = AK (CotightAdj ps )
219+ instance WithObO2 Tight ADJK where
220+ withObO2 @ (AK ps ) @ (AK qs ) r = case (isNilOrL @ ps , isNilOrL @ qs ) of
221+ (SNilL , _) -> r
222+ (SLL , SNilL ) -> r
223+ instance WithObO2 Cotight ADJK where
224+ withObO2 @ (AK ps ) @ (AK qs ) r = case (isNilOrR @ ps , isNilOrR @ qs ) of
225+ (SNilR , _) -> r
226+ (SRR , SNilR ) -> r
227+ instance Equipment ADJK where
228+ withTightAdjoint r = r
229+ withCotightAdjoint r = r
0 commit comments