GHC: Ticket #3490: Relax superclass restrictions
http://ghc.haskell.org/trac/ghc/ticket/3490
<p>
Doaitse points out that we currently reject
</p>
<pre class="wiki">class C a b | a -> b where
class C a b => D a where
</pre><p>
on the grounds that 'b' is not in scope in the second class decl. (Only type variables in the "head", namely (D a), can be mentioned in the superclass context.) My response to him was as follows.
</p>
<p>
The easiest way forward is to re-express your program using type functions. Then class C will have just a single type parameter (a), with the 'b' part being expressed by a type function. That would resolve the problem rather nicely.
</p>
<p>
Medium term, I think the Right Thing is to allow a class declaration
</p>
<pre class="wiki">class Q => C a b
</pre><p>
(where Q is a context) if and only iff the type
</p>
<pre class="wiki">forall ab. Q => C a b
</pre><p>
is unambiguous. What does "unambiguous" mean? As it happens, we are working on nailing that down right now. For example, here is a stupid but unambiguous declaration:
</p>
<pre class="wiki">type family F a
class (b ~ F a, Eq b) => C a
</pre><p>
I do not know of any non-stupid examples that would be rejected by the current rule, but there might be some.
I'll open a ticket because I'd like to get to this when we have the other pieces working.
</p>
en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/3490
Trac 1.2clausTue, 08 Sep 2009 09:46:51 GMT
http://ghc.haskell.org/trac/ghc/ticket/3490#comment:1
http://ghc.haskell.org/trac/ghc/ticket/3490#comment:1
<p>
This sounded familiar. See <a class="closed ticket" href="http://ghc.haskell.org/trac/ghc/ticket/714" title="#714: bug: Inconsistency between handling functional dependencies in class and ... (closed: duplicate)">#714</a> .
</p>
TicketsimonpjTue, 08 Sep 2009 11:00:48 GMT
http://ghc.haskell.org/trac/ghc/ticket/3490#comment:2
http://ghc.haskell.org/trac/ghc/ticket/3490#comment:2
<p>
Dead right -- thanks.
</p>
TicketsimonmarFri, 06 Nov 2009 09:44:31 GMT
http://ghc.haskell.org/trac/ghc/ticket/3490#comment:3
http://ghc.haskell.org/trac/ghc/ticket/3490#comment:3
<p>
So should this be closed as a duplicate?
</p>
TicketsimonpjFri, 06 Nov 2009 10:56:08 GMTtype changed
http://ghc.haskell.org/trac/ghc/ticket/3490#comment:4
http://ghc.haskell.org/trac/ghc/ticket/3490#comment:4
<ul>
<li><strong>type</strong>
changed from <em>bug</em> to <em>feature request</em>
</li>
</ul>
<p>
Actually I'll close <a class="closed ticket" href="http://ghc.haskell.org/trac/ghc/ticket/714" title="#714: bug: Inconsistency between handling functional dependencies in class and ... (closed: duplicate)">#714</a> in favour of this ticket. <a class="closed ticket" href="http://ghc.haskell.org/trac/ghc/ticket/714" title="#714: bug: Inconsistency between handling functional dependencies in class and ... (closed: duplicate)">#714</a> has an interesting discussion but it wanders around a bit, whereas this ticket now focuses on the actual feature request.
</p>
<p>
Simon
</p>
TicketDevarshDesaiWed, 01 Jul 2015 05:41:18 GMTowner, failure set
http://ghc.haskell.org/trac/ghc/ticket/3490#comment:5
http://ghc.haskell.org/trac/ghc/ticket/3490#comment:5
<ul>
<li><strong>owner</strong>
set to <em>DevarshDesai</em>
</li>
<li><strong>failure</strong>
set to <em>None/Unknown</em>
</li>
</ul>
Ticket