ghci can't find package after package installed with cabal

Viewed 413

Did a fresh install of Haskell following instructions from https://www.haskell.org/ghcup/.

Used cabal to install package regex-tdfa-1.3.1.1

PS C:\Users\collumww\Documents\scr0> cabal install regex-tdfa --lib
Resolving dependencies...
Up to date
PS C:\Users\collumww\Documents\scr0>

Verified package is intact:

PS C:\Users\collumww\Documents\scr0> ghc-pkg --package-db=C:\cabal\store\ghc-8.10.2\package.db list
C:\cabal\store\ghc-8.10.2\package.db
    regex-base-0.94.0.2
    regex-compat-0.95.2.1
    regex-posix-0.96.0.1
    regex-posix-clib-2.7
    regex-tdfa-1.3.1.1

PS C:\Users\collumww\Documents\scr0>

I clearly see that it's in a different package database.

Now, I want to do

import Text.Regex.TDFA

ghci can't find it:

PS C:\Users\collumww\Documents\scr0> ghci
GHCi, version 8.10.2: https://www.haskell.org/ghc/  :? for help
Prelude> import Text.Regex.TDFA

<no location info>: error:
    Could not find module `Text.Regex.TDFA'
    It is not a module in the current program, or in any known package.
Prelude>

I know I'm missing something simple, and have looked all over and found numerous things about packages but the only ones that mention ghc (or ghci) not being able to find one propose the cabal command I show as the solution.

1 Answers

I found the answer this morning.

ghc didn't know about the package database that cabal had built and downloaded packages into. There is a flag on the ghc command to add a package database to the database stack.

First, though, I needed to find cabal's package database:

PS C:\Users\collumww> gci c:/cabal -r -i *.db


    Directory: C:\cabal\store\ghc-8.10.2


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----         12/2/2021   2:36 PM                package.db


PS C:\Users\collumww>

Then, in order to see what package databases are being used by ghc, use the -v flag like this:

PS C:\Users\collumww> ghc -v
Glasgow Haskell Compiler, Version 8.10.2, stage 2 booted by GHC version 8.8.3
*** initializing package database:
Using binary package database: C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.10.2\lib\package.conf.d\package.cache
package flags []
loading package database C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.10.2\lib\package.conf.d
wired-in package ghc-prim mapped to ghc-prim-0.6.1
wired-in package integer-wired-in mapped to integer-gmp-1.0.3.0
wired-in package base mapped to base-4.14.1.0
wired-in package rts mapped to rts
wired-in package template-haskell mapped to template-haskell-2.16.0.0
wired-in package ghc mapped to ghc-8.10.2
!!! initializing package database: finished in 15.63 milliseconds, allocated 7.342 megabytes
*** Deleting temp files:
Deleting:
*** Deleting temp dirs:
Deleting:
ghc.exe: no input files
Usage: For basic information, try the `--help' option.
PS C:\Users\collumww>

I saw ghc was using only the default one. So, with the -package-db flag, ghc is told to also look in the one that cabal built, and voila, I can now import the module:

PS C:\Users\collumww> ghci  -package-db C:\cabal\store\ghc-8.10.2\package.db
GHCi, version 8.10.2: https://www.haskell.org/ghc/  :? for help
Prelude> import Text.Regex.TDFA
Prelude Text.Regex.TDFA>
Related