首页 > 解决方案 > Cabal 无法安装日期和半组

问题描述

如果我执行$ 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

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

标签: haskellcabal

解决方案


Semigroup 类现在是 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软件包提出问题。


推荐阅读