对于 haskell 堆栈,我无法安装 Spock

For haskell stack I can't install Spock

对于 Stack,当我尝试为 Spock 使用堆栈安装时,它会给我这个错误(见下文)。

我尝试自己安装每一个(单独的软件包),但没有成功。 我试着按照 中的答案进行操作,但也没有用。

Error: While constructing the build plan, the following exceptions were encountered:

In the dependencies for Spock-0.13.0.0:
    Spock-core must match >=0.13, but the stack configuration has no specified version  (latest
               matching version is 0.13.0.0)
    reroute must match >=0.5, but the stack configuration has no specified version  (latest matching
            version is 0.5.0.0)
    stm-containers must match >=0.2 && <0.3, but the stack configuration has no specified version
                   (latest matching version is 0.2.16)
needed since Spock is a build target.

Some different approaches to resolving this:

  * Consider trying 'stack solver', which uses the cabal-install solver to attempt to find some
    working build configuration. This can be convenient when dealing with many complicated
    constraint errors, but results may be unpredictable.

  * Recommended action: try adding the following to your extra-deps
    in C:\Windows\system32\stack.yaml:

Spock-core-0.13.0.0@sha256:06e007f23c47bdda52d2927da54160d73f1b6f51a977f3ca9087275698db8f0a
reroute-0.5.0.0@sha256:3360747cdc700c9808a38bff48b75926efa443d4af282396082329a218a8d9d3
stm-containers-0.2.16@sha256:e98efa8dcf0045ea8a78a04b4e2763cf2d8bc33aad0750e2f30a67f8f4e933b1

Plan construction failed.

我要安装无误

此错误中的重要部分如下:

In the dependencies for Spock-0.13.0.0: Spock-core must match >=0.13, but the stack configuration has no specified version

基本上,这是正在发生的事情:主要的 Haskell 包存储库是 Hackage. However, Stack gets its packages from its own repository, known as Stackage。正如首页所说:

A Stackage snapshot includes pinned package versions from Hackage … It is a curated set of packages that work well together

然而,Stackage 有一个主要问题:它没有包含 Hackage 中的每个包。这表明该包在您正在使用的 Stackage 快照中没有指定版本。但这就是 Stack 的错误消息所说的!因此,用简单的英语来说,Stack 的错误表明 Spock-core 未包含在您选择的快照中。

那么,我们该如何解决这个问题?好吧,可以手动告诉 Stack 使用哪个包版本。事实上,这样做的说明包含在错误消息中:

  * Recommended action: try adding the following to your extra-deps
   in C:\Windows\system32\stack.yaml:

- Spock-core-0.13.0.0@sha256:06e007f23c47bdda52d2927da54160d73f1b6f51a977f3ca9087275698db8f0a
- reroute-0.5.0.0@sha256:3360747cdc700c9808a38bff48b75926efa443d4af282396082329a218a8d9d3
- stm-containers-0.2.16@sha256:e98efa8dcf0045ea8a78a04b4e2763cf2d8bc33aad0750e2f30a67f8f4e933b1

这里,C:\Windows\system32\stack.yaml是你的全局Stack配置文件的路径。要消除错误,您需要打开该文件并找到以 extra-deps: 开头的行。然后,删除该行并将其替换为从错误消息中获取的以下信息:

extra-deps:
- Spock-core-0.13.0.0@sha256:06e007f23c47bdda52d2927da54160d73f1b6f51a977f3ca9087275698db8f0a
- reroute-0.5.0.0@sha256:3360747cdc700c9808a38bff48b75926efa443d4af282396082329a218a8d9d3
- stm-containers-0.2.16@sha256:e98efa8dcf0045ea8a78a04b4e2763cf2d8bc33aad0750e2f30a67f8f4e933b1

这会通知 Stack 您要使用 Spock-core 的 0.13.0.0 版、reroute 的 0.5.0.0 版和 stm-containers 的 0.2.16 版。通常 Stack 可以使用适当的 Stackage 快照中的信息自行计算出此信息,但在这种情况下,快照不包含有关这三个包的信息,这就是为什么您必须自己指定此信息的原因。