Could not find module in ghci

I installed Haskell through image with ghcup.
But the package I installed through cabal cannot be loaded in ghci
The pacakge can be loaded in ghc.Screenshot from 2022-04-15 10-55-49
How to let ghci detecte these packages?

See this section of the following guide:

In general running a command to install packages globally with cabal/stack is probably not what you want, what you want is to create an environment in which these packages will be available. You can do that as the guide suggests, or alternatively by creating a haskell project and define the dependencies in a cabal file.

1 Like

It doesn’t work.
I found that there is no file named “default” in my computer, However others’s computer have this file . The content of this file are like

clear-package-db
global-package-db
package-db C:\Users\..........
....

Do I need to manually add this file under the directory of GHC?

What exactly doesn’t work? Did you try running cabal repl --build-depends matrix --build-depends accelerate to open a repl with these packages loaded and that failed?
Or did you try to create a project with a cabal file and that failed?

It seems like you are trying a third option that I’m not familiar with.

3 Likes

I run the command cabal repl --build-depends matrix --build-depends accelerate ,The matrix can be loaded, but this is temporary. When I reentered ghci, it failed.
I have created a haskell project, and writen the dependencies in cabal file, It doesn’t work.

This is by design. The command starts ghci with these packages exposed. If you want the packages exposed when you start ghci, run the same command again.

Ok

Did you also run a cabal build, which would pull the dependencies listed in your .cabal file?

Since @wujilingfeng1 wants to run GHCi I suspect cabal repl would have been more appropriate.

Yes, I dit it. The ghci couldn’t load the packages installed by cabal.

You still have to run cabal repl, not ghci.

This is nowadays somewhat discouraged but, if you go to your local project folder, and invoke

cabal install --lib  --package-env . nameofthelibraryyouwanttotry

subsequent ghci invocations in that same folder should find the module (explanation here, another explanation).