Что вызывает ошибку установки этого модуля (NumberTheory) в cabal? - PullRequest
1 голос
/ 05 мая 2020

Я получаю следующую ошибку при попытке установить модуль теории чисел для Haskell

PS C:\Users\prker\Desktop\Haskell SFs> cabal new-install NumberTheory -j1
Wrote tarball sdist to C:\Users\prker\Desktop\Haskell
SFs\dist-newstyle\sdist\Haskell-SFs-0.1.0.tar.gz
Resolving dependencies...
Build profile: -w ghc-8.6.5 -O1
In order, the following will be built (use -v for more details):
 - NumberTheory-0.1.0.1 (lib) (requires build)
Configuring library for NumberTheory-0.1.0.1..
Preprocessing library for NumberTheory-0.1.0.1..
Building library for NumberTheory-0.1.0.1..
[1 of 1] Compiling NumberTheory     ( NumberTheory.hs, dist\build\NumberTheory.o )

NumberTheory.hs:422:10: error:
    * Could not deduce (Semigroup (GaussInt a))
        arising from the superclasses of an instance declaration
      from the context: Monoid a
        bound by the instance declaration at NumberTheory.hs:422:10-42
    * In the instance declaration for `Monoid (GaussInt a)'
    |
422 | instance (Monoid a) => Monoid (GaussInt a) where
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Warning: Some package(s) failed to build. Try rerunning with -j1 if you can't
see the error.

Это похоже на синтаксическую ошибку в самом модуле, но это маловероятно. Я попытался переустановить Cabal и убедиться, что все остальные модули обновлены.

1 Ответ

1 голос
/ 05 мая 2020

На основе информации о Hackage пакет был опубликован в феврале 2016 года. На тот момент последний выпуск пакета base было base-4.8.2.0. В этом пакете есть Monoid класс типов :

class Monoid a where
        mempty  :: a
        -- ^ Identity of 'mappend'
        mappend :: a -> a -> a
        -- ^ An associative operation
        mconcat :: [a] -> a

Но, таким образом, это не требует, чтобы члены были экземпляр класса типов Semigroup, фактически этот класс типов еще не существует.

Начиная с base-4.11.0.0, определение было изменено на:

class <b>Semigroup a =></b> Monoid a 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 = (<>)
        {-# INLINE mappend #-}

        -- | Fold a list using the monoid.
        --
        -- For most types, the default definition for 'mconcat' will be
        -- used, but the function is included in the class definition so
        -- that an optimized version can be provided for specific types.
        mconcat :: [a] -> a
        mconcat = foldr mappend mempty

Таким образом, требуется, чтобы типы, являющиеся членами класса типов Monoid, также были членами класса типов Semigroup . Библиотека, конечно, этого не ожидала.

Причина, по которой система все еще стремится скомпилировать это, заключается в том, что описание пакета из NumberTheory говорит:

  build-depends:       <b>base ==4.*</b>, containers ==0.5.*, primes ==0.2.*

Таким образом, предполагается, что он может собрать программное обеспечение с любой версией базовой версии 4.*, поэтому 4.11 и выше по-прежнему считаются хорошими кандидатами.

...