0
votes

I created a new project using the stack new Proj-Name simple command, and in a file I created within the /src directory imported a module outside of GHC's base library, import System.Process. Running stack build was successful, and the file worked as I expected it to. However, when I ran stack ghci within the same directory it did not have System.Process listed as an importable module.

How do I make it so that all my imported modules are importable within stack ghci?

2
That behaviour sounds quite surprising. In principle, you shouldn't be able to stack build without process in the build-depends of the .cabal file. My guess would be that the real issue here is that the file you created in /src was not added to the relevant sections of the .cabal-file (i.e. either exposed-modules or other-modules). If that is the case, your file is being ignored by stack build and the other commands.duplode
I think you've pinpointed the problem. I'll update the answer I gave accordingly, but not immediately; feel free to edit it or post your own.Nicholas Montaño

2 Answers

1
votes

While the information in Nicholas Montaño's answer is correct, I believe it doesn't reach the root of the issue. The likely cause of the problem is that the newly created source file wasn't declared in the cabal file, leading stack to ignore it. Every source file in a project must be declared in a section of the cabal file, be it exposed-modules (for parts of libraries which you want to expose to the users of your code) or other-modules (for internal modules which you do not want to expose).

1
votes

When you run stack new ..., even with the simple template, you'll notice that several files are created which allow for stack to work. One of these is a Proj_Name.cabal file, and if you open it, you'll notice that under the executable Proj_Name section of the file there's a main-is: Main.hs line.

The default main-is file will be Main.hs, but it may be anything. Your imports should go within whatever file you want to act as your main file. So in this case, you can simply put whatever the name of that file you created (which has the System.Process import) in place of Main.hs in that line.

Following this, run stack build, add whatever dependencies it tells you to under the build-depends: base >= 4.7 && < 5 line in Proj_Name.cabal, which in this case will look like:

build-depends:       base >= 4.7 && < 5
                   , process

run stack build again (if there are any further issues you might want to consult the stack guide, and now stack ghci should have all the modules that you imported in that file available to it.