Sat 26 Apr 2008
Unnatural Transformations
Posted by Edward Kmett under Category Theory , Comonads , Haskell , Monads , Uncategorized[48] Comments
Back in the days of HYLO, it was common to write hylomorphisms with an additional natural transformation in them. Well, I was still coding in evil imperative languages back then, but I have it on reliable, er.. well supposition, that this is probably the case, or at least that they liked to do it back in the HYLO papers anyways.
Transcoding the category theory mumbo-jumbo into Haskell, so I can have a larger audience, we get the following 'frat combinator' -- you can blame Jules Bean from #haskell for that.
hyloEta :: Functor f => (g b -> b) -> (forall a. f a -> g a) -> (a -> f a) hyloEta phi eta psi = phi . eta . fmap (hyloEta phi eta psi) . psi
We placed eta in the middle of the argument list because it is evocative of the fact that it occurs between phi and psi, and because that seems to be where everyone else puts it.
Now, clearly, we could roll eta into phi and get the more traditional hylo where f = g. Less obviously we could roll it into psi because it is a natural transformation and so the following diagram commutes:
This 'Hylo Shift' property (mentioned in that same paper) allows us to move the 'eta' term into the phi term or into the psi term as we see fit. Since we can move the eta term around and it adds no value to the combinator, it quietly returned to the void from whence it came. hyloEta offers us no more power than hylo, so out it goes.
So, if its dead, why talk about it?
Well, when we move to a generalized hylomorphism we have a design decision that has some performance effects, and my initial pass at a generalized hylomorphism isn't as general as it could be. When we open up the generalized hylomorphism and look at its guts (check the slightly updated source code from yesterday) we see:
g_hylo' w m f g = liftW f . w . fmap duplicate . fmap (g_hylo' w m f g) . fmap join . m . liftM g
expanding that to include the eta term gives us 4 candidate locations where we can abuse its status as a natural transformation to slot it in.
g_hylo'1 w m f eta g = liftW f . w . eta . fmap duplicate . fmap (g_hylo' w m f g) . fmap join . m . liftM g g_hylo'2 w m f eta g = liftW f . w . fmap duplicate . eta . fmap (g_hylo' w m f g) . fmap join . m . liftM g g_hylo'3 w m f eta g = liftW f . w . fmap duplicate . fmap (g_hylo' w m f g) . eta . fmap join . m . liftM g g_hylo'4 w m f eta g = liftW f . w . fmap duplicate . fmap (g_hylo' w m f g) . fmap join . eta . m . liftM g
g-hylo'1 and g_hylo'4 are particularly interesting because we have functions sitting right next to them that we can fuse it into by generalizing the type signatures only slightly and because that leaves a run of 3 fmaps in a row that we can fuse together. If we generalize the signatures of both w and m we get the following definition that allows you to place it on the left or the right, and for g_hylo to not have to care about it.
-- new and improved! g_hylo :: (Comonad w, Functor f, Monad m) => (forall a. f (w a) -> w (g a)) -> (forall a. m (e a) -> f (m a)) -> (g (w b) -> b) -> (a -> e (m a)) -> (a -> b) g_hylo w m f g = extract . g_hylo' w m f g . return -- | the kernel of the generalized hylomorphism g_hylo' :: (Comonad w, Functor f, Monad m) => (forall a. f (w a) -> w (g a)) -> (forall a. m (e a) -> f (m a)) -> (g (w b) -> b) -> (a -> e (m a)) -> (m a -> w b) g_hylo' w m f g = liftW f . w . fmap (duplicate . g_hylo' w m f g . join) . m . liftM g
The slightly generalized signatures for our two distributive laws now allow them to change functors on the way through, but we shed a superfluous argument.
Note that while 3 'Functors' e, f and g are involved, only f needs to be a Functor in Hask because we do the duplication, hylomorphism and join all inside f in either case. And most of the time e = f = g. For instance e or g could be exponential or contravariant.
So now that we've generalized our generalized hylomorphism we're done right?
Not quite. Unfortunately the same trick doesn't work for the generalized chronomorphism defined last night.
To see why, we have open up chrono and peek at its guts.
chrono = g_chrono id id
Well, that was boring. Digging deeper we find:
g_chrono :: (Functor f, Functor g, Functor m, Functor w) => (forall b. f (w b) -> w (f b)) -> (forall b. m (f b) -> f (m b)) -> (f (Cofree w b) -> b) -> (a -> f (Free m a)) -> a -> b g_chrono w m = g_hylo (distCofree w) (distFree m)
Sticking in hylo's vestigial natural transformation, we get:
g_chronoEta :: (Functor f, Functor g, Functor m, Functor w) => (forall b. g (w b) -> w (g b)) -> (forall b. m (f b) -> f (m b)) -> (g (Cofree w b) -> b) -> (forall c. f a -> g a) -> (a -> f (Free m a)) -> a -> b g_chronoEta w m f eta g = g_hylo (distCofree w . eta) (distFree m) f g -- g_chronoEta w m f eta g = g_hylo (distCofree w) (eta . distFree m) f g
And so, we roll up our sleeves ready to merge it into something, be it f, g, w, m, anything, but it seems the only places eta can go is to merge into one of the distributive laws, because f and g are executed lifted.
Unfortunately, the user passed us rules for distributing the base functor of the cofree comonad and free monad, not for distributing the whole cofree comonad. And my efforts to generalize distFree and distCofree have thus far met with some frustration, there isn't much to grab onto there to write the more general signature.
Ideally, I'd just be able to merge it into one of the distributive laws. Since the HYLO guys liked to put it on the left of the recursive call to the hylomorphism, we'll look at distCofree. The desired signature for distCofree' would be:
distCofree' :: (Functor f, Functor g, Functor h) => (forall a. f (h a) -> h (g a)) -> f (Cofree h a) -> Cofree h (g a)
and it should have the property that:
distCofree' (f . eta) == distCofree' f . eta
Without that, g_chronoEta is more powerful than g_chrono. Naturally.
April 26th, 2008 at 8:54 pm
[...] Moreover, as an interesting aside, since one side is an anamorphism, there is no power to be gained for a dynamorphism by introducing a natural transformation term, even though dynamorphism is a form of chronomorphism, because ‘eta’ can be folded into the anamorphism side of the chronomorphism, as you do with a normal hylomorphism. [...]
September 23rd, 2022 at 5:54 am
Tadalafil 20 mg https://500px.com/p/skulogovid/?view=groups...
With thanks, I like this….
September 23rd, 2022 at 9:52 am
Viagra online https://500px.com/p/bersavahi/?view=groups...
You reported this fantastically….
September 24th, 2022 at 3:02 am
buy viagra now https://reallygoodemails.com/canadianpharmaceuticalsonlineusa...
Seriously lots of awesome facts!…
September 24th, 2022 at 6:34 am
most reliable canadian pharmacies https://www.provenexpert.com/canadian-pharmaceuticals-online-usa/...
You reported this perfectly….
September 24th, 2022 at 11:40 am
viagra canada https://sanangelolive.com/members/pharmaceuticals...
Fantastic data. Many thanks….
September 26th, 2022 at 10:43 am
online pharmacies canada https://melaninterest.com/user/canadian-pharmaceuticals-online/?view=likes...
Thanks, A lot of data!
…
September 26th, 2022 at 2:42 pm
Viagra 5 mg funziona https://haikudeck.com/canadian-pharmaceuticals-online-personal-presentation-827506e003...
Terrific material. Appreciate it!…
September 26th, 2022 at 6:50 pm
canada pharmacy online https://buyersguide.americanbar.org/profile/420642/0...
Fine data. Thanks!…
September 27th, 2022 at 2:31 am
Viagra purchasing https://experiment.com/users/canadianpharmacy...
Regards! A good amount of posts.
…
September 27th, 2022 at 8:28 am
Viagra for daily use https://slides.com/canadianpharmaceuticalsonline...
Amazing lots of useful data….
September 27th, 2022 at 12:10 pm
stromectol over the counter https://challonge.com/esapenti...
Incredible quite a lot of good advice….
September 27th, 2022 at 4:36 pm
How does viagra work https://challonge.com/gotsembpertvil...
Terrific advice. Appreciate it….
September 28th, 2022 at 6:17 am
Viagra levitra https://challonge.com/citlitigolf...
You said it nicely.!…
September 28th, 2022 at 9:51 am
Viagra reviews https://order-stromectol-over-the-counter.estranky.cz/clanky/order-stromectol-over-the-counter.html...
Amazing data, With thanks!…
September 28th, 2022 at 4:17 pm
Viagra 20mg https://soncheebarxu.estranky.cz/clanky/stromectol-for-head-lice.html...
Really quite a lot of wonderful info!…
September 29th, 2022 at 5:47 am
order stromectol online https://lehyriwor.estranky.sk/clanky/stromectol-cream.html...
You have made your point….
September 29th, 2022 at 4:03 pm
Viagra lowest price https://inflavnena.zombeek.cz/...
With thanks, A lot of data.
…
September 30th, 2022 at 10:17 am
Viagra generique https://www.myscrsdirectory.com/profile/421708/0...
With thanks! Loads of stuff.
…
September 30th, 2022 at 5:31 pm
buy viagra online usa https://supplier.ihrsa.org/profile/421717/0...
Information clearly used!!…
October 1st, 2022 at 7:51 am
Viagra or viagra https://wefbuyersguide.wef.org/profile/421914/0...
Appreciate it. A good amount of content!
…
October 1st, 2022 at 11:54 am
Interactions for viagra https://legalmarketplace.alanet.org/profile/421920/0...
Thanks a lot. Terrific information….
October 2nd, 2022 at 5:29 am
Generic viagra https://moaamein.nacda.com/profile/422018/0...
You actually said it effectively….
October 2nd, 2022 at 9:54 am
canadian pharmacy https://www.audiologysolutionsnetwork.org/profile/422019/0...
You actually explained that adequately!…
October 2nd, 2022 at 1:12 pm
northwestpharmacy https://network.myscrs.org/profile/422020/0...
You’ve made your point quite well.!…
October 3rd, 2022 at 6:57 am
canadian pharmacy world https://sanangelolive.com/members/canadianpharmaceuticalsonlineusa...
With thanks. Loads of stuff!
…
October 3rd, 2022 at 10:27 am
Discount viagra https://sanangelolive.com/members/girsagerea...
Superb posts. With thanks!…
October 4th, 2022 at 9:19 am
Viagra uk https://www.ecosia.org/search?q=“My Canadian Pharmacy – Extensive Assortment of Medications – 2022″…
Wonderful facts. Regards….
October 4th, 2022 at 1:31 pm
buy viagra now https://www.mojomarketplace.com/user/Canadianpharmaceuticalsonline-EkugcJDMYH...
Beneficial facts. Thank you!…
October 4th, 2022 at 5:27 pm
Generic viagra https://seedandspark.com/user/canadian-pharmaceuticals-online...
You reported that very well….
October 5th, 2022 at 10:30 am
Discount viagra https://www.giantbomb.com/profile/canadapharmacy/blog/canadian-pharmaceuticals-online/265652/...
Information effectively utilized!!…
October 5th, 2022 at 2:23 pm
canada drugs https://feeds.feedburner.com/bing/Canadian-pharmaceuticals-online...
Whoa lots of terrific facts….
October 5th, 2022 at 7:05 pm
Canadian viagra https://search.gmx.com/web/result?q=“My Canadian Pharmacy – Extensive Assortment of Medications – 2022″…
You made your point very clearly!!…
October 6th, 2022 at 4:09 am
Viagra tablets australia https://search.seznam.cz/?q=“My Canadian Pharmacy – Extensive Assortment of Medications – 2022″…
You made your point extremely clearly.!…
October 6th, 2022 at 7:53 am
Viagra lowest price https://sanangelolive.com/members/unsafiri...
You revealed this wonderfully!…
October 6th, 2022 at 12:06 pm
northwestpharmacy …
Nicely put. With thanks….
October 6th, 2022 at 6:02 pm
canada drug https://swisscows.com/en/web?query=“My Canadian Pharmacy – Extensive Assortment of Medications – 2022″…
Incredible a good deal of wonderful data….
October 7th, 2022 at 5:36 am
Viagra rezeptfrei https://www.dogpile.com/serp?q=“My Canadian Pharmacy – Extensive Assortment of Medications – 2022″…
Good data, Many thanks….
October 7th, 2022 at 12:46 pm
Viagra 5 mg funziona …
Superb data. Many thanks!…
October 8th, 2022 at 8:39 am
canada online pharmacy https://search.givewater.com/serp?q=“My Canadian Pharmacy – Extensive Assortment of Medications – 2022″…
With thanks! I value it….
October 9th, 2022 at 7:16 am
canadian pharmacy king …
This is nicely put. !…
October 9th, 2022 at 12:24 pm
Viagra kaufen https://results.excite.com/serp?q=“My Canadian Pharmacy – Extensive Assortment of Medications – 2022″…
Wonderful content. Many thanks….
October 9th, 2022 at 4:56 pm
canadian pharmacy viagra https://www.infospace.com/serp?q=“My Canadian Pharmacy – Extensive Assortment of Medications – 2022″…
Regards! I appreciate this!…
October 10th, 2022 at 9:12 am
Viagra 20 mg https://headwayapp.co/canadianppharmacy-changelog...
Thanks! I appreciate this….
October 11th, 2022 at 7:13 am
canada pharmacy online https://results.excite.com/serp?q=“My Canadian Pharmacy – Extensive Assortment of Medications – 2022″…
Thanks a lot. Good information….
October 11th, 2022 at 12:37 pm
online canadian pharmacy https://canadianpharmaceuticalsonline.as.me/schedule.php...
Position effectively taken!….
October 13th, 2022 at 2:28 pm
Viagra generic https://feeds.feedburner.com/bing/stromectolnoprescription...
Seriously a good deal of useful knowledge!…
October 14th, 2022 at 6:52 am
Viagra 20 mg best price https://reallygoodemails.com/orderstromectoloverthecounterusa...
Thanks. Ample forum posts!
…