Stack doesn't work like that. The idea behind Stack is this: you have a project, you know the dependencies of this project, and Stack ensures you can always build that project – now or in the future. Stack is not about tweaking your system in some way that'll give you access to some packages here and now.
So, if you're going to use Stack for development (which I personally don't, but I also don't say it's a bad idea; lots Haskellers do this) then you should first set up the file you're working on as part of a project. This can be as simple as making your file a Stack snippet: add the following to the top of your file (I'll assume it's called script.hs
)
#!/usr/bin/env stack
{- stack --resolver lts-13.0 --install-ghc
runghc --package multiset
-}
(You could also pass those flags on the command line for stack
, but that gets tedious quickly. env
really does nothing else, but consistently.)
Then make your file executable – on Linux or OSX this can be done with chmod +x script.hs
– and all you need to do to compile & run that script will be ./script.hs
. (Not stack script.hs
or ghc script.hs
.) The great thing about this is that you get “instant continuous integration”: if Stack is able to build run your script on your computer now, you can be pretty sure that it'll also work on any other computer in the future, without you needing to remember what packages to install etc..
More info on that technique: https://www.fpcomplete.com/blog/2016/08/bitrot-free-scripts.
If it's more than a simple script you're writing, you should make a proper Cabal/Stack configuration for it. This can be created easily with cabal init
(regardless of whether you will use Cabal or Stack).
--package multiset
option to your command e.g.stack ghc --package multiset myfile.hs
. Not putting this as an answer as I don’t know exactly which command you’re using for compilation. (Also,stack install
is discouraged, especially for libraries.) – bradrn