Adding dependencies to stack project

I am very new to Haskell and I am trying to add the graphics package gloss to my stack project but I am encountering problems when doing stack build.

I have created my stack project as follows:

LICENSE         package.yaml        stack.yaml       package.yaml~       stack.yaml.lock
Setup.hs        project39.cabal     stack.yaml~
TAGS            project39.cabal~    test

and edited the stack.yamland the cabal file as follows:

# extra-deps:
# - acme-missiles-0.3
# - git:
#   commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# - gloss-
executable project39-exe
  main-is: Main.hs
  ghc-options: -threaded -rtsopts -with-rtsopts=-N
      base >=4.7 && <5
    , project39
    , gloss
  default-language: Haskell2010

In the src file Lib.hs I have added a Import Graphics.Gloss to test if it works:

module Lib
    ( someFunc
    ) where
import Graphics.Gloss

but when I then do stack build I get the following error:

    Could not load module ‘Graphics.Gloss’
    It is a member of the hidden package ‘gloss-’.
    Perhaps you need to add ‘gloss’ to the build-depends in your .cabal file.
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
4 | import Graphics.Gloss
  | ^^^^^^^^^^^^^^^^^^^^^

I am unsure what the problem here is and how to solve it.

1 answer

  • answered 2021-02-23 07:52 Masse

    You have a separate library stanza in your package.yaml. You need to add the gloss dependency there.