Neither cabal install nor cabal list do what you are expecting them too. The former will install executables not libraries (you need to pass the --lib flag for that). Even if you installed a library like that, it would be in the “store”, not the pkg-db – the former is a set of packages available to cabal to use, and the latter is the packages that ghc will “always” see. Install --lib places packages in the store, then makes them available via setting up a ghc environment file for them.
The recommended way to build projects is to create a cabal project for them, at which point all the library stuff is handled automatically, rather than through manual installation and configuration of environment fiels.
For a simple script, it is recommended again to not use manual package management, but instead a cabal script.
cabal path --output-format=json | jq -r '."store-dir" + "/" + .compiler.id + "-inplace/package.db"' this will give you the store-dir for the default GHC that cabal build package db for you.
e.g.
#!/usr/bin/env cabal
{- cabal:
build-depends:
base ^>=4.19.0.0,
haskell-say ^>=1.0.0.0
-}
import HaskellSay (haskellSay)
main :: IO ()
main = haskellSay "Hello, Haskell!"
Set permissions
chmod +x myscript.hs
And executed:
cabal run myscript.hs
However, I get:
Error: [Cabal-7136]
There is no <pkgname>.cabal package file or cabal.project file. To build packages locally you need at minimum a <pkgname>.cabal file. You can use 'cabal init' to create one.
For non-trivial projects you will also want a cabal.project file in the root directory of your project. This file lists the packages in your project and all other build configuration. See the Cabal user guide for full details.