On Wed, Aug 15, 2007 at 03:36:49PM -0700, Conal Elliott wrote:
> I'm running ghc-6.7.20070802 and getting a new error message that didn't
> show up with ghc-6.6. Code:
>
> -- | Pairing for unary type constructors.
> newtype Pair1 f g a = Pair1 {unPair1 :: (f a, g a)}
> deriving (Eq, Ord, Show)
>
> Error message:
>
> src/Data/Tupler.hs:26:0:
> No instances for (Show (g a), Show (f a))
> arising from the 'deriving' clause of a data type declaration
> at src/Data/Tupler.hs:(26,0)-(27,25)
> Possible fix:
> add an instance declaration for (Show (g a), Show (f a))
> When deriving the instance for (Show (Pair1 f g a))
>
> Has there been a change to "deriving"?
Simon PJ added a note to test drv015 (which has the same code as above):
-- July 07: I'm changing this from "should_compile" to "should_fail".
-- It would generate an instance decl like
-- insance (Show (f a), Show (g a)) => Show (Pair1 f g a)
-- and that is not Haskell 98.
--
-- See Note [Exotic derived instance contexts] in TcSimplify.
-- The rule is simple: the context of a derived instance decl must
-- contain constraints of form (C tyvar) only, just as H98.
The first half doesn't entirely make sense to me as 6.6 only accepted it
when -fglasgow-exts was on.
Here's the note he mentions:
------------------- BEGIN -------------------
Note [Exotic derived instance contexts]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider
data T a b c = MkT (Foo a b c) deriving( Eq )
instance (C Int a, Eq b, Eq c) => Eq (Foo a b c)
Notice that this instance (just) satisfies the Paterson termination
conditions. Then we *could* derive an instance decl like this:
instance (C Int a, Eq b, Eq c) => Eq (T a b c)
even though there is no instance for (C Int a), because there just
*might* be an instance for, say, (C Int Bool) at a site where we
need the equality instance for T's.
However, this seems pretty exotic, and it's quite tricky to allow
this, and yet give sensible error messages in the (much more common)
case where we really want that instance decl for C.
So for now we simply require that the derived instance context
should have only type-variable constraints.
Here is another example:
data Fix f = In (f (Fix f)) deriving( Eq )
Here, if we are prepared to allow -fallow-undecidable-instances we
could derive the instance
instance Eq (f (Fix f)) => Eq (Fix f)
but this is so delicate that I don't think it should happen inside
'deriving'. If you want this, write it yourself!
NB: if you want to lift this condition, make sure you still meet the
termination conditions! If not, the deriving mechanism generates
larger and larger constraints. Example:
data Succ a = S a
data Seq a = Cons a (Seq (Succ a)) | Nil deriving Show
Note the lack of a Show instance for Succ. First we'll generate
instance (Show (Succ a), Show a) => Show (Seq a)
and then
instance (Show (Succ (Succ a)), Show (Succ a), Show a) => Show (Seq a)
and so on. Instead we want to complain of no instance for (Show (Succ a)).
------------------- END -------------------
Thanks
Ian
_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc