Opened 10 years ago

Closed 10 years ago

Last modified 46 years ago

#391 closed bug (Invalid)

unjustified deduction error

Reported by: nobody Owned by: nobody
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 6.4
Keywords: Cc:
Operating System: Architecture:
Type of failure: Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

(also sent to glasgow-haskell-users) [email protected]

the following (reduced) example used to go through with
ghc-6.2.2 but fails with ghc-6.4. 

This seems to be a - low priority - bug. (hugs accepts
this module.)
I compile with:

ghc -fglasgow-exts Context.hs


module Context where

class Language a
class Language a => Logic a b | a -> b
class (Language a, Logic b c, Logic d e)
    => Comorph a b c d e | a -> b, a -> d

instance (Comorph a1 b1 c1 d1 e1, Comorph a2 b2 c2 d2 e2)
    => Language (a1, a2)

instance (Comorph a1 b1 c1 d1 e1, Comorph a2 b2 c2 d2 e2)
    => Comorph (a1, a2) b1 c1 d2 e2

-- end of module

ghc-6.4 (or ghc-6.4.1) complains with:

Context.hs:11:0:
    Could not deduce (Comorph a2 b2 c21 d2 e21, Comorph
a1 b1 c11 d1 e11)
      from the context (Comorph a1 b1 c1 d1 e1, Comorph
a2 b2 c2 d2 e2)
      arising from the superclasses of an instance
declaration at
Context.hs:11:0
    Probable fix:
      add (Comorph a2 b2 c21 d2 e21, Comorph a1 b1 c11
d1 e11)
      to the instance declaration superclass context
    In the instance declaration for `Comorph (a1, a2)
b1 c1 d2 e2'


If I replace the first instance with
"instance (Language a1, Language a2) => Language (a1, a2)"
then ghc-6.4 is happy.

Cheers Christian

Attachments (1)

Context.2.hs (344 bytes) - added by nobody 10 years ago.

Download all attachments as: .zip

Change History (2)

Changed 10 years ago by nobody

comment:1 Changed 10 years ago by simonpj

  • Status changed from assigned to closed
Logged In: YES 
user_id=50165

Ha ha.  Yet another subtle functional dependency case.

First, the fix is easy: add the fundep
    a -> b c d e
to the class decl for Comorph.  You are relying on the indirect 
functional depenendencies via 'Logic'.

And that's what goes wrong. Below is a smaller test case 
that shows the same problem.  GHC is very very very careful 
about superclasses when compiling instance declarations, 
because it's all too easy to construct a recursive dictionary 
whose value is bottom.  The straightforward approach to the 
types leads to circular evidence....

Anyway, I don't propose to change this for now.  But it's a 
great test case and I've added it as tcfail138.hs

-- This one shows up another rather subtle functional-
dependecy
-- case.  The error is:
--
--    Could not deduce (C a b') from the context (C a b)
--      arising from the superclasses of an instance declaration 
at Foo.hs:8:0
--    Probable fix: add (C a b') to the instance declaration 
superclass context
--    In the instance declaration for `C (Maybe a) a'
--
-- Since L is a superclass of the (sought) constraint (C a b'), 
you might
-- think that we'd generate the superclasses (L a b') and (L a 
b), and now 
-- the fundep will force b=b'.  But GHC is very cautious about 
generating
-- superclasses when doing context reduction for instance 
declarations,
-- becasue of the danger of superclass loops.
--
-- So, today, this program fails.  It's trivial to fix by adding a 
fundep for C
-- 	class (G a, L a b) => C a b | a -> b

module ShouldFail where

class G a
class L a b | a -> b
class (G a, L a b) => C a b

instance C a b' => G (Maybe a)
instance C a b  => C (Maybe a) a
instance L (Maybe a) a

Note: See TracTickets for help on using tickets.