Search code examples
haskellcabal

Haskell project dependency installation


I'm learning Haskell and I keep running into dependency problems when trying to run any project that isn't a simple single file tutorial-like file(aka, a real project).

The one I'm currently fighting with is a tetris clone I thought would be fun and interesting to learn from. Description of game and code at github

I cloned the repo and ran cabal install and got

Resolving dependencies...
cabal: Could not resolve dependencies:
trying: tetris-hs-0.1.0.0 (user goal)
next goal: base (dependency of tetris-hs-0.1.0.0)
rejecting: base-4.5.0.0/installed-40b... (conflict: tetris-hs => base>=4.6 && <4.8)
rejecting: base-4.7.0.1, 4.7.0.0, 4.6.0.1, 4.6.0.0, 4.5.1.0, 4.5.0.0, 4.4.1.0,
4.4.0.0, 4.3.1.0, 4.3.0.0, 4.2.0.2, 4.2.0.1, 4.2.0.0, 4.1.0.0, 4.0.0.0,
3.0.3.2, 3.0.3.1 (global constraint requires installed instance)

I have no idea what this means, so I started searching for steps on setting up projects and landed on the cabal user guide. Started playing with variations of runhaskell Setup.hs configure --user and got a list of missing dependencies. When I try to install them with cabal install foo, sometimes it works, most of the time I get an error, ranging from things like, "Its already installed" to "There is no package named 'Foo'". One interesting one was after I installed netwire, I tried to install lens, and it replies, "cabal: The following packages are likely to be broken by the reinstalls: netwire-5.0.0"

If I try to just run runhaskell Main.hs it says, "Could not find module `Graphics.GLUtil'" and if I try to install Graphics.GLUtil, Graphics, or GLUtil, it says that there is no package of that name.

I need a cabal for dummies book or something.

EDIT: After updating ghc and cabal, I ran cabal install again and it started installing everything but after a few minutes it hit a bump and spit out this:

cabal: Error: some packages failed to install:
FTGL-2.0 failed during the configure step. The exception was:
ExitFailure 1
GLFW-b-1.4.6 depends on bindings-GLFW-3.0.3.3 which failed to install.
GLUtil-0.8.2 depends on vector-0.10.11.0 which failed to install.
JuicyPixels-3.1.7.1 depends on vector-0.10.11.0 which failed to install.
adjunctions-4.2 depends on distributive-0.4.4 which failed to install.
bifunctors-4.1.1.1 depends on distributive-0.4.4 which failed to install.
bindings-GLFW-3.0.3.3 failed during the configure step. The exception was:
ExitFailure 1
comonad-4.2.2 depends on distributive-0.4.4 which failed to install.
distributive-0.4.4 failed during the building phase. The exception was:
ExitFailure 1
free-4.9 depends on distributive-0.4.4 which failed to install.
graphics-drawingcombinators-1.5 depends on FTGL-2.0 which failed to install.
lens-4.4.0.2 depends on vector-0.10.11.0 which failed to install.
linear-1.10.1.2 depends on vector-0.10.11.0 which failed to install.
profunctors-4.2.0.1 depends on distributive-0.4.4 which failed to install.
semigroupoids-4.2 depends on distributive-0.4.4 which failed to install.
tetris-hs-0.1.0.0 depends on vector-0.10.11.0 which failed to install.
vector-0.10.11.0 failed during the building phase. The exception was:
ExitFailure 1

When I try to cabal install vector:

[ 5 of 19] Compiling Data.Vector.Fusion.Stream.Monadic ( Data/Vector/Fusion/Stream/Monadic.hs,    dist/build/Data/Vector/Fusion/Stream/Monadic.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package primitive-0.5.3.0 ... <command line>: can't load .so/.DLL for: libHSprimitive-0.5.3.0.so (libHSprimitive-0.5.3.0.so: cannot open shared object file: No such file or directory)
cabal: Error: some packages failed to install:
vector-0.10.11.0 failed during the building phase. The exception was:
ExitFailure 1

Solution

  • This isn't a full explanation, but I'll point out the problem and interpret things for you.

    next goal: base (dependency of tetris-hs-0.1.0.0)
    rejecting: base-4.5.0.0/installed-40b... (conflict: tetris-hs => base>=4.6 && <4.8)
    

    next goal: base. "Next goal" is silly fluff; cabal is just thinking out loud. Read that as "trying to satisfy this package."

    rejecting: base-4.5.0.0/installed-... This is the version you have installed.

    conflict: tetris-hs => base>=4.6... Version 4.5 won't work, because tetris-hs requires >=4.6.

    And then the rest of the message states, roughly, that you're not allowed to install more than one version of base.

    base, unsurprisingly, is the fundamental package; among other things, it's wired into GHC itself in various ways. So what this all boils down to is that your version of GHC is too old for the version listed in the package cabal file. You can either install the latest Haskell Platform, or try editing the .cabal file to allow older versions--but don't be surprised if compilation fails for other reasons.

    Edit: Read the other comments about cabal sandboxes. Sandboxes are not directly relevant to your question, but if you understand and use them, you'll avoid a whole category of confusing cabal problems in the future.