I'm pretty new to Haskell, and I think I have a fundamental misunderstanding somewhere. When I'm in GHCi (using the ghci
command), I can type import System.Random
, and it works. I can then generate random numbers.
Next, I make a file called test.hs
that contains nothing but one line: import System.Random
. I then call the command ghc test.hs
and get the following error message:
test.hs:1:1: error:
Could not find module ‘System.Random’
There are files missing in the ‘random-1.1’ package,
try running 'ghc-pkg check'.
Use -v to see a list of the files searched for.
|
1 | import System.Random
| ^^^^^^^^^^^^^^^^^^^^
However, if I go back to GHCi, I can type :load test.hs
. This works, and allows me to generate random numbers.
When I run ghc-pkg check
, I get only warnings about missing haddock interface files: https://pastebin.com/6a9f0nYZ. From what I understand, this isn't related to the current issue.
Also, when I run ghc-pkg list
, random-1.1
is in the list, so random
should be installed.
A couple of questions:
- Why would GHC and GHCi have access to different imports? Why is the system set up that way? Maybe I just don't understand the relationship between GHC and GHCi.
- According to the error message, there are "files missing." How can I figure out which files?
- How can I make it so that I can compile Haskell files that use
System.Random
?
Edit: Both GHC and GHCi are the same version.
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.6.4
$ ghci --version
The Glorious Glasgow Haskell Compilation System, version 8.6.4
Edit: Both ghc
and ghci
are in /usr/bin/
$ which ghc
/usr/bin/ghc
$ which ghci
/usr/bin/ghci
which ghc
andwhich ghci
show? I imagine you may have two copies of haskell installed, one of which is broken. – amalloy/usr/bin/
. How could I figure out if/where/how I have two copies of Haskell installed? – Finn