由于“基础版本无法获得”,无法安装 ghc-mod

Cannot install ghc-mod due to “unattainable version of base”

我正在尝试在 Windows 上安装 ghc-mod 库。使用 stack install ghc-mod 显示此冗长的错误消息:

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

In the dependencies for ghc-mod-5.8.0.0:
    Cabal-2.4.1.0 from stack configuration does not match >=1.18 && <1.25  (latest matching version is 1.24.2.0)
    base-4.12.0.0 from stack configuration does not match >=4.6.0.1 && <4.10  (latest matching version is 4.9.1.0)
    cabal-helper must match <0.8 && >=0.7.3.0, but the stack configuration has no specified version  (latest matching
                 version is 0.7.3.0)
    djinn-ghc must match <0.1 && >=0.0.2.2, but the stack configuration has no specified version  (latest matching
              version is 0.0.2.3)
    extra-1.6.17 from stack configuration does not match <1.6 && >=1.4  (latest matching version is 1.5.3)
    ghc-8.6.5 from stack configuration does not match >=7.6 && <8.2
    ghc-syb-utils must match <0.3 && >=0.2.3, but the stack configuration has no specified version  (latest matching
                  version is 0.2.3.3)
    haskell-src-exts-1.20.3 from stack configuration does not match <1.20 && >=1.18  (latest matching version is 1.19.1)    hlint-2.1.11 from stack configuration does not match <2.1 && >=2.0.8  (latest matching version is 2.0.15)
    monad-journal-0.8.1 from stack configuration does not match <0.8 && >=0.4  (latest matching version is 0.7.2)
    optparse-applicative-0.14.3.0 from stack configuration does not match >=0.13.0.0 && <0.14  (latest matching version
                                  is 0.13.2.0)
    temporary-1.3 from stack configuration does not match <1.3 && >=1.2.0.3  (latest matching version is 1.2.1.1)
needed since ghc-mod is a build target.

Some different approaches to resolving this:

  * Build requires unattainable version of base. Since base is a part of GHC, you most likely need to use a different
    GHC version with the matching base.

显然,我需要更改ghc 的版本,但我的版本高于要求的版本,因此更新无济于事。我应该降级吗?如何在不弄乱我的 ghc 生态系统的其余部分的情况下做到这一点?

使用 cabal 安装它会得到类似的结果。

stackage 中,您可以找到所有 LTS 版本和所有可以下载的可能版本:

here 是 ghc-mod:

所需的所有依赖项的列表

您需要检查您没有任何过时的或不匹配的。

抱歉,除非您愿意降级到 GHC 8.0,否则您无法执行此操作。请注意,在依赖项列表中显示 ghc (>=7.6 && <8.2)。没有GHC 8.1(奇数用于测试),所以它回到GHC 8.0.

Stackage 提供了已知可一起编译的软件包版本的精选列表,以及一个 GHC 版本。每个长期支持 (LTS) 都是这些版本的一组特定版本。从 Damián Rafael Lattenero 发布的列表中可以看出,这意味着要回到 LTS-9.21

问题是ghc-mod使用GHC作为库和编译器,所以它对版本非常敏感,你必须为两者使用相同版本的编译器ghc-mod 和您正在开发的软件;获得 ghc-mod 的工作版本后,您不能只为自己的程序切换到更高版本的 GHC。

假设你还想这样做,得到stack installed。然后编辑您的 ~/.stack/config.yaml 文件(在 Windows 上键入 stack path --stack-root 以查找其存储位置)。将其更改为 resolver: lts-9.21。然后说 stack install ghc-mod.