#7171: erroneous overlapping instances reported with FunDeps
---------------------------------------+------------------------------------
 Reporter:  jwlato                     |          Owner:                        
 
     Type:  bug                        |         Status:  new                   
 
 Priority:  normal                     |      Component:  Compiler (Type 
checker)
  Version:  7.6.1-rc1                  |       Keywords:  type classes, fundeps 
 
       Os:  Unknown/Multiple           |   Architecture:  Unknown/Multiple      
 
  Failure:  GHC rejects valid program  |       Testcase:                        
 
Blockedby:                             |       Blocking:                        
 
  Related:                             |  
---------------------------------------+------------------------------------
 When a superclass constraint has functional dependencies, in certain cases
 GHC-7.6 erroneously reports that duplicate instances are found.

 file Foo.hs
 {{{
 {-# LANGUAGE FunctionalDependencies #-}
 {-# LANGUAGE FlexibleInstances #-}

 module Foo where

 import Data.ByteString as B
 import Data.Word

 class Foo a b | a -> b

 class (Foo a b) => Bar a b | a -> b

 instance Foo [a] a
 instance Bar [a] a
 instance Foo ByteString Word8
 instance Bar ByteString Word8

 test :: Bar full item => full -> full
 test inp = inp

 -- this works
 -- _test_x :: ByteString -> ByteString
 -- _test_x = test


 }}}

 file Main.hs
 {{{
 module Main where

 import Foo
 import Data.ByteString

 -- this works
 -- test1 :: [Int] -> [Int]
 -- test1 = test

 -- this fails
 test2 :: ByteString -> ByteString
 test2 = test

 }}}

 ghc reports

 {{{
 Main.hs:12:9:
     Overlapping instances for Foo ByteString GHC.Word.Word8
       arising from a use of `test'
     Matching instances:
       instance Foo ByteString GHC.Word.Word8 -- Defined at Foo.hs:20:10
     There exists a (perhaps superclass) match:
     (The choice depends on the instantiation of `'
      To pick the first instance above, use -XIncoherentInstances
      when compiling the other instance declarations)
     In the expression: test
     In an equation for `test2': test2 = test
 }}}

 For this to manifest, I think that at least the following must be true:
   - a function with class constraints must be called from a separate
 module
   - the type class instance must be monomorphic in the fundep-to parameter

 This example works in ghc-7.4.2.

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

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to