首页 > 解决方案 > 为什么我不能在 Stack 项目中使用 Text.Regex?

问题描述

我想要的只是使用正则表达式解析一个简单的字符串。

第一个问题:我应该使用 Text.Regex 还是其他东西?Stackage 列出了至少 11 个正则表达式包。我不在乎它是 PCRE 还是 Posix。在这一点上,我会接受任何事情。

第二个问题:如何在我的项目中包含 Text.Regex?这是我到目前为止的经验:

package.yaml 有

dependencies:
- base >= 4.7 && < 5
- regex

stacky.yaml 尝试 1

extra-deps:
- regex-1.0.1.3

对堆栈构建的响应

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

In the dependencies for regex-1.0.1.3:
    base-compat-0.10.5 from stack configuration does not match >=0.6 && <0.10  (latest matching version is 0.9.3)
    template-haskell-2.13.0.0 from stack configuration does not match >=2.7 && <2.12  (latest matching version is 2.11.1.0)
needed due to CCompiler-0.1.0.0 -> regex-1.0.1.3

Some different approaches to resolving this:

  * Set 'allow-newer: true' to ignore all version constraints and build anyway.

  * 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 /Users/adamfrank/Dev/Haskell/CCompiler/stack.yaml:

- base-compat-0.9.3
- template-haskell-2.11.1.0

Plan construction failed.

stack.yaml 尝试 2 个额外的依赖:- regex-1.0.1.3 - base-compat-0.9.3 - template-haskell-2.11.1.0

对堆栈构建的响应:

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

In the dependencies for regex-1.0.1.3:
    template-haskell-2.13.0.0 from stack configuration does not match >=2.7 && <2.12  (latest matching version is 2.11.1.0)
needed due to CCompiler-0.1.0.0 -> regex-1.0.1.3

Some different approaches to resolving this:

  * Set 'allow-newer: true' to ignore all version constraints and build anyway.

  * 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 /Users/adamfrank/Dev/Haskell/CCompiler/stack.yaml:

- template-haskell-2.11.1.0

Plan construction failed.

???

它说我需要添加我已经添加的行。

我需要不同版本的正则表达式吗?如果是这样,是哪一个,我该如何弄清楚?

标签: haskell

解决方案


评论中有一些关于使用什么的建议:regex-base,但理解它为什么不编译也很好。

Stackage 提供了每个 LTS 中兼容包的列表。您可以更改某些版本号,只要它们尊重其他依赖项的版本约束即可。并非所有这些依赖限制都在来自 Hackage 的包中得到很好的定义,这也是使用 Stackage 的原因之一。

通常,每个堆栈主要 LTS 版本都与特定版本的 GHC 相关联,该版本也具有特定版本的base. 当您选择 LTS 的主要版本时,您也选择了 GHC 和base. 如果您想更改 GHC 和/或base版本,更改 LTS 版本会更容易。Stackage LTS页面上 LTS 版本之后的第一件事就是 GHC 版本号。

在您的情况下regex,需要一个违反其他依赖项约束的template-haskelland版本。base-compat


推荐阅读