Thu 5 Jun 2008
As you may recall, every functor in Haskell is strong, in the sense that if you provided an instance of Monad for that functor the following definition would satisfy the requirements mentioned here:
strength :: Functor f => a -> f b -> f (a,b) strength = fmap . (,)
In an earlier post about the cofree comonad and the expression problem, I used a typeclass defining a form of duality that enables you to let two functors annihilate each other, letting one select the path whenever the other offered up multiple options. To have a shared set of conventions with the material in Zipping and Unzipping Functors, I have since remodeled that class slightly:
class Zap f g | f -> g, g -> f where zapWith :: (a -> b -> c) -> f a -> g b -> c zap :: f (a -> b) -> g a -> b zap = zapWith id
Interestingly, we can use the fact that every functor in Haskell is strong to derive not only one instance of Zap
, but two, given any Adjunction
.
I'll give one instance here:
zapWithAdjunctionGF :: Adjunction g f => (a -> b -> c) -> f a -> g b -> c zapWithAdjunctionGF f a b = uncurry (flip f) . counit . fmap (uncurry (flip strength)) $ strength a b
And I'll leave the substantially similar derivation of the following to the reader:
zapWithAdjunctionFG :: Adjunction f g => (a -> b -> c) -> f a -> g b -> c
Now, we would like to do the same thing we did with Representable
last time, and just require the user of the Adjunction
class to provide us with more instances, something like:
class (Zap f g, Zap g f, Representable g (f Void), Functor f) => Adjunction f g | f -> g, g -> f where ...
But there is a problem: Adjunction composition.
If you will recall from before, we were able to define an instance for an Adjunction
for a composition of two adjunctions:
newtype O f g a = Compose { decompose :: f (g a) } instance (Functor f, Functor g) => Functor (f `O` g) where fmap f = Compose . fmap (fmap f) . decompose instance (Adjunction f1 g1, Adjunction f2 g2) => Adjunction (f2 `O` f1) (g1 `O` g2) where counit = counit . fmap (counit . fmap decompose) . decompose unit = Compose . fmap (fmap Compose . unit) . unit
The problem is that we have three different ways to build an instance of Zap
for this composition and we would need to define two of them that conflict!
We would need both of these, which would lead to ambiguous instance heads:
instance (Adjunction f1 g1, Adjunction f2 g2) => Zap (f2 `O` f1) (g1 `O` g2) where zapWith = zapWithAdjunctionFG instance (Adjunction f1 g1, Adjunction f2 g2) => Zap (g1 `O` g2) (f2 `O` f1) where zapWith = zapWithAdjunctionGF
Furthermore, we can also define a third instance of Zap
over composition, which doesn't even care about Adjunction
, which also conflicts with the above:
instance (Zap f g, Zap h k) => Zap (f `O` h) (g `O` k) where zapWith f a b = zapWith (zapWith f) (decompose a) (decompose b)
We could use the standard Haskell trick of making different compositions based on which instance of Zap
you want to support, but the combinatorial explosion of constructors here when combined with the other reasons you may want to compose a pair of functors leads to a bit of absurdity, especially since I'm using it to capture a relationship no one cares about.
Consequently, category-extras does not capture this constraint.
Cozapping
As a final aside, we noted previously that Traversable
functors were costrong. If a strong Adjunction
gives rise to a couple of instances of Zap
, we'd expect a similar relationship between a notion of Cozap
and a costrong Adjunction
.
But what would cozapping be?
First lets take a step back and break down zipWith into a couple of steps. If we note that zapWith (,)
looks like:
prezapAdjunctionGF :: Adjunction g f => f a -> g b -> (a,b) prezapAdjunctionGF a b = swap . counit . fmap (uncurry strength . swap) $ strength a b where swap ~(a,b) = (b,a)
Whereupon we can run the output through the canonical eval morphism for exponentials in :
eval :: (a -> b, a) -> b eval (f,a) = f a
We can run everything backwards (modulo the noise caused by currying) in the first definition above and get:
precozapAdjunctionFG :: (Adjunction f g, Traversable f, Traversable g) => Either a b -> Either (f a) (g b) precozapAdjunctionFG = costrength . fmap (swap . costrength) . unit . swap
However, we lack a coeval
morphism for coexponentials, since lacks coexponentials -- with good reason! If was a co-CCC then it would degenerate to a rather boring poset.
But that said, even getting this far, how many adjunctions are there between Traversable
functors in Haskell, really?
June 18th, 2008 at 11:42 pm
Off-topic, but it looks like Allegory.hs and Dyad.hs have not been added to darcs in category-extras?
June 19th, 2008 at 1:10 am
Good catch.
I added Control.Comonad.Exponent in response to a comment over on Dan Piponi’s blog and forgot that I had those in progress at the time.
Fixed and uploading to hackage as I write this.
I may drop Dyad though, since it doesn’t add much value. As near as I can tell there are no interesting dyads in Haskell that aren’t just monads or comonads, and they force a profusion of typeclasses to define that lack other uses. This may also explain why there has been no followup to Fokkinga’s paper on them in the last 14 years. The distributive law is required to be a natural isomorphism, which seems to be too strong to be practical.
September 23rd, 2022 at 6:13 am
stromectol buy https://500px.com/p/skulogovid/?view=groups...
Awesome postings. Thanks a lot!…
September 23rd, 2022 at 10:11 am
canada rx https://500px.com/p/bersavahi/?view=groups...
With thanks. Quite a lot of material!
…
September 24th, 2022 at 3:21 am
online drug store https://reallygoodemails.com/canadianpharmaceuticalsonlineusa...
Really a lot of terrific knowledge….
September 24th, 2022 at 6:53 am
canadian pharmacy no prescription https://www.provenexpert.com/canadian-pharmaceuticals-online-usa/...
Lovely info, Kudos!…
September 24th, 2022 at 11:59 am
Viagra canada https://sanangelolive.com/members/pharmaceuticals...
Nicely put. Cheers….
September 26th, 2022 at 11:03 am
trust pharmacy canada https://melaninterest.com/user/canadian-pharmaceuticals-online/?view=likes...
You actually expressed it superbly….
September 26th, 2022 at 3:01 pm
Viagra for sale https://haikudeck.com/canadian-pharmaceuticals-online-personal-presentation-827506e003...
You made your stand pretty nicely…..
September 26th, 2022 at 7:09 pm
Viagra 5mg prix https://buyersguide.americanbar.org/profile/420642/0...
You reported that perfectly!…
September 27th, 2022 at 2:50 am
Viagra pills https://experiment.com/users/canadianpharmacy...
You have made your position very nicely!….
September 27th, 2022 at 8:47 am
canada pharmacy online https://slides.com/canadianpharmaceuticalsonline...
Really lots of amazing knowledge….
September 27th, 2022 at 12:30 pm
Viagra dosage https://challonge.com/esapenti...
Incredible a good deal of excellent knowledge….
September 28th, 2022 at 6:35 am
Viagra levitra https://challonge.com/citlitigolf...
Thanks, Good information….
September 28th, 2022 at 10:08 am
Viagra 5 mg https://order-stromectol-over-the-counter.estranky.cz/clanky/order-stromectol-over-the-counter.html...
Really tons of wonderful tips!…
September 28th, 2022 at 4:34 pm
Buy viagra https://soncheebarxu.estranky.cz/clanky/stromectol-for-head-lice.html...
Cheers. I value this….
September 29th, 2022 at 6:05 am
Viagra vs viagra vs levitra https://lehyriwor.estranky.sk/clanky/stromectol-cream.html...
Nicely put, Kudos!…
September 29th, 2022 at 9:52 am
dosage for stromectol https://dsdgbvda.zombeek.cz/...
Incredible loads of excellent info!…
September 29th, 2022 at 4:22 pm
stromectol oral https://inflavnena.zombeek.cz/...
Excellent information. With thanks….
September 30th, 2022 at 10:34 am
Viagra tablets https://www.myscrsdirectory.com/profile/421708/0...
Appreciate it! Plenty of stuff!
…
September 30th, 2022 at 5:49 pm
Viagra generika https://supplier.ihrsa.org/profile/421717/0...
Nicely expressed indeed! ….
October 1st, 2022 at 8:08 am
canadian prescriptions online https://wefbuyersguide.wef.org/profile/421914/0...
You said that effectively….
October 1st, 2022 at 12:12 pm
Buy generic viagra https://legalmarketplace.alanet.org/profile/421920/0...
Very good content, With thanks!…
October 2nd, 2022 at 5:47 am
Low cost viagra 20mg https://moaamein.nacda.com/profile/422018/0...
Cheers. An abundance of postings.
…
October 2nd, 2022 at 10:11 am
best canadian pharmacies online https://www.audiologysolutionsnetwork.org/profile/422019/0...
Fantastic facts. Thanks!…
October 2nd, 2022 at 1:28 pm
online pharmacies canada https://network.myscrs.org/profile/422020/0...
Seriously lots of fantastic data!…
October 3rd, 2022 at 7:14 am
Viagra dosage https://sanangelolive.com/members/canadianpharmaceuticalsonlineusa...
Thanks, Fantastic information….
October 4th, 2022 at 9:38 am
Viagra sans ordonnance https://www.ecosia.org/search?q=“My Canadian Pharmacy – Extensive Assortment of Medications – 2022″…
Many thanks. Fantastic stuff….
October 4th, 2022 at 1:54 pm
Viagra 20 mg https://www.mojomarketplace.com/user/Canadianpharmaceuticalsonline-EkugcJDMYH...
Truly a good deal of good facts!…
October 4th, 2022 at 5:46 pm
canadian discount pharmacies https://seedandspark.com/user/canadian-pharmaceuticals-online...
You mentioned it effectively!…
October 5th, 2022 at 10:50 am
Viagra 5mg prix https://www.giantbomb.com/profile/canadapharmacy/blog/canadian-pharmaceuticals-online/265652/...
You actually said that very well!…
October 5th, 2022 at 2:43 pm
Viagra sans ordonnance https://feeds.feedburner.com/bing/Canadian-pharmaceuticals-online...
Regards! I value this….
October 6th, 2022 at 4:29 am
Viagra 20mg https://search.seznam.cz/?q=“My Canadian Pharmacy – Extensive Assortment of Medications – 2022″…
Reliable facts. Cheers!…
October 6th, 2022 at 8:14 am
Viagra generique https://sanangelolive.com/members/unsafiri...
You stated it wonderfully….
October 6th, 2022 at 12:25 pm
Viagra generic …
Terrific posts. Regards….
October 6th, 2022 at 6:21 pm
Viagra 5mg https://swisscows.com/en/web?query=“My Canadian Pharmacy – Extensive Assortment of Medications – 2022″…
Seriously a good deal of great info!…
October 7th, 2022 at 5:57 am
Viagra manufacturer coupon https://www.dogpile.com/serp?q=“My Canadian Pharmacy – Extensive Assortment of Medications – 2022″…
Useful advice. Thanks a lot….
October 8th, 2022 at 8:59 am
Discount viagra https://search.givewater.com/serp?q=“My Canadian Pharmacy – Extensive Assortment of Medications – 2022″…
Thanks a lot. A lot of data!
…
October 8th, 2022 at 2:27 pm
Viagra alternative https://www.bakespace.com/members/profile/Сanadian pharmaceuticals for usa sales/1541108/…
Whoa a lot of excellent info….
October 9th, 2022 at 7:36 am
Viagra alternative …
You revealed this very well!…
October 9th, 2022 at 12:44 pm
online pharmacies https://results.excite.com/serp?q=“My Canadian Pharmacy – Extensive Assortment of Medications – 2022″…
Thanks! I appreciate it!…
October 9th, 2022 at 5:17 pm
Low cost viagra 20mg https://www.infospace.com/serp?q=“My Canadian Pharmacy – Extensive Assortment of Medications – 2022″…
You have made the point!…
October 11th, 2022 at 7:35 am
Viagra uk https://results.excite.com/serp?q=“My Canadian Pharmacy – Extensive Assortment of Medications – 2022″…
Amazing tons of excellent information!…
October 11th, 2022 at 12:59 pm
Viagra daily https://canadianpharmaceuticalsonline.as.me/schedule.php...
Whoa tons of superb information….
October 13th, 2022 at 2:48 pm
How does viagra work https://feeds.feedburner.com/bing/stromectolnoprescription...
You expressed that well!…
October 14th, 2022 at 7:12 am
Online viagra https://reallygoodemails.com/orderstromectoloverthecounterusa...
Nicely put, Appreciate it!…