Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
    • Help
    • Support
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project
    • Project
    • Details
    • Activity
    • Releases
    • Cycle Analytics
    • Insights
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
    • Locked Files
  • Issues 3,610
    • Issues 3,610
    • List
    • Boards
    • Labels
    • Milestones
  • Merge Requests 200
    • Merge Requests 200
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Security & Compliance
    • Security & Compliance
    • Dependency List
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #7171

Closed
Open
Opened Aug 21, 2012 by jwlato@trac-jwlato
  • Report abuse
  • New issue
Report abuse New issue

erroneous overlapping instances reported with FunDeps

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.

Trac metadata
Trac field Value
Version 7.6.1-rc1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC jwlato@gmail.com
Operating system
Architecture

Related issues

  • Discussion
  • Designs
Assignee
Assign to
7.6.1
Milestone
7.6.1
Assign milestone
Time tracking
None
Due date
None
5
Labels
bug FunctionalDependencies P::highest Trac import typechecker
Assign labels
  • View project labels
Reference: ghc/ghc#7171