I have heard your cry.  GHC 6.8 will accept this after all.  I have also 
documented the rules

Simon

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Conal Elliott
Sent: 21 August 2007 21:43
To: Simon Peyton-Jones
Cc: [email protected]
Subject: Re: change to deriving in 6.7 ??

Thanks, Simon.  The manual deriving is easier than I expected, by boilerplate 
delegation of constraints & methods, as below.  You may want to give such an 
example when you document the change.   Cheers,  - Conal

-- | Pairing of type constructors
newtype (f :*: g) a = Prod { unProd :: (f a, g a) }
  -- deriving (Show, Eq, Ord)

-- Deriving no longer works on types like :*:.  So:
instance (Show (f a, g a)) => Show ((f :*: g) a) where
  show (Prod p) = "Prod " ++ show p
instance (Eq (f a, g a)) => Eq ((f :*: g) a) where
  Prod p == Prod q = p == q
instance (Ord (f a, g a)) => Ord ((f :*: g) a) where
  Prod p < Prod q = p < q

On 8/20/07, Simon Peyton-Jones <[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>> 
wrote:

Yes, this is a change.  To guarantee that we generate terminating instance 
declarations, GHC now insists that it can reduce the context of a derived 
instance to

instance (C a, D b) => ...

That is, the context of the instance decl must consist of (class applied to 
type variables).  Without this constraint it's all too easy to generate 
non-terminating instances.



So the deriving mechanism works in straightforward cases, and for more 
complicated cases you have to write the instances yourself.



It's not impossible that the deriving mechanism could be made a little more 
liberal, but it errs on the conservative side at the moment.  There's no 
workaround - -you just have to write the instance yourself.



I should document this



Simon



From: [EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]> [mailto: [EMAIL 
PROTECTED]<mailto:[EMAIL PROTECTED]>] On Behalf Of Conal Elliott
Sent: 15 August 2007 23:37
To: [email protected]<mailto:[email protected]>
Subject: change to deriving in 6.7 ??



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"?  Is there a workaround?

Thanks,  - Conal

_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc

Reply via email to