Apparently inconsistent behaviour in the presence of OverlappingInstances
This report is inspired by http://stackoverflow.com/questions/27051640/strange-behavior-when-adding-constraint-to-instance
I'm not sure if it is a bug, but it certainly feels strange and inconsistent to me, so I'd like to get some clarification.
Here's a self-contained example of the behaviour:
{-# LANGUAGE FlexibleInstances, OverlappingInstances #-}
module Overlap where
class C a where
foo :: a -> a
instance C a where
foo = id
instance C Int where
foo = (+1)
-- Note that this one does not mention class C anywhere:
class D a where
bar :: a -> a
instance D a where
bar = foo -- this works and picks the 'C a' instance always
-- The following does not compile without IncoherentInstances:
{-
baz :: a -> a
baz = foo
-}
I'm surprised that the definitions of bar
and baz
are treated differently. Shouldn't they either both require IncoherentInstances
, or both work?
Trac metadata
Trac field | Value |
---|---|
Version | 7.8.3 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |