I use a package from Hackage (network-uri) which includes a non-standard instance for Show which I need to override (to work with the corresponding Read instance). I understand that the overlapping pragma is specifically created for this case where an instance in a package needs to be excluded.

I have the code

deriving instance {-# Overlapping #-} Show N.URI 

and I get the error message:

 Duplicate instance declarations:
  instance [overlapping] Show N.URI
    -- Defined at Uniform/HttpURI.hs:54:1
  instance [safe] Show N.URI -- Defined in ‘Network.URI’   |
  54 | deriving instance {-# Overlapping #-} Show N.URI 

What additional coding is necessary to achieve the intended overriding of the instance in the package? Is there a problem with safe? I have added

{-# LANGUAGE Unsafe #-} 

but the error remains. Adding

{-# LANGUAGE IncoherentInstances      #-}   

has no effect either. What is missing?

PS. I understand that the package author had perhaps some reason to provide this instance for Show, but the user of a package should be able to override it.

0 Answers