0
votes

I'm trying to install the sbv module https://hackage.haskell.org/package/sbv

Installation with Stack works great (no errors):

stack install sbv

but then I cannot import the corresponding module in stack ghci:

import Data.SBV

-- <no location info>: error:
--     Could not find module ‘Data.SBV’
--     Perhaps you meant Data.Set (from containers-0.6.2.1)

Now, when I try with Cabal instead:

cabal new-install sbv --lib

Everything runs smoothly on ghci

import Data.SBV
prove $ \x -> x `shiftL` 2 .== 4 * (x::SWord8)

--- Q.E.D.      (<-- this is the expected output)

However, still no luck with stack ghci (same error as before). This is the case whether stack install sbv was done globally or in the context of a Stack project.

Is there a way to make sbv work with the Stack installation (even if it was installed via cabal)?

1
You can specify the package when starting GHCi using stack ghci --package sbv, or use :set -package sbv within GHCi to make an installed package visible, although note that changing the package flags will reset your session. If you have several dependencies like this, it becomes much easier to list them in a project file so they’re available automatically.Jon Purdy
for a stack project, is there any difference between using a .cabal file, as @leftaroundabout suggested, or a stack.yaml file to mention dependencies?Jivan
@Jivan they are complementary. Essentially, the .cabal or package.yaml file specifies the direct dependencies of your own project without worrying about which particular versions of libraries actually work together, whereas stack.yaml specifies one concrete configuration that's known to work and where to get the packages from. In principle the .cabal file is enough, but stack.yaml can make your project more portable and future proof.leftaroundabout

1 Answers

4
votes

Stack has always eschewed the idea of manually installing libraries that could then be imported in files on that computer. (Cabal has more recently gone away from that too.) And there are very good reasons for this: relying on “at some point I typed this command” quickly leads to maintenance issues and duplicate work figuring out the dependencies again as soon as you try to run your code on another machine.

Thus, the recommended way is to always mention dependencies right where they're needed. For anything serious, you would use a .cabal (or hpack) file in your project; for smaller one-file stuff you can just make them Stack scripts.

If you don't have any files at all then... well, first, you may want to consider getting a file now... but you can also use the the Stack global project, which is what stack ghci will by defaul use.
Finally, you can also just mention the dependency right at the command line: stack ghci --package sbv.
I don't really recommend this, unless you're really just quickly trying out something.