Can't install "System.Random" by cabal - haskell

I try to install "System.Random" by cabal through Powershell & Git Bash.
getting this result.
PS C:\Users\xxx> cabal install random
Resolving dependencies...
Up to date
Warning: You asked to install executables, but there are no executables in
target: random. Perhaps you want to use --lib to install libraries instead.
And then I try to input like this
cabal install --lib random
Resolving dependencies...
and
cabal install random --lib
both output Resolving dependencies... Up to date without warning.
but ghci Could not find module `System.Random'
input cabal install random still having the same result with warning.

It is a bad idea to install packages globally, so cabal install doesn't do that. The package is built and placed into the Cabal package database, but GHC won't find it unless you specifically tell Cabal to point GHC at it:
cabal repl -b random # -b is short for --build-depends
# Note that cabal install isn't really necessary: the above command would have installed random if it wasn't there already
I think your Cabal/GHC installation might be outdated, however. When you do cabal install --lib random, recent versions of Cabal should write out an "environment file" at %APPDATA%\ghc\arch-os-ghcversion\environments\default, which GHC should then automatically read (GHCi should say something like Loaded package environment from ...), and it should then find the installed package. If you are using the latest version of everything,
cabal install --lib random
ghci
should work.

Related

Haskell: ghc package environment

Hi in my package toaster, i cabal v2-install lib:toaster --package-env ~/myenv/
In the ~/myenv/ dir, there is .ghc.environment.x86_64-linux-9.2.2
I've also set the environment variable to point to the myenv dir.
Unfortunately, cabal install doesn't update the environment.
Am i doing the wrong way?
when I runghc Hello.hs, it says that toaster is hidden.
Found the answer:
cabal install --lib lib:toaster --overwrite-policy=always --env ~/dev/haskell/pkg_env/
By default, cabal install only installs executables, storing libraries built along the way only in its cache. If you want the library to be put somewhere, you must add --lib to your cabal install line.

GHC does not see cabal package

This is my algorithm, which I have followed on my Mac to work with OpenGL.
$ cabal init sandbox
$ cabal install OpenGL
All done. They I import the module Graphics.Rendering.OpenGL and neither ghc or ghci see the module.
What have I done wrong?
As the comments say, when you install into a sandbox, you need to run ghc and ghci in the sandbox (i.e. via cabal commands like cabal repl or cabal build) to have access to the packages you have installed into a sandbox.

dependenacy libraries when installing svgcairo

I want to run a Setup.hs file to install svgcairo library, So I run first the command runhaskell Setup.hs configure --prefix=/usr/local but it's give me the following error :
Configuring svgcairo-0.13.0.1...
setup: At least the following dependencies are missing:
cairo >=0.13.0.0 && <0.14, glib >=0.13.0.0 && <0.14
This is confused me, since both cairo and glib are installed with the correct versions !
to make it convince, I have run the commands cabal install cairo and cabal install glib, and the following output appear:
Resolving dependencies...
All the requested packages are already installed:
cairo-0.13.0.6
Use --reinstall if you want to reinstall anyway.
Resolving dependencies...
All the requested packages are already installed:
glib-0.13.0.7
Use --reinstall if you want to reinstall anyway.
Note : I tried to run the Setup.hs file with runhaskell Setup.hs but its tell me that no command given (try --help)
cabal install defaults to installing to the local package database. Setup.hs defaults to installing to the global package database (hence will ignore anything installed in the local package database when trying to satisfy dependencies). You can change the behavior of either by passing --local or --global to the appropriate stage -- configure for Setup.hs, and configure or install for cabal.

How do you install packages/libraries without Cabal or Cabal-Install?

I'm trying to set up Haskell from scratch, on Ubuntu 11.04, without using the outdated Debian repository or Haskell-Platform.
I've installed GHC-7.0.4 from source with no problem, and now need to install Cabal (which appears to already be included in GHC in /usr/local/lib/ghc-7.0.4/Cabal-1.10.2.0) and Cabal Install.
The latter specifies several dependencies (parsec and network), each of which has several dependencies of their own (mtl, text, etc).
What's the command to install these packages, that I downloaded from hackage in tar.gz form?
Unpack, then runhaskell doesn't work.
I see Setup.lhs, but it's not clear what that's for or how to use it.
Most of the Haskell documentation I've found assumes you've installed from a repo or Haskell-Package and doesn't really explain this well.
cabal-install has a shell script that does this. If you download it from hackage and install it, you can start bootstrap.sh to install cabal-install. You can then use it to install other packages.
There are two different packages: Cabal and cabal-install. Cabal is a library, and cabal-install is an executable named cabal.
To install a package, cabal-install is an optional convenience wrapper around Cabal, but Cabal is required.
According to http://hackage.haskell.org/trac/ghc/wiki/Commentary/Libraries , Cabal is a 'zero-boot' package, so when you build GHC, Cabal and its dependencies are built for you automatically.
You can use ghc-pkg executable to check which packages are already installed:
# ghc-pkg list
Check if Cabal is in the list after you build GHC. If yes, you can install more packages without cabal-install using this documentation:
http://haskell.org/haskellwiki/Cabal/How_to_install_a_Cabal_package
I suggest you to install cabal-install first, and then install everything else using cabal-install executable. A usual commandine for global installation is this:
# runhaskell Setup configure
# runhaskell Setup build
# sudo runhaskell Setup install
Unpack a package tarball and run the commands in the folder with Setup.hs or Setup.lhs files. Note that a per-user non-root installation is also supported - Use runhaskell Setup configure --user
When you install cabal executable and its dependencies this way, use cabal install {package-name} to install more packages.
Note that Haskell Platform exists mostly because of the pain of installing cabal-install by yourself.

Haskell Cabal regenerate documentation for all installed packages

How can I generate and install documentation for all locally installed cabal packages? I turned on the documentation flag in ~/.cabal/config which means that all newly installed packages will have documentation also generated. But how to generate documentation for all already installed packages?
Is there a way to automatically cabal install --reinstall all already installed packages? And more importantly, is that a good idea?
If you have a recent-ish version of cabal-install (>= 0.10, I think), you can try doing
$ cabal install --reinstall --upgrade-dependencies world
Unfortunately, it didn't work in my case:
$ cabal install --dry-run --reinstall world
Resolving dependencies...
cabal: cannot configure Agda-2.2.10. It requires haskell-src-exts >=1.9.6 &&
<1.10
For the dependency on haskell-src-exts >=1.9.6 && <1.10 there are these
packages: haskell-src-exts-1.9.6. However none of them are available.
haskell-src-exts-1.9.6 was excluded because haskell-src-exts-1.11.1 was
selected instead
haskell-src-exts-1.9.6 was excluded because hlint-1.8.12 requires
haskell-src-exts ==1.11.*
If you bump into an error like this, you can try manually editing the ~/.cabal/world file.
Please note that cabal install --only-dep --reinstall does not work.
If you are using a sandbox, you can do
cabal sandbox delete
cabal sandbox init
cabal install -j --only-dep --enable-documentation
The -j option allows it to build in parallel.
You could try something like this in bash.
for pkg in `ghc-pkg list --simple`
do
cabal install $pkg --reinstall
done
But I really don't know, whether it's a good idea.

Resources