Real-world applications of zygohistomorphic prepromorphisms
Solution 1
Sharon Curtis and Shin-Cheng Mu have a Functional Pearl using zygomorphisms to find maximally dense segments (a generalization of maximum segment sums). Zygomorphisms are seemingly a good fit for sliding window problems once you are accustomed to them.
http://www.iis.sinica.edu.tw/~scm/2010/functional-pearl-maximally-dense-segments/
I'd nominate the authors for extra credit as they've avoided the use of the fixed-point Mu functor.
Solution 2
Note, the signature of these has changed, because it was insufficiently general, and I included it (as a joke) in my recursion-schemes package.
zygoHistoPrepro
:: (Unfoldable t, Foldable t)
=> (Base t b -> b)
-> (forall c. Base t c -> Base t c)
-> (Base t (EnvT b (Stream (Base t)) a) -> a)
-> t
-> a
The implementation was simplified as well.
zygoHistoPrepro f = gprepro (distZygoT f distHisto)
And from the new implementation it should be obvious how to implement a generalized zygohistomorphic prepromorphism, by relaxing the constraint that you have a (Base t)-Branching
stream, through the use of distGHisto
instead.
Related videos on Youtube
barsoap
Updated on July 14, 2020Comments
-
barsoap almost 4 years
Yes, these ones:
{-#LANGUAGE TypeOperators, RankNTypes #-} import Control.Morphism.Zygo import Control.Morphism.Prepro import Control.Morphism.Histo import Control.Functor.Algebra import Control.Functor.Extras import Control.Functor.Fix import Control.Comonad.Cofree zygohistomorphic_prepromorphism :: Functor f => Algebra f b -> GAlgebra f (ZygoT (Cofree f) b) a -> (f :~> f) -> FixF f -> a zygohistomorphic_prepromorphism f = g_prepro (distZygoT (liftAlgebra f) (distHisto id))
Yes, I know that they're a (HHOS) joke. I'm looking for a real-world example for simple hack value and last, but not least, to add it to the wiki saying "This is the idiomatic way to express XYZ". I will put a bounty on this should you fail to come up with a solution. If you're completely lost on what they're about, Edward posted a short explanation on reddit.
Eligible Answers must:
do something at least remotely and theoretically computationally useful. That is, answers that reduce to
id
are out.use all the features of the scheme, no passing in of id, or const, or equivalent.
not equally well be expressible by a simple, vanilla fold or such, so don't merely implement
product
in a meandering way.
Bonus points will be given to:
Well-known problem or algorithm
solved, respectively expressed, in an unusual way that gains
clarity and/or performance
and/or hack value
and/or lulz, in roughly that order, as well as
high-ranking answers (yay democracy)
Please also note Edward's answer below. What ZHPM implementation you use is your choice.
-
Yitz about 13 yearsIf you had included
IO
in your stack, we could have used SimonPJ's famouslaunchMissles
function. But I guess the whole point of all that super-pure abstract nonsense is to avoid the possibility of such things. -
barsoap about 13 yearsWell,
a
can be anything, so feel free to construct an IO value that strategically launches missiles based on an assessment of your input data. -
Drew about 13 yearsI clicked on this question because I had no idea what the hell you're talking about. +1 good sir, +1
-
Edward Z. Yang about 13 yearsSomeone looking to use all of the components would do well to manually write out what a zygohistomorphic prepromorphism recursion expands to, and then look for problems that need all of these patterns; imperative loops tend to do arbitrarily complicated tracking, so they might be a good place to look.
-
n00b about 13 yearsand more important - Will it blend ?! (very sorry, couldnt resist)
-
Cosmin about 13 yearsShould I feel stupid for not understanding what all this is about? :D
-
barsoap about 13 yearsFrom skimming, I think I see how they use histo when tracking the DRSP (in the same sense that a simple
foldr
can look at the list it already constructed), but the prepro isn't immediately apparent to me. Could you elaborate? (and, if possible, give short+sweet code we can tack onto the wiki page?) -
stephen tetley about 13 yearsThe code is available from a link below the errata on the landing page. The actual definition of the zygomorphism is in the file Main.hs - its different to the definition in the paper. It is "just" a zygomorphism not a "zygohistomorphic prepromorphisms" - a zygomorphism is the closest thing I've seen with a real world use. Though there are slides by Jevgeni Kabanov using histomorphisms for dynamic programming: cs.ioc.ee/~tarmo/tday-viinistu/kabanov-slides.pdf
-
Ben Longo about 4 yearsAh yes quite obvious.