#7875 closed bug (fixed)

Unhelpful IncoherentInstances suggestion with FunctionalDependencies

Reported by: dreixel Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.7
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: typecheck/should_compile/T7875 Blocked By:
Blocking: Related Tickets:

Description

Consider the following program (simplified from http://hpaste.org/86928):

{-# LANGUAGE
    FlexibleContexts
  , FlexibleInstances
  , FunctionalDependencies
  , MultiParamTypeClasses
  , KindSignatures
  , UndecidableInstances #-}

class Het a b | a -> b where
  het :: m (f c) -> a -> m b

class GHet (a :: * -> *) (b :: * -> *) | a -> b
instance            GHet (K a) (K [a])
instance Het a b => GHet (K a) (K b)


data A a   = A (A a)
data K x a = K x

instance Het (A a) (A [a]) where het = het1

het1 :: (GHet (K a) (K b)) => m (f c) -> a -> m b
het1 = undefined

In HEAD, it gives rise to the following error:

    Overlapping instances for GHet (K (A a)) (K (A [a]))
      arising from a use of ‛het1’
    Matching instances:
      instance Het a b => GHet (K a) (K b) -- Defined at Bug.hs:14:10
    There exists a (perhaps superclass) match:
    (The choice depends on the instantiation of ‛a’
     To pick the first instance above, use -XIncoherentInstances
     when compiling the other instance declarations)
    In the expression: het1
    In an equation for ‛het’: het = het1
    In the instance declaration for ‛Het (A a) (A [a])’

It's already strange that it says multiple instances match, but it only lists one. Furthermore, enabling -XIncoherentInstances, as suggested, does not change the error message.

#7150 and #7171 might be related.

Change History (2)

comment:1 Changed 12 months ago by simonpj@…

commit d31dd88d4eae4e199d1341da2e7a7550a5e4c3a2

Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Fri May 3 07:42:57 2013 +0100

    In doTopReactDict, try lookup even if fundeps work
    
    Previously we looked for fundeps, and if any fired we
    didn't try to solve the constraint.  But that's wrong
    (see Note [Weird fundeps]).  Now I solve first and only
    if that fails try fundeps.  Code is neater too.
    
    Fixes Trac #7875

 compiler/typecheck/TcInteract.lhs |   60 ++++++++++++++++++------------------
 1 files changed, 30 insertions(+), 30 deletions(-)

comment:2 Changed 12 months ago by simonpj

  • Difficulty set to Unknown
  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to typecheck/should_compile/T7875

Excellent point. Thanks for telling me about this. It really was an outright bug.

Simon

Note: See TracTickets for help on using tickets.