删除 Stack/Cabal 个软件包并安装旧版本

Remove Stack/Cabal packages and install older versions

我是 Haskell 的新手,正在使用 Stack 在 Mac OSX 上构建一个小型个人项目。我最近在我的 cabal 文件中添加了一些新的构建依赖,但是现在当我 运行 stack build 时,我收到以下错误:

--  While attempting to add dependency,
    Could not find package api-builder in known packages

--  Failure when adding dependencies:
      api-builder: needed (==0.11.0.0), not present in build plan (latest applicable is 0.11.0.0)
      http-client: needed (==0.4.20), 0.4.27 found (latest applicable is 0.4.20)
      http-types: needed (==0.8.6), 0.9 found (latest applicable is 0.8.6)
    needed for package: music-haskell-0.1.0.0

Recommended action: try adding the following to your extra-deps in /Users/.../src/music-haskell/stack.yaml
- api-builder-0.11.0.0

You may also want to try the 'stack solver' command

当我 运行 stack solver 我收到有关 http-types 包的错误消息

cabal: Could not resolve dependencies:
trying: music-haskell-0.1.0.0 (user goal)
next goal: http-types (dependency of music-haskell-0.1.0.0)
rejecting: http-types-0.9 (conflict: music-haskell => http-types==0.8.6)
rejecting: http-types-0.8.6, 0.8.5, 0.8.4, 0.8.3, 0.8.2................
(global constraint requires ==0.9)
Dependency tree exhaustively searched.

据我了解,我似乎已经安装了 http-types-0.9,但现在我需要 http-types-0.8.6。我最初尝试使用 $stack install http-types 手动安装它,但出现以下错误:

Error parsing targets: Specified target version 0.8.6 for package http-types does not match snapshot version 0.9

当我查看是否可以做时 $ stack uninstall 但它看起来已被弃用。

如何摆脱 http-type 的 snapshot/global 目标??

您可以通过 extra-deps 覆盖 stack.yaml 文件中的特定快照包,例如:

extra-deps:
- http-types-0.8.6

一旦您开始包含版本范围与您正在使用的快照有冲突的包,您很快就会 运行 陷入这些问题。我推荐的解决方案是:

  • 请包维护者将他们的包放入 Stackage,这样您就不必 fiddle 手动设置版本
  • 尽可能坚持 Stackage 中的包

您可以自己将包添加到 Stackage,即使您不是作者也是如此。有关说明,请参阅 the maintainer guide