Reputation: 555
I am working on Ubuntu 16.04 with stack ghci version 8. I want to import System.Random in Haskell but it seems I am having trouble that may involve Cabal. I have seen similar posts on this website but they usually say it is because of an older version but I am using version 8.
I get the error:
Failed to load interface for ‘System.Random’
Use -v to see a list of the files searched for.
which tells me I have problems with System.Random. Looking online, I found that I need to first install Cabal.
When I type
Cabal --version
I get
cabal-install version 1.22.6.0
using version 1.22.5.0 of the Cabal library
which tells me I already have it. So when I try to update with
sudo apt-get install cabal-install cabal update
I get
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package cabal
E: Unable to locate package update
which is weird. If I ignore it and try to install random anyways through
cabal install random
I get
Resolving dependencies...
All the requested packages are already installed:
random-1.1
Use --reinstall if you want to reinstall anyway.
So it seems I also have the random package of cabal. But I can't load a program with the
import System.Random
command.
EDIT: It seems I have stack ghci version 8.0.1 and ghci version 7.10.3. The System.random loads in ghci but not stack ghci.
I also get the following when I try to load a file in stack. Entering
stack ghci R.hs
I get
Warning: Couldn't find a component for file target /home/aa/workspace/share/haskell/chenw/hw4/R.hs. Attempting to load anyway.
Configuring GHCi with the following packages:
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/aa/.ghc/ghci.conf
Loaded GHCi configuration from /tmp/ghci19674/ghci-script
Does this mean there is something wrong with my install of stack?
Upvotes: 3
Views: 16353
Reputation: 2411
If you want to use stack
, and assume you have a working stack
, you don't have to install anything via apt-get
.
First, update your stack
stack update
Make sure you having the right resolver
version number for your packages
stack ghci <source.hs>
. Check ~/.stack/global-project/stack.yaml
. stack
, i.e,. stack new <project>
, stack build
. Check project's stack.yamlTo use stack
globally (anywhere)
stack install random
stack ghci
and :load <source.hs>
stack ghc <source.hs>
stack exec <executable_name>
You can force stack to use specific resolver by using --resolver=
.
Example: using latest lts
$ stack --resolver=lts setup
$ stack --resolver=lts install random
$ stack --resolver=lts ghci
To use stack
in a project directory (stack.yaml
exists), you don't need to install package manually; stack
will install it for you, if needed, when stack build
. But you have to edit <project.cabal>
build-depends: base >= 4.7 && < 5
, random
Upvotes: 6