2

I wanted to use the Control.Monad.Except module, but it turned out I had an outdated mtl package (It caused an import error - I had an obsolete module Control.Monad.Error). So I did

sudo cabal install mtl

And it installed the 2.2.2 version. However, now I had two versions installed, 2.1.2 and 2.2.2 which still caused an import error. I followed instructions here and did

sudo ghc-pkg unregister --force mtl-2.1.2

to remove the old version. But now I get an error:

Could not find module `Control.Monad.State'
It is a member of the hidden package `monads-tf-0.1.0.2'.
Use -v to see a list of the files searched for.

ghc-pkg check outputs

There are problems in package HTTP-4000.2.17:
  dependency "mtl-2.1.2-735d9c92b4f214d454fb5168bb1eb6ee" doesn't exist
There are problems in package fgl-5.5.0.1:
  dependency "mtl-2.1.2-735d9c92b4f214d454fb5168bb1eb6ee" doesn't exist
There are problems in package cgi-3001.1.8.5:
  dependency "mtl-2.1.2-735d9c92b4f214d454fb5168bb1eb6ee" doesn't exist
There are problems in package parsec-3.1.3:
  dependency "mtl-2.1.2-735d9c92b4f214d454fb5168bb1eb6ee" doesn't exist
There are problems in package regex-base-0.93.2:
  dependency "mtl-2.1.2-735d9c92b4f214d454fb5168bb1eb6ee" doesn't exist

The following packages are broken, either because they have a problem
listed above, or because they depend on a broken package.
HTTP-4000.2.17
fgl-5.5.0.1
cgi-3001.1.8.5
parsec-3.1.3
regex-base-0.93.2
network-2.4.1.2
regex-compat-0.95.1
regex-posix-0.95.2

What should I do now?

Dunno
  • 3,632
  • 3
  • 28
  • 43
  • 1
    Is that the output of `ghc-pkg check` or `sudo ghc-pkg check`? (Is it talking about the global package database, or root's user-specific package database?) In the future, for day-to-day work, neither cabal nor ghc-pkg should need to be run with sudo powers; they're both capable of mucking about with a local package database that is user-specific, and this is generally safer (easier to nuke and restart fresh if something unrecoverable breaks). – Daniel Wagner May 14 '18 at 04:01
  • @DanielWagner this comment actually led me to the solution - I shouldn't have used sudo, I did it out of habit (like with `pip` or `apt`). So the problem was that I installed mtl 2.2.2 for root and uninstalled 2.1.2 for local user. After doing `cabal install mtl-2.2.2` (no sudo) it works. – Dunno May 14 '18 at 16:00

1 Answers1

2

You need to reinstall all the packages that depend on mtl to get them up to date with the new version. Cabal-install should be able to do that automatically if, in your project folder with the yourproject.cabal file, you do

$ cabal install --dependencies-only

As Daniel remarks, it may also be necessary to add --reinstall, namely if Cabal-install hasn't properly caught on to the dependency changes and needs to be manually ticked onto rebuilding them. If it thinks the reinstalls themselves might break yet other packages, --force-reinstalls may be needed too.

An alternative that avoids dependency hell is using the new Nix-style commands, which never break anything when reinstalling.

leftaroundabout
  • 117,950
  • 5
  • 174
  • 319