Mark Karavan
Mark Karavan

Reputation: 2674

Trying to install System.Random on stack

I'm using stack 1.6.1. In src/Main.hs I start with

module Main where

import System.IO
import System.Random
...

I do not use anything from System.Random at this time.

When I run stack ghci I get

/Users/mkaravan/end2end/Music/music/src/Main.hs:4:1: error:
    Could not find module ‘System.Random’
    Use -v to see a list of the files searched for.
  |
4 | import System.Random
  | ^^^^^^^^^^^^^^^^^^^^

I've had no luck with any of the following commands:

stack install System.Random
stack install system.random
stack install random

I get this error:

>>> stack install System.Random
Error parsing targets: Directory not found: System.Random

How do I get System.Random to run in Stack?

Upvotes: 1

Views: 3981

Answers (2)

mgsloan
mgsloan

Reputation: 3295

You probably need to add random to the dependencies section in your package.yaml (or if you are not using hpack, to build-depends in *.cabal). This tells stack that the package depends on the random package, which contains the System.Random module.

Upvotes: 4

Michael Snoyman
Michael Snoyman

Reputation: 31315

Probably the most straightforward command is stack ghci --package random. But in theory stack install random should have worked as well. However, since you haven't included the output from that call, it's not clear what didn't work with it.

Upvotes: 4

Related Questions