如果我执行$ 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这是一个bug吗?如何解决这个问题?
发布于 2018-06-03 01:19:55
在GHC 8.4.x中,Semigroup类现在是基础的一部分:
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中,它不是base的一部分,最初存在于semigroups包中。比semigroups更老的是semigroup,你正在尝试安装它,它与现在base的一部分有类似的冲突(感谢@Li-yao的评论)。因此,半组包不应该与较新的ghc/base一起使用。
您的第二个问题是dates的版本没有针对新的基础进行更新,这要求所有么半群实例也是Semigroup的实例:
class Semigroup a => Monoid a where
mempty :: a
mappend :: a -> a -> a
mconcat :: [a] -> a
{-# MINIMAL mempty #-}
-- Defined in ‘GHC.Base’您可以向dates包提交一个问题。
https://stackoverflow.com/questions/50658624
复制相似问题