Cabal Install trouble resolving dependencies - haskell

I'm following this tutorial trying to set up a Haskell project: http://shuklan.com/haskell/lec10.html#/0/9
I've had this issue before with 'cabal install'.
I get the message below. I read to try 'rm -rf ~/.ghc ~/.cabal'. I tried that and 'cabal install' again, along with 'cabal new-build' but I still get the same message.
How can I fix this? I'm on Mac OS X 10.11.4. I can make and run .hs files and us ghci. I've never created a "file structure" or anything like that with other programming languages, so I'm not familiar with what's involved.
Thank you!!
Please switch to using either the new project style and the new-install
command or the legacy v1-install alias as new-style projects will become the
default in the next version of cabal-install. Please file a bug if you cannot
replicate a working v1- use case with the new-style commands.
For more information, see: https://wiki.haskell.org/Cabal/NewBuild
Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] trying: FirstCabalInit-0.1.0.0 (user goal)
[__1] next goal: base (dependency of FirstCabalInit)
[__1] rejecting: base-4.12.0.0/installed-4.1... (conflict: FirstCabalInit =>
base==4.6.*)
[__1] rejecting: base-4.12.0.0, base-4.11.1.0, base-4.11.0.0, base-4.10.1.0,
base-4.10.0.0, base-4.9.1.0, base-4.9.0.0, base-4.8.2.0, base-4.8.1.0,
base-4.8.0.0, base-4.7.0.2, base-4.7.0.1, base-4.7.0.0, base-4.6.0.1,
base-4.6.0.0, base-4.5.1.0, base-4.5.0.0, base-4.4.1.0, base-4.4.0.0,
base-4.3.1.0, base-4.3.0.0, base-4.2.0.2, base-4.2.0.1, base-4.2.0.0,
base-4.1.0.0, base-4.0.0.0, base-3.0.3.2, base-3.0.3.1 (constraint from
non-upgradeable package requires installed instance)
[__1] fail (backjumping, conflict set: FirstCabalInit, base)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: base, FirstCabalInit ```

You can find the following guide to build tools in Haskell useful:
https://kowainik.github.io/posts/2018-06-21-haskell-build-tools
According the error message, it looks like in your .cabal file you have a line like
build-depends: base == 4.6.*
This version of the standard library base is very old, it corresponds to GHC-7.6, however, according to the error message, you have GHC-8.6.5 installed. Since base versions are bundled with GHC, you can't use base for GHC you didn't install. See the following list of matching base and GHC versions:
https://wiki.haskell.org/Base_package
It looks like your error can be resolved by the following fix:
build-depends: base == 4.12.*
For the future, I can recommend using ghcup tool to manage GHC and cabal-install versions on macOS:
https://www.haskell.org/ghcup/
Alternatively, you can use stack build tool, it manages GHC versions for you in a sandboxed location.

Famous "cabal hell".
You're better use newest package manager https://docs.haskellstack.org/en/stable/README/ .

Related

How to install a local library using Cabal?

I am a total Haskell beginner, and am going through the Hudak book Haskell School of Expression. I am working on the graphics chapter, and have found an updated version of the book's graphics library: https://github.com/noughtmare/haskell-school-of-expression. However, when I run cabal v1-build, I get
Resolving dependencies...
Warning: solver failed to find a solution:
Could not resolve dependencies:
[__0] trying: SOE-0.1.0.0 (user goal)
[__1] next goal: base (dependency of SOE)
[__1] rejecting: base-4.12.0.0/installed-4.12.0.0 (conflict: SOE => base>=4.13
&& <4.15)
[__1] fail (backjumping, conflict set: SOE, base)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: SOE, base
Trying configure anyway.
Configuring SOE-0.1.0.0...
cabal-3.6.2.0.exe: Encountered missing or private dependencies:
GLFW-b, base >=4.13 && <4.15, freetype2, old-time
I do know that base is just the Haskell Prelude, which I know I have, so I have no idea what to do here. Thanks!
The specific error you're seeing occurs because the version of GHC you have installed is not compatible with that package.
The reason is that the base package version is locked to a specific GHC version, so you cannot use newer versions of base with older versions of GHC. See this wiki page for a list of the corresponding GHC version for each base version.
You could upgrade to a newer GHC version, such as 8.10.7.
An alternative is to run cabal with --allow-older=base.
And now I have actually updated the package to change the lower bound from 4.13 to 4.12, so it should compile fine if you pull the latest changes.
Also, I would recommend using the default v2-build, but that is not immediately related to the error you're seeing.

How to fail fast(er) when trying to update a package in Haskell?

Problem
In a very used library
haddock we have
#if MIN_VERSION_ghc(9,2,0) && !MIN_VERSION_ghc(9,3,0)
Those hidden dependencies make it into the built binary.
So, say, haddocset builds just fine thanks to stack.yaml targeting lts-12.0, with extra-dependency
extra-deps:
- haddock-api-2.20.0
- haddock-library-1.6.0
And then when running the actual executable
haddock: internal error: /Users/nicolas/.stack/programs/x86_64-osx/ghc-8.4.4/lib/ghc-8.4.4/settings: openFile: does not exist (No such file or directory)
Updating with Stackage
To update haddocset to lts-18.25 as far as I understand I have to update the "extra-deps" which entails to
check GHC version (in my case from LTS-18.25 so ghc 8.10.7).
check which version of the base library 8.10.7 comes with in the release notes so 4.14.3.0
browse through hackage to find which version of that package has a compatible base library so its haddock-api-2.24.0
same for finding hsdev-0.3.1.4 hdocs-0.4.4.1
then stack build suggests to add
- MonadCatchIO-transformers-0.3.1.3#sha256:468a6f12fd3821d2ab6301cc3543930c05e5117118917c6857ea383bdcc96c54,1127
- ghc-syb-utils-0.2.3.3#sha256:fc4cd944bbd4d5160b2ee8bb458974a135c0abbd9941fb6e5f9180164efd091a,1302
which look compatible on hackage.
Then I get an error from ghc-syb-utils
ghc-syb-utils > /private/var/folders/nw/tfpqw8w97hq8kw7kvf1qst2w0000gn/T/stack-03a7d85958fa8f57/ghc-syb-utils-0.2.3.3/GHC/SYB/Utils.hs:258:64: error:
ghc-syb-utils > • Could not deduce (Outputable (HsOverLit RdrName))
which says something on ghc-syb-utils (ghc (>=7.10 && <8.6)) and something else on github ("GHC 8.0 or later is not supported")
So I can't build this binary for 8.10.7/LTS-18.25.
Updating with Cabal
I am no expert at all on cabal, because having random build plan depending on what is currently published is both totally mad for end-users, and a great freedom for library authors who want their updates to be picked up everywhere silently. And I am just a user here, wanting to install a binary.
Of course the project haddocset as it is does not build with cabal anymore, although nothing has changed, because (I think) of the said madness, either with v1-build or v2-build prayer. Maybe some way do exist. I just don't know.
If in the cabal file one set the bounds for base and ghc, relax the upper bounds for the other dependencies, or else, there are only the usual message about "backjumping" from those invocation
🕙[ 04:42:14 ] [💣 1] ❯ cabal-3.4.1.0 v1-build
Resolving dependencies...
Warning: solver failed to find a solution:
Could not resolve dependencies:
[__0] trying: haddocset-0.4.3 (user goal)
[__1] next goal: base (dependency of haddocset)
[__1] rejecting: base-4.12.0.0/installed-4.12.0.0 (conflict: haddocset =>
base>=4.14.3.0 && <5)
[__1] fail (backjumping, conflict set: base, haddocset)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: haddocset, base
Trying configure anyway.
Configuring haddocset-0.4.3...
cabal-3.4.1.0: Encountered missing or private dependencies:
base >=4.14.3.0 && <5,
conduit,
conduit-extra,
haddock-api >=2.15,
hsdev,
http-types,
resourcet,
sqlite-simple
🕙[ 04:42:11 ] [💣 130] ❯ cabal-3.4.1.0 v2-build
Resolving dependencies...
cabal-3.4.1.0: Could not resolve dependencies:
[__0] trying: haddocset-0.4.3 (user goal)
[__1] next goal: base (dependency of haddocset)
[__1] rejecting: base-4.12.0.0/installed-4.12.0.0 (conflict: haddocset =>
base>=4.14.3.0 && <5)
[__1] rejecting: base-4.16.0.0, base-4.15.1.0, base-4.15.0.0, base-4.14.3.0,
base-4.14.2.0, base-4.14.1.0, base-4.14.0.0, base-4.13.0.0, base-4.12.0.0,
base-4.11.1.0, base-4.11.0.0, base-4.10.1.0, base-4.10.0.0, base-4.9.1.0,
base-4.9.0.0, base-4.8.2.0, base-4.8.1.0, base-4.8.0.0, base-4.7.0.2,
base-4.7.0.1, base-4.7.0.0, base-4.6.0.1, base-4.6.0.0, base-4.5.1.0,
base-4.5.0.0, base-4.4.1.0, base-4.4.0.0, base-4.3.1.0, base-4.3.0.0,
base-4.2.0.2, base-4.2.0.1, base-4.2.0.0, base-4.1.0.0, base-4.0.0.0,
base-3.0.3.2, base-3.0.3.1 (constraint from non-upgradeable package requires
installed instance)
[__1] fail (backjumping, conflict set: base, haddocset)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: base, haddocset
Question
What are the fastest way, either with stack or with cabal, to spot that there are real code issue in ghc-syb-utils, so that it's not just a matter of updating dependencies ?

Dificoulties installing gloss and other packages with cabal

I am trying to install gloss but, I dont know why ghci doesn't find the modules.
When I do cabal install gloss it says:
Up to date
Warning: You asked to install executables, but there are no executables in
target: gloss. Perhaps you want to use --lib to install libraries instead.
When I do cabal install -lib gloss it gives me thies error:
Resolving dependencies...
cabal.exe: Could not resolve dependencies:
[__0] trying: bytestring-0.11.0.0 (user goal)
[__1] next goal: directory (user goal)
[__1] rejecting: directory-1.3.6.1 (constraint from user target requires
==1.3.6.0)
[__1] trying: directory-1.3.6.0/installed-1.3.6.0
[__2] next goal: Win32 (dependency of directory)
[__2] rejecting: Win32-2.6.1.0/installed-2.6.1.0 (conflict:
bytestring==0.11.0.0, Win32 => bytestring==0.10.10.0/installed-0.10.10.0)
[__2] rejecting: Win32-2.10.1.0, Win32-2.10.0.0, Win32-2.9.0.0, Win32-2.8.5.0,
Win32-2.8.4.0, Win32-2.8.3.0, Win32-2.8.2.0, Win32-2.8.1.0, Win32-2.8.0.0,
Win32-2.7.0.0, Win32-2.6.2.0, Win32-2.6.1.0, Win32-2.6.0.0, Win32-2.5.4.1,
Win32-2.5.3.0, Win32-2.5.2.0, Win32-2.5.1.0, Win32-2.5.0.0, Win32-2.4.0.0,
Win32-2.3.1.1, Win32-2.3.1.0, Win32-2.3.0.2, Win32-2.3.0.1, Win32-2.3.0.0,
Win32-2.2.2.0, Win32-2.2.1.0, Win32-2.2.0.2, Win32-2.2.0.1, Win32-2.2.0.0,
Win32-2.1.0.0, Win32-2.1, Win32-2.5.4.0 (conflict: directory =>
Win32==2.6.1.0/installed-2.6.1.0)
[__2] fail (backjumping, conflict set: Win32, bytestring, directory)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: ghc, bytestring, Win32, directory
Try running with --minimize-conflict-set to improve the error message.
This is very strange because the firs time I used this command it worked perfectly but then when I tried to do on ghci ´´´import ...´´´ it sayd: Module not found.
I have tried other modules and it gives me the same error. I thought that the issue could be that ghc is not able to search in the cabal folder where the packages are saved but I am no longer sure.
How can I fix this? Thanks

How to downgrade base with cabal?

I'm trying to install a program called clanki on Windows 10. In it's installation doc it says to use 'cabal install clanki'. I downloaded cabal, then ghc. Now I run into a version problem for the package base.
$ cabal install clanki
Resolving dependencies...
cabal.exe: Could not resolve dependencies:
trying: clanki-1.2.7 (user goal)
next goal: base (dependency of clanki-1.2.7)
rejecting: base-4.9.0.0/installed-4.9... (conflict: clanki => base<=4.9.0)
rejecting: base-4.9.0.0, base-4.8.2.0, base-4.8.1.0, base-4.8.0.0,
base-4.7.0.2, base-4.7.0.1, base-4.7.0.0, base-4.6.0.1, base-4.6.0.0,
base-4.5.1.0, base-4.5.0.0, base-4.4.1.0, base-4.4.0.0, base-4.3.1.0,
base-4.3.0.0, base-4.2.0.2, base-4.2.0.1, base-4.2.0.0, base-4.1.0.0,
base-4.0.0.0, base-3.0.3.2, base-3.0.3.1 (constraint from non-upgradeable
package requires installed instance)
Dependency tree exhaustively searched.
So clanki requires base to be older than 4.9 (stack says this more clearly than cabal), and I then would like to downgrade base to 4.8.2.0. When I try ghc-pkg unregister base, it doesn't allow me. Not even with --force:
$ ghc-pkg unregister base --force
unregistering would break the following packages: xhtml-3000.2.1 Win32-2.3.1.1 transformers-0.5.2.0 time-1.6.0.1 template-haskell-2.11.0.0 process-1.4.2.0 pretty-1.1.3.3 hpc-0.6.0.3 hoopl-3.10.2.1 haskeline-0.7.2.3 ghci-8.0.1 ghc-boot-th-8.0.1 ghc-boot-8.0.1 ghc-8.0.1 filepath-1.4.1.0 directory-1.2.6.2 deepseq-1.4.2.0 containers-0.5.7.1 Cabal-1.24.0.0 bytestring-0.10.8.1 binary-0.8.3.0 array-0.5.1.1 (ignoring)
As I mentioned, I tried also with stack, but in the end it also comes down to the wrong version of base. How can I downgrade this package?
According to #leftroundabout’s answer, the upper bound on base in this package is bogus. In such a case, or simply if you feel bold, you can instruct cabal to ignore upper bounds on dependencies with the appropriate option:
cabal install clanki --allow-newer=base
You can't. base is fixed to the GHC install; the only way to get a different version is to install an older compiler, i.e. GHC-7.10. stack would automatically do that for you, but I wouldn't be sure if that's the best solution.
Likely enough, the package will actually work with GHC-8.0; in fact the constraint base <= 4.9.0 indicates that it should. That constraint doesn't make a lot of sense since it only allows the pre-first subrevision; it should probably really be base < 4.10.
So the best thing would be to download the source from github, where base does in fact not have the upper bound, and install it from the local folder with cabal install. If that works, notify the author to relax the bound on Hackage.
If it doesn't compile in GHC-8.0, again the best thing would be to make it work by editing the source and then file a pull request.
Alternatively, I'd then resort to stack for installing the package with an older GHC. To do this, get the source code with the base < 4.9 constraint (you need to insert that in the github code), and run stack setup, stack init and stack install.

My installed transformers version is not considered by cabal-install

I am totally new to Haskell an cabal and I'm trying to make yesod work.
My cabal version is cabal-install version 1.20.0.3
using version 1.20.0.2 of the Cabal library
This is what happends when I tru to install alex:
$ cabal install alex
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: alex-3.1.4 (user goal)
next goal: QuickCheck (dependency of alex-3.1.4)
rejecting: QuickCheck-2.8.1, 2.8 (global constraint requires ==2.7.6)
trying: QuickCheck-2.7.6
next goal: transformers (dependency of QuickCheck-2.7.6)
rejecting: transformers-0.4.3.0, 0.4.2.0, 0.4.1.0, 0.3.0.0, 0.2.2.1, 0.2.2.0,
0.2.1.0, 0.2.0.0, 0.1.4.0, 0.1.3.0, 0.1.1.0, 0.1.0.1, 0.1.0.0, 0.0.1.0,
0.0.0.0, 0.4.0.0 (global constraint requires installed instance)
Dependency tree exhaustively searched.
Second attempt:
$ cabal install alex happy yesod-bin --allow-newer
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: alex-3.1.4 (user goal)
trying: QuickCheck-2.7.6/installed-1a8... (dependency of alex-3.1.4)
trying: tf-random-0.5/installed-ef3... (dependency of
QuickCheck-2.7.6/installed-1a8...)
next goal: primitive (dependency of tf-random-0.5/installed-ef3...)
rejecting: primitive-0.5.0.1/installed-8e5... (global constraint requires
==0.6)
rejecting: primitive-0.6 (conflict: tf-random =>
primitive==0.5.0.1/installed-8e5...)
rejecting: primitive-0.5.4.0, 0.5.3.0, 0.5.2.1, 0.5.1.0, 0.5.0.1, 0.5, 0.4.1,
0.4.0.1, 0.4, 0.3.1, 0.3, 0.2.1, 0.2, 0.1 (global constraint requires ==0.6)
Dependency tree exhaustively searched.
What do I have to do to install alex?
A related question is this one:
cabal install --- global constraint requires installed instance
The comment by #kosmikus on that question is:
So the Stackage LTS config file contains the constraint transformers
installed, meaning that only an already present version of
transformers can be used. This is reasonable, because GHC ships with a
specific version of transformers. For ghc-7.8, this is
transformers-0.3.0.0. For some reason, this installed version is not
considered by cabal-install. Your partial log doesn't contain
sufficient info to see why.
How can I fix my Stackage LTS config file? Where is it on Ubuntu?
Try this cabal install alex --allow-newer
The reason of the problem was that my GHC was too old. I downloaded a newer version and solved the problem.
Failed (and wrong) attempt
You should have a cabal.config file in your current directory. Open it with any text editor and serach for the transformers installed string.
Once you have found it, replace it with transformers ==0.4.3.0 or any other version you like.
It is a bad solution, because, as dfeurer writes:
transformers sits very far down in the package dependency structure. I
believe it depends only on base; I imagine a large majority of
packages on Hackage depend, directly or indirectly, on it. If you
upgrade transformers, practically every dependency in the system will
go screwy, which is the opposite of what you're going for if you're
using Stackage.
Clean solution by Sibi
Use the stackage packages as it is. If you have some global package causing problem, then remove them and use stackage exclusively. Also using sandbox for each project is a good idea.

Resources