Search code examples
haskellatom-editorhaskell-stackghc-mod

Haskell Stack: installed packages are not visible


I installed package with stack install but I cannot import the package unless I use stack ghc or stack ghci ...

The problem is I have installed atom haskell ide, that uses ghc-mod backend, which also doesn't see packages installed by stack!


Solution

  • You'll want to ensure that you have a ghc-mod that is both recent and built by the same version of ghc as the one your project is using. Do this by installing with stack (using the same resolver as your project). e.g.

    $ stack install --resolver lts-6.11 ghc-mod
    $ which ghc-mod
    /Users/steshaw/.local/bin/ghc-mod
    $ ghc-mod --version
    ghc-mod version 5.5.0.0 compiled by GHC 7.10.3
    

    To test this, perhaps set up an example project with stack new.

    $ stack new example
    $ cd example
    

    Change example.cabal to include, say, the HTTP package for the example-exe.

    e.g.

    executable example-exe
      hs-source-dirs:      app
      main-is:             Main.hs
      ghc-options:         -threaded -rtsopts -with-rtsopts=-N
      build-depends:       base
                         , example
                         , HTTP
      default-language:    Haskell2010
    

    Build with stack to install the HTTP package.

    $ stack build
    

    Now start Atom.

    $ atom .
    

    You should find that the imports from HTTP are visible within Atom.

    HTTP imports