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.
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.
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.
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?
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).