First, I created a new workspace:
stack new xxxx
stack init
stack build
then
cd xxx\app
stack ghci
import Data.Map
I can import other modules like Data.Char
and Data.List
, but I can't import Data.Map
. GHCi told me:
Could not find module 'Data.Map'
It is a member of the hidden package 'containers-0.5.7.1@containers-0.5.7.1'.`
The reason you can import
Data.Char
andData.List
is that they are part of the packagebase
, which is included with GHC and is always loaded with GHCi. By contrast,Data.Map
is in the external librarycontainers
. One way to load it withstack ghci
is to add a cabal file with abuild-depends
oncontainers
. This will install it in the stack environment forxxxx
, so it will then be accessible.These general steps were helpful for me to resolve similar issues:
Use Hoogle or Stackage to find the package where the module resides
Note that Hoogle and Stackage are case-sensitive. Looking up
Data.Map
in Hoogle yields a list similar to the one below. Stackage has a slightly different style, but the basics are the same (mostly because it also uses Hoogle for lookup).The lines in green under the result headings show the name(s) of the containing
(1) package(s) (in small caps) and
(2) module(s) (capitalized).
Open
project-name.cabal
in project root and add required package underbuild-depends:
Issue
stack build
to download and build dependencies(or
stack ghci
if you plan to use it in the REPL)