Overlapping instances for poly-kinded data

Gabor Greif ggreif at gmail.com
Sun Apr 12 14:33:46 UTC 2015


Hi all,

I observe a strange "deriving Show" behaviour for my data type Foo
that has proxies:

data Foo :: k -> * where
  Foo :: Proxy t -> Foo t

deriving instance Show (Foo t)

This works as expected. But now I add

instance {-# OVERLAPPING #-} KnownSymbol s => Show (Proxy (s :: Symbol)) where
  show = ('#' :) . symbolVal
instance {-# OVERLAPPING #-} KnownNat n => Show (Proxy (n :: Nat)) where
  show = ('#' :) . show . natVal

these orphan instances, and "deriving Show" won't pick them up. When I
go and specialise
deriving instance {-# OVERLAPPING #-} KnownNat t => Show (Foo (t :: Nat))
deriving instance {-# OVERLAPPING #-} KnownSymbol s => Show (Foo (s :: Symbol))

then it seems to work allright. Is polykinded derivation so different
from the monokinded one? Or is this simply a bug?

(a more elaborate WIP example can be found here:
https://code.google.com/p/omega/source/browse/mosaic/CloudAtlas.hs?spec=svn2465&r=2465)

Cheers,

    Gabor


More information about the ghc-devs mailing list