Haskell实例中缺少Mappend

我正在编译一个Haskell项目,并得到一条以前从未见过的消息。有人知道确切缺少什么吗?

=TDIST(1.92,5,2)

相应的代码是:

No instance nor default method for class operation mappend

函数instance S.semigroup Macros where x <> y = Macros (commands x ++ commands y) (environments x ++ environments y) (counters x ++ counters y) 似乎是一个关联运算符,但是我还不熟悉Haskell。

zx705 回答:Haskell实例中缺少Mappend

警告来自Monoid实例的定义,该实例可能在代码的后面某个位置,您将其保留了一半。

您可能有类似的东西

instance Monoid Macros where
    mempty = Macros [] [] []

但是,由于mappendMonoid的成员,因此您应该写

instance Monoid Macros where
    mempty = Macros [] [] []
    mappend = (<>)

注意:由于base-4.11(GHC-8.2),mappend可以省略,因为类型类中有默认定义

class Semigroup => Monoid m where
    -- | Identity of 'mappend'
    mempty  :: a

    -- | An associative operation
    --
    -- __NOTE__: This method is redundant and has the default
    -- implementation @'mappend' = '(<>)'@ since /base-4.11.0.0/.
    mappend :: a -> a -> a
    mappend = (<>)

https://hackage.haskell.org/package/base-4.11.0.0/docs/src/GHC.Base.html#mappend

如果您需要支持多个GHC版本,则可以将mappend = (<>)留在实例中。

本文链接:https://www.f2er.com/3169408.html

大家都在问