无法在 Stack 项目中成功导入 Text.Regex.Posix

Unable to successfully import Text.Regex.Posix in Stack project

我正在尝试在 Haskell 源文件中使用 =~ 函数。 我已经使用 stack (stack install regex-posix-0.96.0.0) 安装了 Text.Regex.Posix 包并将其添加到我的 stack.yaml 文件的 extra-deps 数组中:

stack.yaml:

resolver: lts-15.5
packages:
- .
extra-deps:
  - regex-posix-0.96.0.0

在我的 Haskell 源文件中,我按如下方式导入 Text.Regex.Posix

module Lib (
 someFunc
) where

import Text.Regex.Posix

someFunc :: String -> Bool
someFunc str = str =~ "myregex"

但是,运行 stack ghci 我收到以下错误:

    Could not load module ‘Text.Regex.Posix’
    It is a member of the hidden package ‘regex-posix-0.96.0.0’.
    You can run ‘:set -package regex-posix’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
5 | import Text.Regex.Posix
  | ^^^^^^^^^^^^^^^^^^^^^^^

如何公开 =~ 函数? 谢谢!

您需要通过将其添加到 package.yaml 或 .cabal 文件中的 build-depends 来将其声明为包的依赖项。

你不需要在 extra-deps 中提及它,因为它在 lts-15 中。