Search code examples
haskellghcihaskell-stack

Haskell stack, how to revert ambiguous module names found in multiple packages globally


While trying to debug a different question, I installed a package that seems to conflict with some of my other installed packages.

I ran

$ stack install regex-pcre-text
regex-pcre-builtin-0.94.4.8.8.35: configure
regex-tdfa-1.2.3.1: download
regex-pcre-builtin-0.94.4.8.8.35: build
regex-tdfa-1.2.3.1: configure
regex-tdfa-1.2.3.1: build
regex-pcre-builtin-0.94.4.8.8.35: copy/register
regex-tdfa-1.2.3.1: copy/register
regex-tdfa-text-1.0.0.3: download    
regex-tdfa-text-1.0.0.3: configure   
regex-tdfa-text-1.0.0.3: build       
regex-tdfa-text-1.0.0.3: copy/register
regex-pcre-text-0.94.0.1: download    
regex-pcre-text-0.94.0.1: configure   
regex-pcre-text-0.94.0.1: build       
regex-pcre-text-0.94.0.1: copy/register
Completed 4 action(s).                

I can no longer simply import

Text.Regex.PCRE

When I try, I now see:

$ stack ghci
Prelude> :set -XOverloadedStrings
Prelude> import Text.Regex.PCRE

Yields

<no location info>: error:
    Ambiguous module name ‘Text.Regex.PCRE’:
      it was found in multiple packages:
      regex-pcre-0.94.4 regex-pcre-builtin-0.94.4.8.8.35

I would like to revert my installation to the earlier state such that code on my machine that imports Text.Regex.PCRE without qualification continues to work as it used to.

However, it looks like stack does not have a clear uninstall:

$ stack uninstall regex-pcre-text

Error: stack does not manage installations in global locations. The only global mutation stack performs is executable copying. For the default executable destination, please run stack path --local-bin

I hesitate to simply run this stack path --local-bin because I don't know what it's going to do, or whether it can be reversed (which was my error in installing the above package in the first place). What is the right fix for my import problem?

Update 1

I tried suggestions here:

$ ghc-pkg unregister regex-pcre-text
ghc-pkg: cannot find package regex-pcre-text

$ stack exec ghc-pkg unregister regex-pcre-text
ignoring (possibly broken) abi-depends field for packages

Solution

  • The issue is that regexp-pcre-text installed its dependency regex-pcre-builtin which caused the conflict. You want to run both of the following commands in the global project (i.e., outside of any specific project directory):

    $ stack exec ghc-pkg unregister regex-pcre-text
    $ stack exec ghc-pkg unregister regex-pcre-builtin
    

    You already ran the first, and I suspect it completed successfully, despite the warning message about the abi-depends fields, so you just need to run the second.

    (These could be combined into a single command:

    $ stack exec ghc-pkg unregister regex-pcre-text regex-pcre-builtin
    

    but given you already removed the first package, I believe this would fail with a message that regex-pcre-text wasn't found.)

    The solution mentioned by @DarthFennec is to use the PackageImports extension to resolve the conflict. From GHCi, it would look like this, to use the module from the regex-pcre package even with both packages installed:

    Prelude> :set -XPackageImports
    Prelude> import "regex-pcre" Text.Regex.PCRE
    Prelude Text.Regex.PCRE>