ubuntu haskell ghci 7.4.1 could not find module "System.Random" - haskell

When I tried to load a .hs in ghci, it failed on the line:
import System.Random
Message:
Could not find module `System.Random'
Use -v to see a list of the files searched for.
I remember it worked yesterday and all of a sudden today it does not work.
This problem only occurs on Ubuntu 12.04 LTS, GHCi 7.4.1 , when i tried this on windows haskell platform and other linux machines i worked.
I tried to use
sudo apt-get remove ghc
sudo apt-get install ghc
to remove and re install ghc, but however the problem persists.
Could someone help me? Thanks

You must install the random package. You can probably get it from your package manager (as something like libghc-random-dev or similar), or you may cabal install random.
Edit in 2021 These days, cabal install is not the way. Instead, use cabal init to create a package and list random in your build-depends field. Compilation can be performed with cabal build (just build) or cabal run (to execute the result); interactive use is available via cabal repl.

Related

cabal install ghc impossible happened: heap overflow

I'm trying to follow along with the Plutus Pioneer lectures, and I'm getting this error
My system:
Ubuntu Linux Docker image running on MacOS.
I installed the Haskell package on the image from here: https://www.haskell.org/platform/linux.html
using this line in my Dockerfile: RUN apt-get install -y haskell-platform
This seems to install Cabal version 2.4.
When I clone the code repository for the lectures: https://github.com/input-output-hk/plutus-pioneer-program and then go to the week01 directory and try cabal build like in the lecture, I get dependencies not found errors. The first missing dependency is 'aeson', which seems to install if I run cabal install aeson.
The subsequent build attempts fail on dependency 'base' being the wrong version.
Then I thought maybe if I update Cabal to version 3.4 it might help, so I tried cabal install cabal-install, but this also has errors:
Theexception was:ExitFailure (-9)
This may be due to an out-of-memory condition.
So I googled some more and tried this command line: cabal install --ghc-options="+RTS -M600M" -j1 cabal-install from here https://stackoverflow.com/a/46148345/52236
This seems to get further, but now I'm at this error:
ghc: panic! (the 'impossible' happened)
(GHC version 8.6.5 for x86_64-unknown-linux): heap overflow
If anyone has any idea how to fix this it would be appreciated. Do I need to add more RAM to my Docker Ubuntu image? It currently has 1.9GB of memory and 1.7GB free.
thanks,
m
I fixed this by increasing the RTS param:
cabal install --ghc-options="+RTS -M1000M" -j1 cabal-install
Well, actually it compiled everything, but cabal --version still says 2.4, not 3.4. There was this warning too:
Warning: could not create a symlink in /root/.cabal/bin for cabal because the
file exists there already but is not managed by cabal. You can create a
symlink for this executable manually if you wish. The executable file has been
installed at /root/.cabal/bin/cabal

Cabal install command Gives error

I can't understand why it just dosen't work. My question is what might have gone wrong i have created the ~/.bash_profile and tried to add the PATH given by the haskell webpage.
When i preform cabal install i get this output:
Marcuss-MacBook-Pro:~ marcuslagerstedt$ cabal install
cabal: Error reading local package.
Couldn't find .cabal file in: .
Marcuss-MacBook-Pro:~ marcuslagerstedt$
I hope i did a correct question.
But i really need help aswell.
You seem to be wanting to install a particular package, namely agda. The command cabal install takes either the name of a package or assumes you are installing some package in the local directory. You are hitting this second case.
To install agda try:
cabal update
cabal install agda

Failing to install Haskell uniplate library

I am trying to install Elm and the instructions are to install Haskell and then
sh> cabal update
sh> cabal install cabal-install
sh> cabal install -j Elm elm-repl elm-reactor elm-get
When I do, the cabal-install installation installs text-1.2.0.0 which conflicts with the text-1.1.0.0 which uniplate requires so uniplate and its dependents fail to install. Text-1.1.0.0 is installed and present but is rejected in favour of text-1.2.0.0, even though the target needs text-1.1.0.0.
Is there a way to insist that cabal use text-1.1.0.0?
Is there a way to get text-1.1.0.0 and text-1.2.0.0 to co-exist?
Is there a way to convince uniplate that it can accept text-1.2.0.0?
Or a way to make uniplate (or cabal) believe that version text-1.1.0.0 is actually installed? Would that even work?
When I explicitly try to install version 1.1.0.0 of text, I am told that a reinstall would break other packages. Apparently it is a downgrade and not a co-installation. cabal does not seem to have an option to allow to me install two versions of the same library at the same time.
If I uninstall Haskell and all the libraries and then re-install Elm (without installing cabal-install so I don't get text-1.2.0.0 installed so there is no clash), I get 100 or so lines of
package aeson-0.7.0.4-8f84b14cc682e4c9b009352420076a45 is unusable due to missing or recursive dependencies:
attoparsec-0.10.4.0-ec2d0a330db1f6e3a6a3b79471a403ef hashable-1.2.2.0-45bd22df8c4ead6b3a7fb1d08bb07f7d mtl-2.1.3.1-8bcc0591131896cfc8761a93703d4c61 scientific-0.2.0.2-5e275f5d96527da6dc1f05642692a484 syb-0.4.1-be94ebe67c3607f5df1dfcc1906f5d5c text-1.1.0.0-9bd69e9ace700e05fb08e463086bc383 unordered-containers-0.2.4.0-69836b34d13649bcfacc8fb0c9f53e64 vector-0.10.9.1-c550551354bc7c2b5a1d261f39b2f3f4
package aeson-pretty-0.7.1-5dc26d5a4560afe110e90283479a1251 is unusable due to missing or recursive dependencies:
aeson-0.7.0.4-8f84b14cc682e4c9b009352420076a45
text-1.1.0.0-9bd69e9ace700e05fb08e463086bc383
unordered-containers-0.2.4.0-69836b34d13649bcfacc8fb0c9f53e64
vector-0.10.9.1-c550551354bc7c2b5a1d261f39b2f3f4
package asn1-encoding-0.9.0-94e9066cccf7ead73bee5ae4aa982071 is unusable due to missing or recursive dependencies:
mtl-2.1.3.1-8bcc0591131896cfc8761a93703d4c61
package asn1-parse-0.9.0-af4efc4777a8a0d9d19a626d5e4b08ff is unusable due to missing or recursive dependencies:
asn1-encoding-0.9.0-94e9066cccf7ead73bee5ae4aa982071
mtl-2.1.3.1-8bcc0591131896cfc8761a93703d4c61
text-1.1.0.0-9bd69e9ace700e05fb08e463086bc383
I have no idea at all how in resolve this or where to even try. Has anybody trod this path before and do you have any advice or pointers?
Thank you.
Edit
Installing in a sandbox changes the outcome only by degrees: text-1.1.0.0 does not clash with text-1.1.0.0 but still can not be loaded (despite being installed) and still remains the unsatisfied dependency.
blaze-builder is first to fail with cannot satisfy -package-id text-1.1.0.0-9bd69e9ace700e05fb08e463086bc383 yet the same log earlier stated [_12] trying: text-1.1.0.0/installed-9bd... (dependency of Elm-0.13) without apparent error or complaint.
cabal list shows both text-1.1.0.0 and text-1.2.0.0 as installed.
Installing blaze-builder separately looks the same. Dependency resolution shows
[_56] trying: blaze-builder-0.3.3.4 (user goal)
[_57] next goal: text (dependency of blaze-builder-0.3.3.4)
[_57] trying: text-1.1.0.0/installed-9bd...
[_58] done
All looks good but later, same log has
<command line>: cannot satisfy -package-id text-1.1.0.0-9bd69e9ace700e05fb08e463086bc383
(use -v for more information)
The ghc command line already had the -v flag and trying to re-run the command line copied from the log, with more -vs, gives an error with "can't find a package database at
dist/dist-sandbox-ad0bcd57/package.conf.inplace".
No package.conf.inplace seems to exist.
Further edit
On the Elm install page is a link to a BuildFromSource.hs script that is also supposed to work installing Elm. In the time that it took for that script to run and fail to work, I managed to install leiningen, node, npm, grunt and Clojure. I am now further along the road to getting Clojurescript installed in about 20 minutes than I am in getting Elm installed in nearly a week.
Elm looked really interesting but it is playing way too hard to get.
Thanks again to everyone who tried to help.
* Edit *
I finally got it.
Every executable installed by the installer at http://elm-lang.org/Install.elm caused a segfault.
The "Build from source" option at the same page did not work because the dependencies either stepped all over each other or could not get themselves straight in the first place.
The ghc at http://new-www.haskell.org/downloads/osx needs a later version of Mac OS than I have. (A link to older versions would not have gone astray.)
The solution (and it is obvious in retrospect) was to port install haskell-platform and port install hs-cabal-install and cabal install Elm .... I did have to run one of those installers twice because it could not find hackage.haskell.org (How is that a 'user' error?) but my hello-world.elm now compiles.
Thank you all again.
It looks like some dependency issues with elements you already have installed. You will probably need to install it in a sandbox.
First, update to the latest version of cabal:
$ cabal update
$ cabal install cabal cabal-install
Next, make sure you have the installed version of cabal on your $PATH.
$ which cabal
> /path/to/cabal/bin/cabal
If it says something like /usr/bin/cabal you will need to export cabal to be on your $PATH. For me this is `/home/username/.cabal/bin
$ export PATH=/path/to/cabal/bin/cabal;$PATH
Run which cabal again and ensure it is pointing to that path.
Now that you have the latest version of cabal. Run the following:
$ mkdir elm
$ cd elm
$ cabal sandbox init
This will initialize a sandbox where dependencies are completely independent of your other installs. Within this directory, you should be able to install the elm platform by running:
$ cabal install Elm elm-repl elm-reactor elm-get
These will be installed in a sub-directory called .cabal-sanbox/bin/ For convenience, you will probably want to add this to your $PATH so you can run the executables from any directory.
Hope this helps!

Cabal install hoogle not working

I need to configure eclipsefp and install hoogle and scion-browser for setting up a haskell project using mysql.
I tried to install hoogle and scion-browser from Eclipse -> Preference -> Helper executable, and also from the terminal, however unsuccessfully.
cabal install hoogle
and
cabal install scion-browser
fail, throwing the following:
cabal:codec.compression.zlib: premature end of compressed stream.
Edit:
It may be a problem with the cabal version?
If I run cabal --version in terminal, it says:
cabal-install version 0.14.0
using version 1.14.0 of the Cabal library
If I perform cabal update nothing happens.
However, in Eclipse -> Helper Executables there are two versions available:
version 0.14.0
version 1.18.0.2
They are located at different locations, I checked the second one to be used.
in my case, the downloaded package is broken, figured it out by running cabal install -v package-name, removed it manually and finally worked

Reinstall all depending packages with cabal manually [duplicate]

I want to compile my program with profiling, so I run:
$ cabal configure --enable-executable-profiling
...
$ cabal build
...
Could not find module 'Graphics.UI.GLUT':
Perhaps you havent installed the profiling libraries for package 'GLUT-2.2.2.0'?
...
$ # indeed I have not installed the prof libs for GLUT, so..
$ cabal install -p GLUT --reinstall
...
Could not find module 'Graphics.Rendering.OpenGL':
Perhaps you havent installed the profiling libraries for package 'OpenGL-2.4.0.1'?
...
So, the problem is, that unlike cabal's usual welcome behavior, cabal doesn't resolve the dependencies and install them when needing profiling libraries.
I can work around it by resolving the dependencies manually (by following errors that appear after a while of compiling):
$ cabal install -p OpenGLRaw --reinstall
$ cabal install -p StateVar --reinstall
$ cabal install -p Tensor --reinstall
$ cabal install -p ObjectName --reinstall
$ cabal install -p GLURaw --reinstall
$ cabal install -p OpenGL --reinstall
$ cabal install -p GLUT --reinstall
And then repeat for my next dependency..
Is there a better way to do this? i.e do make cabal do the work on its own as it does for normal libraries?
I've enabled library-profiling: True in my ~/.cabal/config file. From then on, any new installations will automatically enable profiling.
Unfortunately that still means I had to manually reinstall for the old packages already installed. Although, after a while of doing this manually, I now have most packages reinstalled with profiling enabled...
From a comment by Tom Lokhorst:
I do hope someone will come along with a better answer, one that would not require me to reinstall the complete Haskell Platform manually next time.
For future visitors:
The task of installing profiling versions of all installed libraries has become less of a chore, cabal (cabal-install) now keeps track of what was installed using it in the world file in the .cabal directory (on linux, that would be $HOME/.cabal, on Windows something like C:\Users\%YOU%\AppData\Roaming\cabal\, on OSX ??).
So after enabling profiling in the config file (in the same directory), and clearing GHC's package database (you can find the locations of the global and user db per ghc-pkg list nonexisting; remove the cabal-installed packages from the global database with ghc-pkg unregister packagename if you have any, rename or delete the entire user db - this is necessary because the world file only tracks explicitly installed packages, not their dependencies), installing everything with profiling support should work as follows:
$ cabal install --reinstall world --dry-run
First run with --dry-run to check for problems before actually reinstalling anything. If it would reinstall boot packages like process or directory, that's a bad sign, if you don't know how to handle it, ask on the #haskell IRC channel, one of the mailing lists, or here for guidance. If it fails to find a consistent install plan due to new versions on hackage of some packages which are incompatible with each other, that can usually be solved by editing the world file and constraining allowable versions of some packages.
Then, if you are optimistic that nothing will badly break,
$ cabal install --reinstall world
and have a nice pot of tea while GHC is busy compiling.
Daniel Fischer's answer looks good, but for some reason my ~/.cabal/world library only contained entries for libraries directly installed, and not their dependencies.
Instead, I dumped out a list of all installed libraries using
$ ghc-pkg list > list
This lists the libraries installed system-wide and locally. Therefore, I edited the list file to remove the first portion (containing libraries installed system-wide) leaving only the lines after /home/<user>/.ghc/.... Finally, I ran
$ cabal install --reinstall $(cat list)
This worked for me. You should maybe do --dry-run first. Then go make a pot of tea. Or bake a cake.
it appears there is no way right now: Ticket #282 - profiling versions of libraries not managed well "As usual the problem is lack of devevloper time to implement all these
nice features we all want."
For visitors 2016+: Just install ghc-prof
Debian Linux Systems:
sudo apt-get install ghc-prof
Arch Linux Systems:
sudo pacman -S ghc-prof

Resources