logo       

[ ghc-Bugs-1206891 ] unjustified deduction error: msg#00117

lang.haskell.glasgow.bugs

Subject: [ ghc-Bugs-1206891 ] unjustified deduction error

Bugs item #1206891, was opened at 2005-05-23 08:13
Message generated for change (Comment added) made by simonpj
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=108032&aid=1206891&group_id=8032

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Compiler (Type checker)
Group: 6.4
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: unjustified deduction error

Initial Comment:
(also sent to glasgow-haskell-users) maeder@xxxxxx

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

----------------------------------------------------------------------

>Comment By: Simon Peyton Jones (simonpj)
Date: 2005-05-24 10:48

Message:
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


----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=108032&aid=1206891&group_id=8032


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise