- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 recursion-schemes 中的组织同态 (histo
)我可以从初始列表中获取仅包含奇数索引的列表:
import Data.Functor.Foldable
odds :: [a] -> [a]
odds = histo $ \case
Nil -> []
Cons h (_ :< Nil) -> [h]
Cons h (_ :< Cons _ (t :< _)) -> h:t
如何使用 mhisto
获得相同的结果?
nil = Fix Nil
cons a b = Fix $ Cons a b
list = cons 1 $ cons 2 $ cons 3 $ nil
modds :: Fix (ListF a) -> [a]
modds = mhisto alg where
alg _ _ Nil = []
alg f g (Cons a b) = ?
最佳答案
就是这样:
modds :: Fix (ListF a) -> [a]
modds = mhisto alg
where
alg _ _ Nil = []
alg odd pre (Cons a b) = a : case pre b of
Nil -> []
Cons _ b' -> odd b'
GHCi> list = cata embed [1..10] :: Fix (ListF Int)
GHCi> odds (cata embed list)
[1,3,5,7,9]
GHCi> modds list
[1,3,5,7,9]
odd
折叠列表的其余部分,而 pre
挖掘前一个。请注意门德勒代数中 y -> f y
函数的可用性如何反射(reflect)了普通组织同态代数中 Cofree
的引入(其中可以通过获取来进行回溯) Cofree
流的尾部):
cata :: Functor f => (f c -> c) -> Fix f -> c
histo :: Functor f => (f (Cofree f c) -> c) -> Fix f -> c
mcata :: (forall y. (y -> c) -> f y -> c) -> Fix f -> c
mhisto :: (forall y. (y -> c) -> (y -> f y) -> f y -> c) -> Fix f -> c
有关 mcata
和 mhisto
的进一步阅读,请参阅 Categorical programming with inductive and coinductive types, by Varmo Vene 的第 5 章和第 6 章.
关于haskell - 门德勒的组织形态论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53126614/
我想实现一个 bool NAND/NOR 门。问题是我在代码本身中即时学习的门没有输入,即我事先不知道它可能有多少输入。以下是 OR 的代码。但我想不出一种方法来为 NOR/NAND 做这件事。结果的
我正试图找到用 C 语言编写 XNOR 门的最有效方法。 if(VAL1 XNOR VAL2) { BLOCK; } 有什么建议吗? 谢谢。 最佳答案 有两个操作数,这很简单: if (val
我正在尝试进行 laravel 基本授权。我正在使用 gate 进行 laravel 授权。 表结构 User Table, Permission Table, Role, role_permissi
据我所知,我们有一个Youtube API,可通过使用以下API详细信息来获取基于某个地区的趋势YouTube视频: https://developers.google.com/youtube/v3/
我有一个看起来像这样的出租车列表: 1204725 2162 1300163 420247 我希望从上面的taxids中按顺序获得一个带有分类ID的文件: kingdom_id phylum
我一直在尝试弄清楚如何制作“ HitTest 门帖子”,其中帖子是按在最短的时间内获得最多支持排序的。 我有 2 个数据库表: 有趣的帖子: fun_post_upvotes: 我的最新代码仍然不起作
如何通过 Windows API 调用打开 CD/DVD 门? 最佳答案 如果您使用 .NET,这将起作用: http://www.dotnetspider.com/resources/15834-e
我们的核心目标是: 使用图像处理来读取/扫描建筑平面图图像(从 CAD 软件导出) 使用图像处理来读取/扫描建筑平面图图像(从 CAD 软件导出)提取各种直线和曲线,将它们分组为结构实体,如墙、柱、梁
给定 n 个元素 1,2,.........,n 上的二叉搜索树的后序遍历 P。您必须确定以 P 作为其后序遍历的唯一二叉搜索树。执行此操作的最有效算法的时间复杂度是多少? (a) theeta(lo
根据定义,门 1/sqrt(5) (I + 2iZ) 应作用于量子位 a|0> + b|1> 以将其转换为 1/sqrt (5) ((1+2i)a|0> + (1-2i)b|1>) 但每个 RUS 步
我有物种的分类 ID,我可以从 NCBI ( https://www.ncbi.nlm.nih.gov/Taxonomy/TaxIdentifier/tax_identifier.cgi ) 获得物种
我是一名优秀的程序员,十分优秀!