接合组织同态前原态的现实应用
是的,这些:
{-#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))
是的,我知道它们是(HHOS)笑话。我正在寻找一个简单的 hack 值的真实示例,最后但并非最不重要的一点是,将其添加到 wiki 中并表示“这是表达 XYZ 的惯用方式”。如果您无法找到解决方案,我将悬赏。如果您完全不知道它们的内容,Edward 发布了一个 简短内容reddit 上的解释。
合格的答案必须:
至少进行一些远程且理论上在计算上有用的事情。也就是说,减少到
id
的答案已经消失。使用该方案的所有功能,不传入 id、const 或等效项。
不能用简单的、普通的折叠或类似的方式来表达,所以不要仅仅以蜿蜒的方式实现
产品
。
奖励分将给予:
众所周知的问题或算法
以一种不寻常的方式解决,分别表示,收益
清晰度和/或性能
和/或黑客价值
和/或lulz的不寻常方式,大致如此顺序,以及
高级答案(耶民主)
另请注意爱德华的回答如下。您可以选择使用哪种 ZHPM 实现。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Sharon Curtis 和 Shin-Cheng Mu 有一个功能珍珠,使用对称性来找到最大密集段(最大段和的概括)。一旦您习惯了对称性,它们似乎就非常适合解决滑动窗口问题。
http://www.iis.sinica .edu.tw/~scm/2010/function-pearl-maximally-dense-segments/
我提名作者获得额外荣誉,因为他们避免使用定点 Mu 函子。
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.
请注意,这些签名已更改,因为它不够通用,我将其(作为一个笑话)包含在我的 递归方案 包。
实施也得到了简化。
从新的实现中,应该很明显如何通过使用
(Base t)-Branching
放宽约束来实现广义 zygohistomorphic prepromorphism改为distGHisto
。Note, the signature of these has changed, because it was insufficiently general, and I included it (as a joke) in my recursion-schemes package.
The implementation was simplified as well.
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 ofdistGHisto
instead.