Possible instances problem with ghc-6.2.1
Simon Peyton-Jones
simonpj at microsoft.com
Wed Mar 31 08:27:26 EST 2004
George
This "bug" is the same as the one I described in the enclosed message,
but it's a bit simpler this time.
The basic setup is:
newFormEntry :: HasButton value => Radio value -> Int
instance Show value => HasButton value
foogle :: (HasButton woggle) => Radio woggle -> Int
foogle lab = let
form0 = newFormEntry lab
in
undefined
The call to newFormEntry requires the constraint (HasButton woggle).
You point out that (HasButton woggle) is available in foogle's type. But
it's *also* available via
instance Show value => HasButton value
So it depends on which of two (incompatible!) ways of deriving
(HasButton woggle) wins. GHC makes no guarantees about this.
In fact, a recent change (don't ask) makes GHC just a bit keener to do
context simplification at monomorphic local definitions (like that for
form0). So GHC tries to simplify the (HasButton woggle) constraint at
the "form0 = ..." point, and succeeds by using the instance declaration.
In short, you'd defined a non-confluent rewrite system, so you should
not be surprised if it unpredictably paints you into a corner, and does
so differently on different days of the week.
Simon
| -----Original Message-----
| From: glasgow-haskell-bugs-bounces at haskell.org
[mailto:glasgow-haskell-bugs-
| bounces at haskell.org] On Behalf Of George Russell
| Sent: 26 March 2004 10:21
| To: glasgow-haskell-bugs at haskell.org
| Subject: Possible instances problem with ghc-6.2.1
|
| With ghc-6.2.1 compiled from source
|
| tar -xzf instances2.tar.gz
| cd instances2
| gmake
|
| produces the message:
|
| AttributesType.hs:15:
| Could not deduce (Show value)
| from the context (AttributeValue (Radio value),
| HasConfigRadioButton value,
| Bounded value,
| Enum value,
| FormLabel label)
| arising from use of `newFormEntry' at AttributesType.hs:15
|
|
|
| However:
| (1) this does not seem to happen with ghc-6.2.
| (2) why does newFormEntry need Show anyway? It would only be
| relevant in deducing HasConfigRadioButton, but in fact
| it has that in the context anyway.
|
|
| Sorry I didn't report this earlier.
-------------- next part --------------
An embedded message was scrubbed...
From: "Simon Peyton-Jones" <simonpj at microsoft.com>
Subject: RE: Problem deriving instances
Date: Thu, 18 Mar 2004 18:09:17 +0100
Size: 5244
Url: http://www.haskell.org/pipermail/glasgow-haskell-bugs/attachments/20040331/04081e78/attachment.eml
More information about the Glasgow-haskell-bugs
mailing list