I just upgraded to Fedora 33, and at least for Data.Vector and System.Random, I am getting stuff like:
Prelude> import Data.Vector
<no location info>: error:
Could not load module ‘Data.Vector’
It is a member of the hidden package ‘vector-0.12.1.2’.
You can run ‘:set -package vector’ to expose it.
(Note: this unloads all the modules in the current scope.)
Any ideas?
EDIT: I upgraded another system, and both modules are fine. Maybe some local cabal misconfiguration?
EDIT 2: ghc-pkg list shows both packages as non-hidden (ie they are not in parenthesis). What is overriding this?
EDIT 3: Removing .ghc/x86_64-linux-8.8.4/environments/default solves the issue. By looking at it, not all system packages are listed. Do I need that? How was it generated?
EDIT 4: The problem seems to be that cabal install --lib creates a default environment which does not include all the system packages. I'll file a bug...
I don't know the root cause but I would warn against using bare ghci on a modern Haskell install. Instead I would suggest cabal v2-repl --build-depends vector to ensure a compatible vector package is loaded.
Related
I try to use
Control.Monad.Extra.andM
import Control.Monad.Extra (andM)
but has an error:
Could not find module ‘Control.Monad.Extra’
Perhaps you meant
Control.Monad.Catch (needs flag -package-key exceptions-0.10.4)
Control.Monad.Error (needs flag -package-key mtl-2.2.2)
Control.Monad.Except (needs flag -package-key mtl-2.2.2)not found
This error does not make sense.
According to
https://cabal.readthedocs.io/en/3.6/installing-packages.html#installing-packages-from-hackage
3.2.1. Installing packages from Hackage
The cabal tool also can download, configure, build and install a Hackage package and all of its dependencies in a single step. To do this, run:
$ cabal install [PACKAGE...]
To browse the list of available packages, visit the Hackage web site.
Which says "in a single step", but in my experience this is too complicated and actually I have no idea how to install Control.Monad.Extra .
Usually, when a Haskeller want to install a specific library/package like this, how do you do this? There's no adequate documentations, it seems.
How to install an library in Haskell?
You don't. You should just depend on them, and then let Cabal worry about any installations that may need to be done. I.e., as you wrote
Go to the Hackage page and study which exact library to be used.
*.cabal file -> build-depends: extra >=1.7.10
This is the crucial step. Your own Cabal file is the way to both specify what libraries are needed right now, as well as ensuring that everything will still work in the future. This file needs to specify both the packages you require, as well as the modules you're defining yourself.
Probably you don't actually need >=1.7.10, but it can't hurt much to be specific there. Standard practice is to add both lower and upper bounds on the x.y level, i.e. you'd use extra >=1.7 && <1.8, and then push the upper boundary as new versions come out. Arguably this is a bit overcautious; if you only use some simple tools from a package that is unlikely to have breaking changes in the future then it may be less trouble to just leave the upper boundary out.
$ cabal install extra
You've already specified that extra is needed for your project, no need to state that again. Instead, simply build your own project now.$ cabal buildor, to get a GHCi prompt with your modules,$ cabal replor, if you have an executable with a main that you wish to execute$ cabal runor if you want to install that executable (and only then)$ cabal installCabal will then automatically figure out that extra-1.7.10 should be installed first.
(In old Cabal it would still have been necessary to run cabal install --dependencies-only first.)
Ok Self-Answered. Comment me if the information is wrong.
1. Go to the Hackage page and study which exact library to be used.
In this case, it seems extra-1.7.10.
2. *.cabal file -> build-depends: extra >=1.7.10 (among other libs)
3. $ cabal install extra
Error:
cabal: Cannot build the executables in the package extra because it does not contain any executables. Check the .cabal file for the package and make sure that it properly declares the components that you expect.
Well, I did for sure.
4. cabal install extra --lib
Finally works, but the documentation never said this.
Am I correct?
`
Is this the only method? or any other smarter way?
I was trying to build one new project in Haskell (GHC version 8.10.4, stack version 2.7.3, cabal version 3.6.2.0) using stack, but at the time of running the command stack setup I (surprisingly) got the following error:
Setup.hs:2:1: error:
Could not load module ‘Distribution.Simple’
It is a member of the hidden package ‘Cabal-3.2.1.0’.
You can run ‘:set -package Cabal’ to expose it.
(Note: this unloads all the modules in the current scope.)
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
2 | import Distribution.Simple
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Also, it is worth noting that I was trying to look for different solutions on the Internet, but didn't find the working one for me. The general idea was to explicitly add Cabal into the package.yaml file here:
library:
source-dirs: src
dependencies:
- Cabal
But that didn't save my situation. I was able to build the project without that step (well, just skipped that part), but I was interested to solve the issue.
Moreover, when I was trying to build Haskell package timeit (as an example, using the command line), there was the same error at the time of executing
runhaskell Setup.hs configure.
Interestingly, I didn't have this problem before (probably, it appeared after I updated GHC).
Does anybody know any ways of how to deal with such issue? Is there any way probably to reinstall the GHC, or cabal, or stack (if it helps)? Would be glad to see any comments and solutions.
Instead of deleting the
~/.ghc/*/environments/default
file, just add the Cabal package to it, including version number, which you can find if you run the command:
ghc-pkg list
I had the same issue.
Deleting the files
~/.ghc/*/environments/default
(or the whole folder .ghc) solved the stack setup problem.
It seems that they were somehow interacting with stack's operations.
I'm attempting to start a new project using the Snap web framework. I used snap init to get my basic skeleton working. I also put http://www.stackage.org/lts/cabal.config next to my .cabal file. I didn't uncomment the line to use Stackage exclusively. So I tried to build and it failed and couldn't find the version of lens required by my .cabal file. The cabal.config file from Stackage specifies a version of lens that is not the same as the one in my .cabal file. So I deleted every constraint from my package list and did the usual cabal install --only-dep -j8 --enable-test and it worked!
However, I have always been told that package versions should be constrained. So when working with Stackage is it okay to leave package versions unconstrained? Should I downgrade my packages to the ones available in Stackage instead?
As far as I understand a cabal.config file specifies a set of dependencies with the specific versions that satisfy dependencies, so how does Stackage work? Is it just a subset of packages from Hackage that are proven to be compatible? Do they host their own packages or rely on Hackage for downloads?
Thanks in advance :)
Both options are available. The default option is what you did, and still goes to hackage to get the packages. You just added a filter to your cabal that prevents you from using any version of a package included in Stackage that was not tested to work together with all of the other packages.
The other option is to simply point your cabal repo to a Stackage url, and then you will download packages directly from the Stackage server. That server will only serve packages that are known to work together, so there is no need for additional constraints in your cabal file. I actually prefer this way of working.
In both cases, if you have additional constraints in your cabal file that are incompatible with the Stackage restrictions, your build will fail. If you use the first option, you will get dependency conflicts. When using the second option, the Stackage server will simply report that it does not have that specific package/version.
I'm trying to install packages which require a different version of base than the one I have installed (I have 4.6.0.0, they require < 4.6). How can I install these on my system?
Edit: These packages actually require older packages in order to build, not just as a .cabal constraint.
Since you can't reinstall base, the only way to get these packages installed before they are updated is to grab the source,
cabal unpack foo
and then edit foo.cabal, changing the upper bound for base there, bump the package version (append a .1) so that when installing other packages cabal doesn't think it is broken, since the .cabal file it knows (from the package index) says it requires a different version of base, and
cabal install
from the directory you unpacked to.
Since there were a few significant changes in base-4.6; the Eq and Show superclasses have been removed from Num, and Bits no longer has Num as a superclass, it may be necessary to fix the code by adding Eq, Show or Num to the constraints of some functions to make the packages compile.
That's inconvenient, but the price for being up-to-date yourself with the newest GHC version for a few weeks.
If you just want one of your programs to depend on these packages, you can use cabal-dev as a drop-in replacement for cabal. The former installs local copies of packages in a cabal-dev path in the current directory. To install it, just run:
cabal install cabal-dev
For portability, you may add something like this to a makefile:
CABAL ?= cabal
build :
$(CABAL) build --builddir=$(BUILD_PATH)
Then in your Bash settings:
CABAL=cabal-dev
export CABAL
If a package isn't compatible with the base you currently have (i.e. just changing the constraint is insufficient), your only options are to port the package yourself or use an older ghc that provides the correct version of base.
You might want to check with the package maintainer first though. A development branch may already support what you need, and they just need a little prodding to release it.
Today when I tried to compile my code in Geany I got this error
Could not find module `Control.Monad.Reader':
it was found in multiple packages: monads-fd-0.1.0.1 mtl-1.1.0.2
Compilation failed.
I get the same for the Writer monad; I thought I should remove one of those packages, but I do not want to break other packages, so now what should I do, yesterday everything worked without any problem.
It looks like you have recently installed monads-fd, perhaps as a dependency of something else you installed. Both monads-fd and mtl packages contain the module Control.Monad.Reader, so GHC doesn't know which one to use when you compile some code that imports it. You need to resolve the ambiguity somehow:
If you are using GHC or GHCi directly
either use a -hide-package <package> flag on the command line to hide one of the packages, or
hide the package by default using ghc-pkg hide <package>. You may need to use ghc-pkg --user hide <package> if the package was installed in your home directory (the default on some platforms).
You can use Cabal, and say exactly which one of the conflicting packages you depend on using the build-depends field in your .cabal file
I encountered a similar problem recently, and it was suggested that I run ghc-pkg hide {x} where '{x}' is the name of one of those packages. It worked in my situation.