[ ghc-Bugs-1277810 ] ghc is confused about instances of Ord
SourceForge.net
noreply at sourceforge.net
Wed Aug 31 20:23:56 EDT 2005
Bugs item #1277810, was opened at 2005-08-31 23:39
Message generated for change (Comment added) made by greenrd
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=108032&aid=1277810&group_id=8032
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Compiler (Type checker)
Group: 6.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Robin Green (greenrd)
Assigned to: Nobody/Anonymous (nobody)
Summary: ghc is confused about instances of Ord
Initial Comment:
When I compile the attached file _without_ -fallow-incoherent-instances
on ghc 6.4 on Fedora Core Linux, I receive the following errors:
PartialOrder.hs:19:0:
Overlapping instances for PartialOrder a
arising from the superclasses of an instance declaration at
PartialOrder.hs:19:0
Matching instances:
PartialOrder.hs:11:0: instance (Ord a) => PartialOrder a
PartialOrder.hs:19:0: instance PartialOrder (LineList a)
(The choice depends on the instantiation of `a'
Use -fallow-incoherent-instances to use the first choice above)
In the instance declaration for `PartialOrder (LineList a)'
PartialOrder.hs:20:53:
Overlapping instances for PartialOrder a
arising from use of `lte' at PartialOrder.hs:20:53-55
Matching instances:
PartialOrder.hs:11:0: instance (Ord a) => PartialOrder a
PartialOrder.hs:19:0: instance PartialOrder (LineList a)
(The choice depends on the instantiation of `a'
Use -fallow-incoherent-instances to use the first choice above)
In the first argument of `zipWith', namely `lte'
In the first argument of `and', namely `(zipWith lte c d)'
In the definition of `lte':
lte (LineList c) (LineList d) = and (zipWith lte c d)
However, when I compile it _with_ -fallow-incoherent-instances, I
receive _these_ errors:
PartialOrder.hs:19:0:
No instance for (Ord a)
arising from the superclasses of an instance declaration at
PartialOrder.hs:19:0
Probable fix: add (Ord a) to the instance declaration superclass
context
In the instance declaration for `PartialOrder (LineList a)'
PartialOrder.hs:20:53:
Could not deduce (Ord a)
from the context (PartialOrder (LineList a), Eq (LineList a))
arising from use of `lte' at PartialOrder.hs:20:53-55
Probable fix: add (Ord a) to the class or instance method `lte'
In the first argument of `zipWith', namely `lte'
In the first argument of `and', namely `(zipWith lte c d)'
In the definition of `lte':
lte (LineList c) (LineList d) = and (zipWith lte c d)
So in the _first_ compilation run, ghc is suggesting that an instance of
Ord a (which I believe is a figment of its imagination) collides; but in the
_second_ compilation run, it complains that it can't _find_ the instance for
Ord a. Surely an inconsistency.
----------------------------------------------------------------------
>Comment By: Robin Green (greenrd)
Date: 2005-09-01 00:23
Message:
Logged In: YES
user_id=2202
The general problem here seems to be that ghc is not being very smart about
making trivial instance deductions that may be very obvious to the
programmer. Here is another example:
mkLineBunch :: (Ord a) => [[a]] -> LineBunch a
mkLineBunch = (uncurry LineBunch) . ((uncurry withBoth) ((map `ofBoth`
minimum) maximum)) . transpose
ghc complains here about instance collisions. But if the _logically_ equivalent
type signature is substituted:
mkLineBunch :: (Ord a, PartialOrder a) => [[a]] -> LineBunch a
the file suddenly compiles successfully! So the first error message was bogus,
and apparently arose from the compiler being unable to deduce that Ord a
implies PartialOrder a, even though it had been _told_ that Ord a =>
PartialOrder a above.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=108032&aid=1277810&group_id=8032
More information about the Glasgow-haskell-bugs
mailing list