Could not find module `Control.Monad.Reader'

我是研究僧i 提交于 2020-01-03 15:33:10

问题


Today when I tried to compile my code in Geany I got this error

Could not find module `Control.Monad.Reader':
  it was found in multiple packages: monads-fd-0.1.0.1 mtl-1.1.0.2
Compilation failed.

I get the same for the Writer monad; I thought I should remove one of those packages, but I do not want to break other packages, so now what should I do, yesterday everything worked without any problem.


回答1:


It looks like you have recently installed monads-fd, perhaps as a dependency of something else you installed. Both monads-fd and mtl packages contain the module Control.Monad.Reader, so GHC doesn't know which one to use when you compile some code that imports it. You need to resolve the ambiguity somehow:

  • If you are using GHC or GHCi directly
    • either use a -hide-package <package> flag on the command line to hide one of the packages, or
    • hide the package by default using ghc-pkg hide <package>. You may need to use ghc-pkg --user hide <package> if the package was installed in your home directory (the default on some platforms).
  • You can use Cabal, and say exactly which one of the conflicting packages you depend on using the build-depends field in your .cabal file



回答2:


I encountered a similar problem recently, and it was suggested that I run ghc-pkg hide {x} where '{x}' is the name of one of those packages. It worked in my situation.



来源:https://stackoverflow.com/questions/3476088/could-not-find-module-control-monad-reader

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