Could not find module `Control.Monad.State` after updating mtl

流过昼夜 提交于 2021-01-27 20:18:11

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/50321045/could-not-find-module-control-monad-state-after-updating-mtl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!