higher-kind deriving ... or not

C T McBride C.T.McBride@durham.ac.uk
Tue, 26 Feb 2002 19:23:02 +0000 (GMT)


Hi

I'm rather fond of fixpoint constructions like this one:

> newtype Copy a = Copy a deriving Show

> data Wonky f
>   = Wonky
>   | Manky (f (Wonky f))
>   deriving Show

(Clearly this is an ill-motivated example, but the real example which
caused this problem is available on request...) 

The trouble is that when I ask either hugs -98 or ghci -fglasgow-exts
to

  show (Wonky :: Wonky Copy)

the poor compiler's brain explodes.

I take it this is a known problem with instance inference, deriving, etc.
Of course, it's easy to write my own show for Wonky Copy, but that's
a tad annoying.

I tried to guess the type of the show instance derived for
Wonky. Being a naive sort of chap, I thought it might be

  show :: (forall a. Show a => Show (f a)) => Wonky f -> String

but that's a syntax error.

A little more tinkering, and it looks like it might be

  show :: Show (f (Wonky f)) => Wonky f -> String

Is this really the type of show? If so, no wonder there's a problem.

I don't want to start an argument about how to solve this problem.  I
do want to suggest that, for the time being, it would be better to
reject `deriving Show' for type constructors like Wonky (ie those with
higher-kind parameters) than to generate instances which break the
compiler.

Or am I just being a spoilsport?

Conor