是什么导致 cabal 中的这个模块 (NumberTheory) 安装错误?
What is causing this module (NumberTheory) installation error in cabal?
我在尝试为 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 并确保所有其他模块都是最新的。
基于information on Hackage the package was published in february 2016. At that time latest release of the base
package was base-4.8.2.0
. In that package, there is a Monoid
typeclass:
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
type class 类型的成员。图书馆当然没有预料到这一点。
系统仍然打算编译它的原因是因为 NumberTheory
的 package description 说:
build-depends: <b>base ==4.*</b>, containers ==0.5.*, primes ==0.2.*
因此假设它可以使用版本 4.*
的任何版本的 base 构建软件,因此 4.11
及更高版本仍然被认为是很好的候选者。
我在尝试为 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 并确保所有其他模块都是最新的。
基于information on Hackage the package was published in february 2016. At that time latest release of the base
package was base-4.8.2.0
. In that package, there is a Monoid
typeclass:
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
type class 类型的成员。图书馆当然没有预料到这一点。
系统仍然打算编译它的原因是因为 NumberTheory
的 package description 说:
build-depends: <b>base ==4.*</b>, containers ==0.5.*, primes ==0.2.*
因此假设它可以使用版本 4.*
的任何版本的 base 构建软件,因此 4.11
及更高版本仍然被认为是很好的候选者。