Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't build cabal package due to ambiguous Prelude

I've been trying to install BNF converter from cabal, however there is a problem building it. Apparently, this package uses a mix of modules from haskell98 and version 4.* of base. This presents a problem in that if you compile with haskell98 hidden then some modules are not found. However, if you compile with haskell98 exposed then ghc cannot tell if it's supposed to use the new Prelude or the haskell98 Prelude!

The error message:

Main.hs:1:1:
    Ambiguous module name `Prelude':
    it was found in multiple packages: base haskell98-2.0.0.1 

How do you resolve errors like this?

like image 374
keiter Avatar asked Feb 22 '23 00:02

keiter


2 Answers

Pester the maintainers to upload a fix. Or, if they are unresponsive, consider taking over maintenance yourself.

This is because haskell98 is a compatibility package that duplicates functions in other modules. New code shouldn't depend on it, unless it's meant to be Haskell-98 compatible. However this change is relatively recent, and a lot of older code references both "base" and "haskell98" although it doesn't actually use the "haskell98" package.

In the immediate term, I would run cabal unpack BNFC, then edit the ".cabal" file and remove the reference to haskell98 from the "build-depends:" field. I would also bump the version number for a library (this step doesn't matter for executables). Then build and install from the local copy you just edited. There may be other issues if BNFC was meant to use mtl version 1, but you can add that constraint yourself if necessary.

like image 50
John L Avatar answered Mar 03 '23 03:03

John L


A workaround would be using the language extensions NoImplicitPrelude and PackageImports. The former prevents Haskell from importing one of the Preludes, which would fail. The second extension allows to specify the package and the version from which to import a module:

import "base" Prelude

or

import "haskell98" Prelude

like image 32
MauganRa Avatar answered Mar 03 '23 03:03

MauganRa