[Haskell-beginners] Overlapping Instances

John Smith voldermort at hotmail.com
Sun Oct 24 09:54:19 EDT 2010


Following is a simplification of some code which I have written. I have an overlapping Show instance for A, which is 
more specific than the general instance for arrays, so I would expect it to be acceptable as an overlapping instance. 
Nevertheless, I get the following compiler error:

     Overlapping instances for Show A
       arising from a use of `show' at 13:17-22
     Matching instances:
       instance (Ix a, Show a, Show b) => Show (Array a b)
         -- Defined in GHC.Arr
       instance [overlap ok] Show A -- Defined at 9:9-14
     In the expression: show a
     In the definition of `show': show (B a) = show a
     In the instance declaration for `Show B'
Compilation failed.

I've tried UndecidableInstances and IncoherentInstances, but they don't seem to help. What am I doing wrong?

Many thanks in advance for any assistance.

-John

{-# LANGUAGE TypeSynonymInstances, OverlappingInstances #-}

import Data.Array

type A = Array Int Bool

data B = B A

instance Show A where
     show a = "foo"

instance Show B where
     show (B a) = show a



More information about the Beginners mailing list