
#10532: Unnecessary constraints when using overlapping instances -------------------------------------+------------------------------------- Reporter: MikeIzbicki | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 7.10.1 checker) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Description changed by MikeIzbicki: Old description:
The following code compiles just fine:
{{{ class Foo a where foo :: a -> Int instance Foo a where foo _ = 5
f :: a -> Int f = foo }}}
But if we modify the code to use overlapping instances like so:
{{{ class Foo a where foo :: a -> Int instance {-# OVERLAPS #-} Foo Int where foo = id instance {-# OVERLAPPABLE #-} Foo a where foo _ = 5
f:: a -> Int f = foo }}}
We get the following compiler message: {{{ Overlapping instances for Foo a arising from a use of ‘foo’ Matching instances: instance [overlappable] Foo a -- Defined at ... instance [overlap ok] Foo Int -- Defined at ... (The choice depends on the instantiation of ‘a’ To pick the first instance above, use IncoherentInstances when compiling the other instance declarations) }}}
Including the constraint in the type signature makes the problem go away, but the constraint shouldn't be needed. In most use cases this wouldn't be a big deal, but it's making my type signatures much messier looking than they actually are.
Adding IncoherentInstances as the error message suggests gives the instance I don't want. Weirdly, I get different instances depending on whether the constraint is in the type signature or not.
New description: The following code compiles just fine: {{{ class Foo a where foo :: a -> Int instance Foo a where foo _ = 5 f :: a -> Int f = foo }}} But if we modify the code to use overlapping instances like so: {{{ class Foo a where foo :: a -> Int instance {-# OVERLAPS #-} Foo Int where foo = id instance {-# OVERLAPPABLE #-} Foo a where foo _ = 5 f:: a -> Int f = foo }}} We get the following error message: {{{ Overlapping instances for Foo a arising from a use of ‘foo’ Matching instances: instance [overlappable] Foo a -- Defined at ... instance [overlap ok] Foo Int -- Defined at ... (The choice depends on the instantiation of ‘a’ To pick the first instance above, use IncoherentInstances when compiling the other instance declarations) }}} Including the constraint in the type signature makes the problem go away, but the constraint shouldn't be needed. In most use cases this wouldn't be a big deal, but it's making my type signatures much messier looking than they actually are. Adding IncoherentInstances as the error message suggests gives the instance I don't want. Weirdly, I get different instances depending on whether the constraint is in the type signature or not. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10532#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler