更新 mtl 后找不到模块"Control.Monad.State"



我想使用Control.Monad.Except模块,但事实证明我有一个过时的 mtl 包(它导致了导入错误 - 我有一个过时的模块Control.Monad.Error(。所以我做到了

sudo cabal install mtl

它安装了 2.2.2 版本。但是,现在我安装了两个版本,2.1.2 和 2.2.2,这仍然导致导入错误。我按照这里的说明做了

sudo ghc-pkg unregister --force mtl-2.1.2

以删除旧版本。但是现在我得到一个错误:

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输出

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

我现在应该怎么做?

您需要重新安装所有依赖于mtl的软件包,以使它们与新版本保持同步。Cabal-install应该能够自动执行此操作,如果在包含yourproject.cabal文件的项目文件夹中,您这样做

$ 阴谋集团安装

--仅依赖关系正如丹尼尔所说,可能还需要添加--reinstall,即如果 Cabal-install 没有正确捕捉到依赖关系的变化,需要手动勾选重建它们。如果它认为重新安装本身可能会破坏其他软件包,则可能还需要--force-reinstalls

避免依赖地狱的另一种方法是使用新的 Nix 样式命令,这些命令在重新安装时永远不会破坏任何内容。

最新更新