change to deriving in 6.7 ??
Conal Elliott
conal at conal.net
Wed Sep 5 14:59:28 EDT 2007
I'm delighted!! I've been meaning to beg even more abjectly, as I've
realized that the burden is significant for lots of methods or tricky ones.
In some cases, where possible, I'd omit the newtype and leave my users to
scary representations in their error messages.
Thank you Simon!
- Conal
On 9/5/07, Simon Peyton-Jones <simonpj at microsoft.com> wrote:
>
> I have heard your cry. GHC 6.8 will accept this after all. I have also
> documented the rules
>
>
>
> Simon
>
>
>
> *From:* conal.elliott at gmail.com [mailto:conal.elliott at gmail.com] *On
> Behalf Of *Conal Elliott
> *Sent:* 21 August 2007 21:43
> *To:* Simon Peyton-Jones
> *Cc:* cvs-ghc at haskell.org
> *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* <simonpj at microsoft.com> 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:* cvs-ghc-bounces at haskell.org [mailto: cvs-ghc-bounces at haskell.org]
> *On Behalf Of *Conal Elliott
> *Sent:* 15 August 2007 23:37
> *To:* cvs-ghc at haskell.org
> *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
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/cvs-ghc/attachments/20070905/506cb707/attachment-0001.htm
More information about the Cvs-ghc
mailing list