Search code examples
haskellcabalcabal-installhunit

Random Word8 duplicate instance declaration during cabal testpack installation


What does the following error message mean when cabal install testpack-2.1.1 has failed:

... Everything above this succeeded with no problems.
[22 of 22] Compiling Control.Monad.Cont ( Control/Monad/Cont.hs, dist/build/Control/Monad/Cont.o )
Registering mtl-2.2.1...
Installing library in /home/ely/.cabal/lib/mtl-2.2.1/ghc-7.4.2
Registering mtl-2.2.1...
Downloading testpack-2.1.1...
Configuring testpack-2.1.1...
Building testpack-2.1.1...
Preprocessing library testpack-2.1.1...
[1 of 3] Compiling Test.QuickCheck.Instances ( src/Test/QuickCheck/Instances.hs, dist/build/Test/QuickCheck/Instances.o )

src/Test/QuickCheck/Instances.hs:50:10:
    Duplicate instance declarations:
      instance Random Word8
        -- Defined at src/Test/QuickCheck/Instances.hs:50:10
      instance Random Word8 -- Defined in `System.Random'
cabal: Error: some packages failed to install:
testpack-2.1.1 failed during the building phase. The exception was:
ExitFailure 1

I've tried Googling, but cannot make sense of this install error.


Solution

  • testpack-2.1.1 provides a so called orphan instance for Random Word8, that is, an instance where it doesn't define either the class or the type itself.

    One of the several problems with orphan instances is that one of the packages which do define the class or type might choose to add that instance themselves in a later version, which is precisely what the random package has done in this case, and so the instances conflict.

    From testpack version 2.1.2 there is a check that makes sure to only define the instance if the random package is too old to have done so itself. So you should be able to fix this by installing a later version of testpack instead.