GHC says there are unsafe overlapping instances, but only one instance applies
The following code rightfully does not compile:
import Text.Printf
f :: a -> b
f = undefined
g i = f $ printf "" i
However, the error message is a very surprising one:
test.hs:6:1:
Unsafe overlapping instances for PrintfType (t -> a0)
arising from the ambiguity check for `g'
The matching instance is:
instance [safe] (PrintfArg a, PrintfType r) => PrintfType (a -> r)
-- Defined in `Text.Printf'
It is compiled in a Safe module and as such can only
overlap instances from the same module, however it
overlaps the following instances from different modules:
When checking that `g'
has the inferred type `forall a b t. PrintfType (t -> a) => t -> b'
Probable cause: the inferred type is ambiguous
What I find surprising is the claim that there are overlapping instances, followed by a list of instances that clearly does not have any overlaps. For comparison, changing the definition of g to be
g = f . printf ""
gives a much more reasonable error:
test.hs:6:9:
No instance for (PrintfArg a0) arising from a use of `printf'
The type variable `a0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there are several potential instances:
instance [safe] PrintfArg Char -- Defined in `Text.Printf'
instance [safe] PrintfArg Double -- Defined in `Text.Printf'
instance [safe] PrintfArg Float -- Defined in `Text.Printf'
...plus 12 others
In the second argument of `(.)', namely `printf ""'
In the expression: f . printf ""
In an equation for `g': g = f . printf ""
Trac metadata
Trac field | Value |
---|---|
Version | 7.6.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |