- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要为玫瑰树数据结构制作一个可折叠的实例:
data Rose a = a :> [Rose a]
deriving (Eq, Show)
instance Functor Rose where
fmap f (a :> bs) = (f a) :> (map (fmap f) bs)
class Monoid a where
mempty :: a
(<>) :: a -> a -> a
instance Monoid [a] where
mempty = []
(<>) = (++)
instance Foldable Rose where
fold (a:>b) = a <> (foldMap fold b)
*** Failed! Exception: 'Prelude.undefined':
[] :> []
最佳答案
您对 fold
的实现是正确的,没有理由改变它。
问题是 fold
不足以定义 Foldable
.来自 the documentation :
class Foldable t where Source
Data structures that can be folded.
Minimal complete definition:
foldMap
orfoldr
.
foldMap
或
foldr
(或两者)。定义
foldMap
更容易、更自然(在许多情况下也更有效)。所以你应该写这样的东西:
import Data.Foldable
import Data.Monoid
data Rose a = a :> [Rose a]
deriving (Eq, Show)
instance Foldable Rose where
foldMap f (x :> xs) = f x <> foldMap (foldMap f) xs
关于class - Haskell 单体可折叠玫瑰树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26257369/
现在我需要确切地知道如何在需要时立即部署基于微服务的后端?我可以自己管理所有技术的集成,但是在 AWS 上托管时,我不可能获得这么多实例,而且现在也买不起。 我正在考虑从单一后端开始的想法,同时有可能
我有一个使用 spring 3.1 和 spring-security 3.1 以及 Java 7 开发的整体式 Spring Web 应用程序,并将其部署在 tomcat 7 上。 现在我有一个新要
在他的Monad Reader article on Hoogle第 33 页,Neil Mitchell 提倡将 Haskell 项目捆绑到一个具有多种模式的可执行文件中。 (仅供引用,Neil M
我有一个单进程有 5 个线程的单体应用程序。每个线程完成某些特定任务。考虑使用 docker 将此应用程序移动到微服务。如果我看一下架构,每个工作线程都会变成一个 docker 进程。因此,在某种程度
我知道有人问过很多类似的问题,但我还没有看到对链接和管理样式的所有三种可能方法的比较。哪个是浏览性能最好和最差的?我知道 推荐超过@import因为它允许并行下载,但我也听说单个大型 CSS 优于 正
多年来,我的目标是从 ASP/VBScript 转向“更好”的语言——我的偏好是 C#,因为我有 C 技能——但我也会考虑其他语言(包括 PHP 等,所以不仅仅是 DotNet ) 目标是使用一种对我
我是一名优秀的程序员,十分优秀!