接合组织同态前原态的现实应用

发布于 2024-10-18 09:40:48 字数 1614 浏览 1 评论 0原文

是的,这些

{-#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 上的解释

合格的答案必须:

  1. 至少进行一些远程且理论上在计算上有用的事情。也就是说,减少到id的答案已经消失。

  2. 使用该方案的所有功能,不传入 id、const 或等效项。

  3. 不能用简单的、普通的折叠或类似的方式来表达,所以不要仅仅以蜿蜒的方式实现产品

奖励分将给予:

  • 众所周知的问题或算法

  • 以一种不寻常的方式解决,分别表示,收益

  • 清晰度和/或性能

  • 和/或黑客价值

  • 和/或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:

  1. do something at least remotely and theoretically computationally useful. That is, answers that reduce to id are out.

  2. use all the features of the scheme, no passing in of id, or const, or equivalent.

  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小忆控 2024-10-25 09:40:48

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.

神经大条 2024-10-25 09:40:48

请注意,这些签名已更改,因为它不够通用,我将其(作为一个笑话)包含在我的 递归方案 包。

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

实施也得到了简化。

zygoHistoPrepro f = gprepro (distZygoT f distHisto)

从新的实现中,应该很明显如何通过使用 (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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文