0

重复这些书,直到我确定它是正确的。在 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

4

0 回答 0