21

While evaluating the line "import Control.Monad.State" in a Haskell module, GHC gives me the following error:

Could not find module `Control.Monad.State':
  it was found in multiple packages: monads-fd-0.0.0.1 mtl-1.1.0.2
Failed, modules loaded: none.

How do I resolve this conflict?

Don Stewart
  • 137,316
  • 36
  • 365
  • 468
Bill
  • 44,502
  • 24
  • 122
  • 213

2 Answers2

35

You have several options. Either:

  • ghc-pkg hide monads-fd. This will cause GHC and GHCi to ignore the presence of the monads-fd by default until you later ghc-pkg expose monads-fd, but software installed by Cabal will still be able to build against it.
  • Use the {-# LANGUAGE PackageImports #-} pragma, and change your import statement to import "mtl" Control.Monad.State.
  • Use Cabal to build your project, and specify mtl in the Build-depends line.

The first is best for casual hacking, and the last is best for production builds.

These all assume you want the mtl module and not the monads-fd module; otherwise swap them.

Tom Crockett
  • 30,818
  • 8
  • 72
  • 90
Reid Barton
  • 14,951
  • 3
  • 39
  • 49
1

Both packages implement Control.Monad.State and GHC does not know which implementation it should prefer, so you need to hide one of the packages from GHC. Seems like the -ignore-package <name> GHC flag might help you here.

liwp
  • 6,746
  • 1
  • 27
  • 39