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:

7 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

I want to install System.Random too.
The answers you give above work, I’m sure but I tried using cabal list System.Random and instead of clarifying the exact name of the module to use, cabal listed tens of modules with similar names. I was enable to know which module was from the System and which are made by some other peers.

How do I know that the package listed with cabal list is from the System library ?

This is also described here: First steps - GHCup

1 Like