[GHC] #7857: GHC says there are unsafe overlapping instances, but only one instance applies

GHC cvs-ghc at haskell.org
Mon Apr 22 22:38:19 CEST 2013


#7857: GHC says there are unsafe overlapping instances, but only one instance
applies
-----------------------------+----------------------------------------------
Reporter:  dmwit             |          Owner:                  
    Type:  bug               |         Status:  new             
Priority:  normal            |      Component:  Compiler        
 Version:  7.6.1             |       Keywords:                  
      Os:  Unknown/Multiple  |   Architecture:  Unknown/Multiple
 Failure:  None/Unknown      |      Blockedby:                  
Blocking:                    |        Related:                  
-----------------------------+----------------------------------------------
 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 ""
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7857>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler



More information about the ghc-tickets mailing list