11 | module Data.Profunctor.Costrong
13 | import Data.Morphisms
15 | import Data.Profunctor.Functor
16 | import Data.Profunctor.Types
39 | interface Profunctor p => GenCostrong (0 ten : Type -> Type -> Type) p where
41 | costrongl : p (a `ten` c) (b `ten` c) -> p a b
43 | costrongr : p (c `ten` a) (c `ten` b) -> p a b
48 | Costrong : (p : Type -> Type -> Type) -> Type
49 | Costrong = GenCostrong Pair
54 | unfirst : Costrong p => p (a, c) (b, c) -> p a b
55 | unfirst = costrongl {ten=Pair}
60 | unsecond : Costrong p => p (c, a) (c, b) -> p a b
61 | unsecond = costrongr {ten=Pair}
65 | Cochoice : (p : Type -> Type -> Type) -> Type
66 | Cochoice = GenCostrong Either
71 | unleft : Cochoice p => p (Either a c) (Either b c) -> p a b
72 | unleft = costrongl {ten=Either}
77 | unright : Cochoice p => p (Either c a) (Either c b) -> p a b
78 | unright = costrongr {ten=Either}
87 | GenCostrong Pair Tagged where
88 | costrongl (Tag (x,_)) = Tag x
89 | costrongr (Tag (_,x)) = Tag x
92 | GenCostrong Either (Forget r) where
93 | costrongl (MkForget k) = MkForget (k . Left)
94 | costrongr (MkForget k) = MkForget (k . Right)
97 | GenCostrong Pair (Coforget r) where
98 | costrongl (MkCoforget k) = MkCoforget (fst . k)
99 | costrongr (MkCoforget k) = MkCoforget (snd . k)
110 | data GenCotambara : (ten, p : Type -> Type -> Type) -> Type -> Type -> Type where
111 | MkCotambara : GenCostrong ten q => q :-> p -> q a b -> GenCotambara ten p a b
114 | Profunctor (GenCotambara ten p) where
115 | lmap f (MkCotambara n p) = MkCotambara n (lmap f p)
116 | rmap f (MkCotambara n p) = MkCotambara n (rmap f p)
117 | dimap f g (MkCotambara n p) = MkCotambara n (dimap f g p)
120 | ProfunctorFunctor (GenCotambara ten) where
121 | promap f (MkCotambara n p) = MkCotambara (f . n) p
124 | GenCostrong ten (GenCotambara ten p) where
125 | costrongl (MkCotambara @{costr} n p) = MkCotambara n (costrongl @{costr} p)
126 | costrongr (MkCotambara @{costr} n p) = MkCotambara n (costrongr @{costr} p)
129 | ProfunctorComonad (GenCotambara ten) where
130 | proextract (MkCotambara n p) = n p
131 | produplicate (MkCotambara n p) = MkCotambara id (MkCotambara n p)
134 | Functor (GenCotambara ten p a) where
143 | Cotambara : (p : Type -> Type -> Type) -> Type -> Type -> Type
144 | Cotambara = GenCotambara Pair
151 | CotambaraSum : (p : Type -> Type -> Type) -> Type -> Type -> Type
152 | CotambaraSum = GenCotambara Either
156 | cotambara : GenCostrong ten p => p :-> q -> p :-> GenCotambara ten q
157 | cotambara f = MkCotambara f
160 | uncotambara : Tensor ten i => Profunctor q => p :-> GenCotambara ten q -> p :-> q
161 | uncotambara f p = proextract (f p)
172 | record GenCopastro (ten, p : Type -> Type -> Type) a b where
173 | constructor MkCopastro
174 | runCopastro : forall q. GenCostrong ten q => p :-> q -> q a b
177 | Profunctor (GenCopastro ten p) where
178 | dimap f g (MkCopastro h) = MkCopastro $
\n => dimap f g (h n)
179 | lmap f (MkCopastro h) = MkCopastro $
\n => lmap f (h n)
180 | rmap f (MkCopastro h) = MkCopastro $
\n => rmap f (h n)
183 | ProfunctorFunctor (GenCopastro ten) where
184 | promap f (MkCopastro h) = MkCopastro $
\n => h (n . f)
187 | ProfunctorMonad (GenCopastro ten) where
188 | propure p = MkCopastro ($
p)
189 | projoin p = MkCopastro $
\x => runCopastro p (\y => runCopastro y x)
192 | GenCostrong ten (GenCopastro ten p) where
193 | costrongl (MkCopastro h) = MkCopastro $
\n => costrongl {ten} (h n)
194 | costrongr (MkCopastro h) = MkCopastro $
\n => costrongr {ten} (h n)
197 | ProfunctorAdjunction (GenCopastro ten) (GenCotambara ten) where
198 | prounit p = MkCotambara id (propure {t=GenCopastro ten} p)
199 | procounit (MkCopastro h) = proextract (h id)
207 | Copastro : (p : Type -> Type -> Type) -> Type -> Type -> Type
208 | Copastro = GenCopastro Pair
215 | CopastroSum : (p : Type -> Type -> Type) -> Type -> Type -> Type
216 | CopastroSum = GenCopastro Either
220 | copastro : GenCostrong ten q => p :-> q -> GenCopastro ten p :-> q
221 | copastro f (MkCopastro h) = h f
224 | uncopastro : Tensor ten i => GenCopastro ten p :-> q -> p :-> q
225 | uncopastro f x = f (MkCopastro ($
x))