【问题标题】:Why can't I use Text.Regex in my Stack project?为什么我不能在 Stack 项目中使用 Text.Regex?
【发布时间】:2018-12-08 14:06:44
【问题描述】:

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

第一个问题:我应该使用 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 额外的部门: - 正则表达式-1.0.1.3 - 基础兼容-0.9.3 - 模板-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.

???

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

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

【问题讨论】:

  • 似乎 regex-base 替换/增强了 Text.Regex。新的构建计划应该没问题。
  • 是否使用与 Text.Regex 相同的界面?另外,您是如何发现它替换了 Text.Regex 的?
  • 写在标题的正下方。 This is the interface
  • 你可以访问 stackage.org,选择一个解析器(一个 LTS 版本,如果你想要稳定的东西)然后检查它附带的包。例如,选择resolver: lts-12.21,我们会得到几个正则表达式库,我们可以将它们添加到我们的依赖项中——找到一个适合您的:stackage.org/lts-12.21

标签: haskell


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 2017-06-14
    • 2016-12-21
    • 2021-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-28
    • 2018-12-07
    • 1970-01-01
    相关资源
    最近更新 更多