GHC: Ticket #6117: Cyclic Type Class Hierarchy Produces <<loop>>
http://ghc.haskell.org/trac/ghc/ticket/6117
<p>
If there is a cyclic class hierarchy like
</p>
<pre class="wiki"> class B a => Semigroup a where ...[[BR]]
class Semigroup (Additive a) => Ring a where ...[[BR]]
instance Ring a => Semigroup (Additive a) where ...[[BR]]
</pre><p>
then uses of B's methods on <tt>(Additive a)</tt> in the method implementations of the
third declaration <tt>instance Ring a => Semigroup (Additive a)</tt> will:
</p>
<ol><li>be accepted by the compiler even in cases where <tt>B (Additive a)</tt> is not derivable.
</li><li>result in <<loop>>.
</li></ol><p>
The attached program prints <<loop>> when compiled with GHC-7.2.1 or newer but prints 1234567890 when compiled with GHC-7.0.4 or older. I haven't had time to try out any revisions in between those two, but I did check that HEAD produces <<loop>> as well.
</p>
en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/6117
Trac 1.0.9jun0Sun, 20 May 2012 00:33:50 GMTattachment set
http://ghc.haskell.org/trac/ghc/ticket/6117
http://ghc.haskell.org/trac/ghc/ticket/6117
<ul>
<li><strong>attachment</strong>
set to <em>test.hs</em>
</li>
</ul>
TicketsimonpjMon, 21 May 2012 17:02:30 GMTdifficulty set
http://ghc.haskell.org/trac/ghc/ticket/6117#comment:1
http://ghc.haskell.org/trac/ghc/ticket/6117#comment:1
<ul>
<li><strong>difficulty</strong>
set to <em>Unknown</em>
</li>
</ul>
<p>
Thanks. I think this is another example of <a class="closed ticket" href="http://ghc.haskell.org/trac/ghc/ticket/5751" title="bug: code works in 7.0 but hangs in 7.2/7.4 due to changes in type checker ... (closed: fixed)">#5751</a>. I know how to fix it but am hoping to wait until after the Haskell Symposium deadline (2 June). How much of a problem is it for you?
</p>
Ticketjun0Mon, 21 May 2012 19:03:53 GMT
http://ghc.haskell.org/trac/ghc/ticket/6117#comment:2
http://ghc.haskell.org/trac/ghc/ticket/6117#comment:2
<p>
That sure looks like the same problem. This is just some test code for a library we're writing, so it can wait. We'll just not run this test till the problem gets fixed.
</p>
TicketiglooThu, 11 Oct 2012 19:58:48 GMTcomponent changed; owner, testcase, milestone set
http://ghc.haskell.org/trac/ghc/ticket/6117#comment:3
http://ghc.haskell.org/trac/ghc/ticket/6117#comment:3
<ul>
<li><strong>owner</strong>
set to <em>simonpj</em>
</li>
<li><strong>testcase</strong>
set to <em>T6117</em>
</li>
<li><strong>component</strong>
changed from <em>Compiler</em> to <em>Compiler (Type checker)</em>
</li>
<li><strong>milestone</strong>
set to <em>7.8.1</em>
</li>
</ul>
<p>
I'm getting a core lint failure for this test:
</p>
<pre class="wiki">=====> T6117(normal) 69 of 69 [0, 0, 0]
cd . && '/home/ian/ghc/git/ghc/inplace/bin/ghc-stage2' -fforce-recomp -dcore-lint -dcmm-lint -dno-debug-output -no-user-package-db -rtsopts -fno-ghci-history -o T6117 T6117.hs >T6117.comp.stderr 2>&1
Compile failed (status 256) errors were:
[1 of 1] Compiling Main ( T6117.hs, T6117.o )
*** Core Lint errors : in result of Simplifier ***
{-# LINE 37 "T6117.hs #-}: Warning:
[RHS of Main.$fBAdditive :: forall a_ahu.
Main.B a_ahu =>
Main.B (Main.Additive a_ahu)]
Bad axiom application (check_ki2)
Main.NTCo:B (Sym (Main.NTCo:B (Main.NTCo:Additive <a_XhN>)))
*** Offending Program ***
[...]
</pre>
TicketsimonpjFri, 12 Oct 2012 07:41:42 GMTdescription changed
http://ghc.haskell.org/trac/ghc/ticket/6117#comment:4
http://ghc.haskell.org/trac/ghc/ticket/6117#comment:4
<ul>
<li><strong>description</strong>
modified (<a href="/trac/ghc/ticket/6117?action=diff&version=4">diff</a>)
</li>
</ul>
TicketmonoidalThu, 22 Nov 2012 19:14:57 GMT
http://ghc.haskell.org/trac/ghc/ticket/6117#comment:5
http://ghc.haskell.org/trac/ghc/ticket/6117#comment:5
<p>
In fact, the core lint error is on much simpler:
</p>
<pre class="wiki">class B a where
b :: a
newtype Additive a = Additive a
instance B a => B (Additive a) where
b = Additive b
main = undefined
</pre><p>
This is a bit worrisome, since this is a rather natural program.
</p>
TicketsimonpjFri, 23 Nov 2012 18:05:34 GMT
http://ghc.haskell.org/trac/ghc/ticket/6117#comment:6
http://ghc.haskell.org/trac/ghc/ticket/6117#comment:6
<p>
You should not worry about this. In GHC we have kind <tt>*</tt> and kind <tt>Constraint</tt>. They are really the <em>same</em> kind, so far as System FC is concerned. But they are distinct in the following sense: given a type
</p>
<pre class="wiki"> f :: t1 -> t2 -> t3
</pre><p>
where
</p>
<pre class="wiki"> t1 :: Constraint
t2 :: *
t3 :: *
</pre><p>
the type inference engine will auto-instantiate a constraint for <tt>t1</tt>, but not for <tt>t2</tt>. Also it'll display the type as
</p>
<pre class="wiki"> f :: t1 => t2 -> t3
</pre><p>
What I need to so is to make the distinctions in only the right places, and it's not quite right now.
</p>
<p>
In short, don't lose sleep.
</p>
TicketsimonpjMon, 26 Nov 2012 11:55:11 GMTstatus changed; resolution set
http://ghc.haskell.org/trac/ghc/ticket/6117#comment:7
http://ghc.haskell.org/trac/ghc/ticket/6117#comment:7
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
</ul>
<p>
I've opened a new ticket <a class="closed ticket" href="http://ghc.haskell.org/trac/ghc/ticket/7451" title="bug: Constraint and * should not be distinct in FC (closed: fixed)">#7451</a> for this, since the new topic is nothing to do with the original subject of this ticket.
</p>
Ticket