简体   繁体   中英

Cabal cannot install dates and semigroup

If I execute $ cabal install semigroup , I get the error

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
   |                      ^^^^^^^^^

(repeating itself at several other occurences)

Similarly if I $ 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

Is this a bug? and how to work around it?

The Semigroup class is now part of base in 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’

But in older versions of GHC it was not part of base and originally lived in the semigroups package. Older still than semigroups is semigroup which you are trying to install and similarly conflicts with what is now part of base (thanks @Li-yao for the comment). So semigroup, the package, should not be used with the newer ghc/base.

Your second problem is that version of dates is not updated for the new base, which requires all Monoid instances to also be an instance of Semigroup:

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

You could file an issue with the dates package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM