Cabal 无法安装日期和半组

Cabal cannot install dates and semigroup

如果我执行 $ cabal install semigroup,我得到错误

Data/Semigroup.hs:29:22: error:
Ambiguous occurrence ‘Semigroup’
It could refer to either ‘Prelude.Semigroup’,
                         imported from ‘Prelude’ at Data/Semigroup.hs:2:8-21
                         (and originally defined in ‘GHC.Base’)
                      or ‘Data.Semigroup.Semigroup’,
                         defined at Data/Semigroup.hs:22:1
   |
29 | instance Monoid a => Semigroup (Identity a) where
   |                      ^^^^^^^^^

(在其他几次出现时重复)

同样如果我$ cabal install dates,

Data/Dates/Types.hs:62:10: error:
• No instance for (Semigroup DateTime)
    arising from the superclasses of an instance declaration
• In the instance declaration for ‘Monoid DateTime’
   |
62 | instance Monoid DateTime where
   |          ^^^^^^^^^^^^^^^
cabal: Leaving directory '/tmp/cabal-tmp-16926/dates-0.2.2.1'
cabal: Error: some packages failed to install:
dates-0.2.2.1-ILbYRzHuQkwCfqySpiVks0 failed during the building phase. The
exception was:
ExitFailure 1

这是一个错误吗?以及如何解决它?

Semigroup class 现在是 GHC 8 中基础的一部分。4.x:

class Semigroup a where
  (<>) :: a -> a -> a
  GHC.Base.sconcat :: GHC.Base.NonEmpty a -> a
  GHC.Base.stimes :: Integral b => b -> a -> a
  {-# MINIMAL (<>) #-}
        -- Defined in ‘GHC.Base’

但在旧版本的 GHC 中,它不是基础的一部分,最初位于 semigroups 包中。比 semigroups 更老的是 semigroup,您正在尝试安装它,并且与现在 base 的一部分有类似的冲突(感谢@Li-yao 的评论)。所以 semigroup,包,不应该与较新的 ghc/base.

一起使用

你的第二个问题是 dates 的版本没有为新的基础更新,这要求所有 Monoid 实例也是 Semigroup 的实例:

class Semigroup a => Monoid a where
  mempty :: a
  mappend :: a -> a -> a
  mconcat :: [a] -> a
  {-# MINIMAL mempty #-}
        -- Defined in ‘GHC.Base’

您可以提交 dates 包的问题。