Haskell 包 Data.ByteString 问题

发布于 2025-01-20 00:15:22 字数 2479 浏览 3 评论 0原文

所以我看到另一篇文章,有人解决了这个问题,但他们只是说他们解决了,而我不能。

我正在开发的项目需要 Data.ByteString 来读取二进制文件。我的 Main.hs 上出现此错误。

Could not load module ‘Data.ByteString’
It is a member of the hidden package ‘bytestring-0.10.8.2’.
You can run ‘:set -package bytestring’ to expose it.
(Note: this unloads all the modules in the current scope.)

现在,我的 stack.yaml 文件和 .cabal 文件中分别有此相关代码。

resolver: lts-14.27
packages:
- bytestring >= 0.10.8.2
- binary >= 0.7.5
library
  exposed-modules:
      Lib
  other-modules:
      Paths_maze
  hs-source-dirs:
      src
  build-depends:
      base >=4.7 && <5
  default-language: Haskell2010

executable maze-exe
  main-is: Main.hs
  other-modules:
      Paths_maze
  hs-source-dirs:
      app
  ghc-options: -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , maze
    , bytestring >= 0.10.8.2
    , binary >= 0.7.5
  default-language: Haskell2010

我不明白我错过了什么,任何帮助总是值得赞赏。 另外,是的,我对 Haskell 很陌生。

编辑

(响应 tosjakobi 的评论)

更新:

  • .cabal 文件已将依赖项添加到其库部分
  • stack.yaml 文件已删除二进制和字节串。这就是堆栈文件在新建时最初的样子,除了我根据教授的选择更改了解析器。我什至不知道其中的区别。
  • package.yaml 文件现在位于以下

文件(相关代码):

stack.yaml 文件

resolver: lts-14.27
packages:
- .

package.yaml 文件

dependencies:
- base >= 4.7 && < 5

library:
  source-dirs: src

executables:
  maze-exe:
    main:                Main.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - maze

tests:
  maze-test:
    main:                Spec.hs
    source-dirs:         test
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - maze

.cabal 文件

library
  exposed-modules:
      Lib
  other-modules:
      Paths_maze
  hs-source-dirs:
      src
  build-depends:
      base >=4.7 && <5
    , bytestring >= 0.10.8.2
    , binary >= 0.7.5
  default-language: Haskell2010

executable maze-exe
  main-is: Main.hs
  other-modules:
      Paths_maze
  hs-source-dirs:
      app
  ghc-options: -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , maze
    , bytestring >= 0.10.8.2
    , binary >= 0.7.5
  default-language: Haskell2010

So I seen another post where somebody figured this out but they just said they figured it out and I can't.

I need Data.ByteString for a project I'm working on to read a binary file. I get this error on my Main.hs.

Could not load module ‘Data.ByteString’
It is a member of the hidden package ‘bytestring-0.10.8.2’.
You can run ‘:set -package bytestring’ to expose it.
(Note: this unloads all the modules in the current scope.)

I now have this relevant code in my stack.yaml file and .cabal file respectively.

resolver: lts-14.27
packages:
- bytestring >= 0.10.8.2
- binary >= 0.7.5
library
  exposed-modules:
      Lib
  other-modules:
      Paths_maze
  hs-source-dirs:
      src
  build-depends:
      base >=4.7 && <5
  default-language: Haskell2010

executable maze-exe
  main-is: Main.hs
  other-modules:
      Paths_maze
  hs-source-dirs:
      app
  ghc-options: -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , maze
    , bytestring >= 0.10.8.2
    , binary >= 0.7.5
  default-language: Haskell2010

I don't understand what I'm missing, any help is always appreciated.
Also yes I am very new to Haskell.

EDIT

(in response tosjakobi's comment)

Updates:

  • .cabal file had dependencies added to it's library section
  • stack.yaml file had binary and bytestring removed. This is how the stack file was originally when it was made new, except I changed the resolver based on my professors given choice. I don't even know the difference.
  • package.yaml file is now below

Files (relevant code):

stack.yaml file

resolver: lts-14.27
packages:
- .

package.yaml file

dependencies:
- base >= 4.7 && < 5

library:
  source-dirs: src

executables:
  maze-exe:
    main:                Main.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - maze

tests:
  maze-test:
    main:                Spec.hs
    source-dirs:         test
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - maze

.cabal file

library
  exposed-modules:
      Lib
  other-modules:
      Paths_maze
  hs-source-dirs:
      src
  build-depends:
      base >=4.7 && <5
    , bytestring >= 0.10.8.2
    , binary >= 0.7.5
  default-language: Haskell2010

executable maze-exe
  main-is: Main.hs
  other-modules:
      Paths_maze
  hs-source-dirs:
      app
  ghc-options: -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , maze
    , bytestring >= 0.10.8.2
    , binary >= 0.7.5
  default-language: Haskell2010

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文