1

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
Kastor438
  • 37
  • 8
  • 1
    Weird. What happens when you add `bytestring` to the `build-depends` of your library? Also your `stack.yaml` looks wrong. The `packages` section should specify the local packages that are part of your project. It's not for dependencies. Finally, is there a `package.yaml` file in this project? – sjakobi Apr 08 '22 at 21:46
  • @sjakobi I will edit my question to reflect all this – Kastor438 Apr 08 '22 at 21:52
  • My impression is that `stack` simply ignores the .cabal file and only uses the `package.yaml` to determine dependencies and other configuration data. Adding `bytestring` to the `dependencies` in the `package.yaml` should fix your issue. Alternatively, you can delete the `package.yaml` and use only `maze.cabal` to configure the package metadata. FYI, `package.yaml` files are part of an alternative package format, hpack: https://github.com/sol/hpack#readme. – sjakobi Apr 08 '22 at 22:20
  • @sjakobi So did you mean for my package.yaml file to have the binary and bytestring part in the executable dependencies? or the regular the dependencies spot? – Kastor438 Apr 08 '22 at 22:24
  • @sjakobi I actually tried both options I mentioned, and with both options you mentioned. Error still exists in VsCode. I did just find out though, it now works with stack build and stack run, even with the error persisting in the ide. No idea how. – Kastor438 Apr 08 '22 at 22:31
  • I think the top-level `dependencies` field contains common dependencies, that can be used in both the library and the executable. – sjakobi Apr 08 '22 at 22:32
  • I'm not familiar with VsCode. – sjakobi Apr 08 '22 at 22:32
  • Add `byestring` to `package.yaml` under `dependencies` section. – Sibi Apr 10 '22 at 09:46

0 Answers0