Il De Santa
Il De Santa

Reputation: 85

Can not load a file that uses standard libraries in haskell

Hi I use GHCI and can normally load my files. Now I need to load a file that uses random. I get this error.

Chatterbot.hs:3:1: error:
    Could not find module ‘System.Random’
    Use -v to see a list of the files searched for.
  |
3 | import System.Random
  | ^^^^^^^^^^^^^^^^^^^^

This is very weird since it works for my friend who also have just installed GHCI and did nothing other than me. The main difference is that I am on windows. I really don t understand this and have tried googling a bit and many people speak about stack but it seems annoying and It obviously works for my friend without it.

Thanks in advance

EDIT problem solved. I needed to update cabal then I ran cabal install random and it worked well. Thanks everyone for the help!

Upvotes: 2

Views: 712

Answers (2)

danidiaz
danidiaz

Reputation: 27766

If you are using a version of cabal-install >= 3.0 (check with cabal --version), then, instead of creating a cabal package, you can move to an empty folder and type:

cabal install --lib --package-env . random

This creates a .ghc.environment file in the folder. ghci sessions started inside that folder will pick it up, and they will be able to import System.Random.

If that works correctly, you might want to install "random" globally so that any invocation of ghci can use it:

cabal install --lib random

This creates/modifies the global environment file located at ~/.ghc/$ARCH-$OS-$GHCVER/environments/default.

Upvotes: 5

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 477210

The System.Random module is part of the random package, not of the base package. You thus should install it. If you for example use cabal, you can install it with cabal install random.

If you use Haskell stack for example, you can add it to your package-name.cabal file:

  -- …
  build-depends:
      base >=4.7 && <5
    , random >=1.0 && <2

Upvotes: 1

Related Questions