How to install modules

Hello. I’m a beginner in Haskell. I want to install modules (for example System.Random), but I dont’ know how to do it. Some easy instructions?

1 Like

cabal install random

https://www.haskell.org/cabal/

1 Like

Ensure that cabal --version is >= 3.

In an empty folder, type

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

That should create a file named .ghc.environment.<somemorestuff> in the folder.

In that same empty folder, start ghci:

ghci

Some message like “Loaded package environment from…” should appear when starting.

Inside ghci, import System.Random.

Prelude> import System.Random

If, when installing the package, you omit the location of the package environment:

cabal install --lib random

then it updates a default package environment located somewhere in your home directory.

With a bit of luck, ghci invocations should pick this default environment, too, but explicitly writing –package-env . is more foolprof.

Some relevant links:

3 Likes

Note that this can cause conflicts (e.g. Cannot satisfy -package-id X11-1.9.1-As84WI1VImVHquwEDPbrTE), so the package-env method should be preferred.

1 Like

Thank you very much. It works!

1 Like