重复这些书,直到我确定正确为止。在Haskell食谱中找到了此内容:
data Option = Option { boolOption :: Bool, selections :: [String] }
deriving Show
instance Monoid Option where
mempty = Option False []
(Option b1 s1) `mappend` (Option b2 s2) = Option (b1 || b2) (s1 ++ s2)
从编译器得到了这一点:
error:
• No instance for (Semigroup Option)
arising from the superclasses of an instance declaration
• In the instance declaration for ‘Monoid Option’
|
116 | instance Monoid Option where
| ^^^^^^^^^^^^^
Failed, no modules loaded.
这本书是错误的还是过时的? Option
是否也需要是Semigroup
的实例?