Haskell Cookbook,Monoid实例

时间:2019-03-06 17:48:38

标签: haskell cookbook monoids semigroup

重复这些书,直到我确定正确为止。在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的实例?

0 个答案:

没有答案