在 Haskell 中使用堆栈构建 Distribution.Simple 包失败
Failed to build Distribution.Simple package using stack in Haskell
堆栈命令 stack new my-project
创建一个自动生成的文件 Setup.hs,内容为:
import Distribution.Simple
main = defaultMain
但我的 vs code intellisense 只是告诉我
Could not load module ‘Distribution.Simple’
It is a member of the hidden package ‘Cabal-3.2.1.0’.
You can run ‘:set -package Cabal’ to expose it.
(Note: this unloads all the modules in the current scope.)
所以我尝试通过命令安装分发包
stack install distribution
但是我收到以下消息:
WARNING: Ignoring distribution's bounds on containers (==0.5.*); using containers-0.6.5.1.
Reason: allow-newer enabled.
WARNING: Ignoring distribution's bounds on random (==1.1.*); using random-1.2.0.
Reason: allow-newer enabled.
distribution> configure
distribution> Configuring distribution-1.1.1.0...
distribution> build
distribution> Preprocessing library for distribution-1.1.1.0..
distribution> Building library for distribution-1.1.1.0..
distribution> [1 of 8] Compiling Data.Distribution.Core
distribution>
distribution> Data\Distribution\Core.hs:173:10: error:
distribution> • Could not deduce (Semigroup (Distribution a))
distribution> arising from the superclasses of an instance declaration
distribution> from the context: (Ord a, Monoid a)
distribution> bound by the instance declaration
distribution> at Data\Distribution\Core.hs:173:10-53
distribution> • In the instance declaration for ‘Monoid (Distribution a)’
distribution> |
distribution> 173 | instance (Ord a, Monoid a) => Monoid (Distribution a) where
distribution> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
distribution>
-- While building package distribution-1.1.1.0 (scroll up to its section to see the error) using:
C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_3.2.1.0_ghc-8.10.7.exe --builddir=.stack-work\dist4b403a build --ghc-options " -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
该错误意味着您已经安装了该包,但它没有在您的项目中列为依赖项。您需要将其添加到 package.yaml
in library/dependencies
或您的 exe:
library:
source-dirs: src
dependencies:
- Cabal
(另请注意,您错过的包是消息中所述的 Cabal
,而不是 distribution
,它只是一个模块名称)
堆栈命令 stack new my-project
创建一个自动生成的文件 Setup.hs,内容为:
import Distribution.Simple
main = defaultMain
但我的 vs code intellisense 只是告诉我
Could not load module ‘Distribution.Simple’ It is a member of the hidden package ‘Cabal-3.2.1.0’. You can run ‘:set -package Cabal’ to expose it. (Note: this unloads all the modules in the current scope.)
所以我尝试通过命令安装分发包
stack install distribution
但是我收到以下消息:
WARNING: Ignoring distribution's bounds on containers (==0.5.*); using containers-0.6.5.1.
Reason: allow-newer enabled.
WARNING: Ignoring distribution's bounds on random (==1.1.*); using random-1.2.0.
Reason: allow-newer enabled.
distribution> configure
distribution> Configuring distribution-1.1.1.0...
distribution> build
distribution> Preprocessing library for distribution-1.1.1.0..
distribution> Building library for distribution-1.1.1.0..
distribution> [1 of 8] Compiling Data.Distribution.Core
distribution>
distribution> Data\Distribution\Core.hs:173:10: error:
distribution> • Could not deduce (Semigroup (Distribution a))
distribution> arising from the superclasses of an instance declaration
distribution> from the context: (Ord a, Monoid a)
distribution> bound by the instance declaration
distribution> at Data\Distribution\Core.hs:173:10-53
distribution> • In the instance declaration for ‘Monoid (Distribution a)’
distribution> |
distribution> 173 | instance (Ord a, Monoid a) => Monoid (Distribution a) where
distribution> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
distribution>
-- While building package distribution-1.1.1.0 (scroll up to its section to see the error) using:
C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_3.2.1.0_ghc-8.10.7.exe --builddir=.stack-work\dist4b403a build --ghc-options " -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
该错误意味着您已经安装了该包,但它没有在您的项目中列为依赖项。您需要将其添加到 package.yaml
in library/dependencies
或您的 exe:
library:
source-dirs: src
dependencies:
- Cabal
(另请注意,您错过的包是消息中所述的 Cabal
,而不是 distribution
,它只是一个模块名称)