Overlapping instances error with single instance
{-# LANGUAGE MultiParamTypeClasses, FlexibleContexts, FlexibleInstances #-}
module Bug where
class C a b
instance C a Int
x :: ()
x = undefined :: C a Int => ()
ghc -c Bug.hs
Bug.hs:10:18: error:
• Overlapping instances for C a0 Int
Matching givens (or their superclasses):
C a Int
bound by an expression type signature:
forall a. C a Int => ()
at Bug.hs:10:18-30
Matching instances: instance C a Int -- Defined at Bug.hs:7:10
(The choice depends on the instantiation of ‘a0’)
• In the ambiguity check for an expression type signature
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
In an expression type signature: C a Int => ()
In the expression: undefined :: C a Int => ()
|
10 | x = undefined :: C a Int => ()
| ^^^^^^^^^^^^^
The "matching instances" bit of the error messages only lists a single instance. Doesn't it take at least two instances for something to overlap?
Also, following the algorithm laid out in the user guide (section "Overlapping Instances"), it appears this program should be accepted.
Trac metadata
Trac field | Value |
---|---|
Version | 8.6.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |