GHC: Ticket #5763: Confusing error message
http://ghc.haskell.org/trac/ghc/ticket/5763
<p>
For test <tt>indexedtypes/should_fail/T4272</tt> we get this type error
</p>
<pre class="wiki">T4272.hs:11:16:
Occurs check: cannot construct the infinite type:
x0 = TermFamily x0 x0
Expected type: TermFamily x0 x0
Actual type: TermFamily a a
In the first argument of `prune', namely `t'
In the expression: prune t (terms (undefined :: TermFamily a a))
In an equation for `laws':
laws t = prune t (terms (undefined :: TermFamily a a))
</pre><p>
It's not at all obvious why unifying <tt>(TermFamily x0 x0)</tt> with <tt>(TermFamily a a)</tt> should yield an occurs check. Especially as <tt>TermFamily</tt> is a type function with arity 1, and <tt>x0</tt> is a unification variable. So the natural way to solve this constraint would be to unify <tt>x0</tt> with <tt>a</tt>, and then the constraint is satisfied.
</p>
<p>
What goes wrong is that there is <em>another</em> insolube constraint (which is also reported):
</p>
<pre class="wiki">T4272.hs:11:19:
Could not deduce (a ~ TermFamily x0 x0)
from the context (TermLike a)
bound by the type signature for
laws :: TermLike a => TermFamily a a > b
at T4272.hs:11:154
`a' is a rigid type variable bound by
the type signature for laws :: TermLike a => TermFamily a a > b
at T4272.hs:11:1
In the return type of a call of `terms'
In the second argument of `prune', namely
`(terms (undefined :: TermFamily a a))'
In the expression: prune t (terms (undefined :: TermFamily a a))
</pre><p>
The constraint solver finds this latter constraint, can't solve it, <em>but still uses it to simplify the first one</em>, by substituting <tt>(TermFamily x0 x0)</tt> for <tt>a</tt>; and that is what gives the occurs check error.
</p>
<p>
I don't think that we should use <em>insoluble</em> constraints to rewrite unsolved constraints. But it's delicate, so I am not trying to fiddle right now. Hence making this ticket.
</p>
<p>
(Incidentally, it's not a regression; it's been like this forever.)
</p>
enusGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/5763
Trac 1.0.1simonpjWed, 11 Jan 2012 08:27:27 GMTpriority changed
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:1
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:1
<ul>
<li><strong>priority</strong>
changed from <em>normal</em> to <em>high</em>
</li>
</ul>
<p>
I'll make it high priority to make sure I look at it for 7.6. But it's not really that serious.
</p>
TicketsimonpjWed, 11 Jan 2012 08:31:38 GMTtestcase changed
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:2
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:2
<ul>
<li><strong>testcase</strong>
changed from <em>indexedtypes/should_fail/T4272</em> to <em>indexedtypes/should_fail/T5763</em>
</li>
</ul>
TicketsimonpjMon, 02 Apr 2012 12:43:19 GMTowner set
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:3
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:3
<ul>
<li><strong>owner</strong>
set to <em>simonpj</em>
</li>
</ul>
TicketiglooWed, 12 Sep 2012 11:11:54 GMTmilestone changed
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:4
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:4
<ul>
<li><strong>milestone</strong>
changed from <em>7.6.1</em> to <em>7.6.2</em>
</li>
</ul>
TicketliyangTue, 26 Mar 2013 02:10:20 GMTcc changed
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:5
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:5
<ul>
<li><strong>cc</strong>
<em>hackage.haskell.org@…</em> added
</li>
</ul>
TicketwiraWed, 17 Jul 2013 08:20:20 GMT
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:6
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:6
<p>
can i know too problem solving
</p>
TicketthoughtpoliceMon, 14 Jul 2014 13:11:07 GMTpriority changed
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:7
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:7
<ul>
<li><strong>priority</strong>
changed from <em>high</em> to <em>normal</em>
</li>
</ul>
<p>
Lowering priority (these tickets are assigned to older versions, so they're getting bumped as they've been around for a while).
</p>
TicketthoughtpoliceMon, 14 Jul 2014 13:12:10 GMTmilestone changed
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:8
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:8
<ul>
<li><strong>milestone</strong>
changed from <em>7.6.2</em> to <em>7.10.1</em>
</li>
</ul>
<p>
Moving to 7.10.1.
</p>
TicketthomieThu, 27 Nov 2014 02:35:19 GMT
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:9
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:9
<p>
Is this problem solved?
</p>
<p>
<tt>T4272</tt> doesn't show the <tt>Occurs check</tt> message anymore (as also noted by SPJ in <a class="changeset" href="http://ghc.haskell.org/trac/ghc/changeset/da71a9524ffff0865222127bef09fd04a1359a53/ghc" title="Add comment">da71a9524ffff0865222127bef09fd04a1359a53</a>), but maybe this is incidental? I can not find test <tt>T5763</tt> anywhere, so I'll leave this open for now.
</p>
<p>
Output of running the command "git show <a class="changeset" href="http://ghc.haskell.org/trac/ghc/changeset/0b3c3c81792c88ee40687f86bed4935e721dabe0/ghc" title="Error message modifications following ghcnewsolver modifications">0b3c3c81792c88ee40687f86bed4935e721dabe0</a> testsuite/tests/indexedtypes/should_fail/T4272.stderr":
</p>
<pre class="wiki">Author: Dimitrios.Vytiniotis <>
Date: Wed Apr 4 14:41:11 2012 +0100
Error message modifications following ghcnewsolver modifications
diff git a/testsuite/tests/indexedtypes/should_fail/T4272.stderr b/testsuite/tests/indexedtypes/should_fail/T4272.stderr
index 24f0cbd..e809d9c 100644
 a/testsuite/tests/indexedtypes/should_fail/T4272.stderr
+++ b/testsuite/tests/indexedtypes/should_fail/T4272.stderr
@@ 1,29 +1,6 @@
T4272.hs:11:16:
 Couldn't match type `TermFamily (TermFamily x0 x0)'
 with `TermFamily x0'
 NB: `TermFamily' is a type function, and may not be injective
 The type variable `x0' is ambiguous
 Possible fix: add a type signature that fixes these type variable(s)
 Expected type: TermFamily x0 x0
 Actual type: TermFamily a a
 In the first argument of `prune', namely `t'
 In the expression: prune t (terms (undefined :: TermFamily a a))
 In an equation for `laws':
 laws t = prune t (terms (undefined :: TermFamily a a))

T4272.hs:11:16:
 Occurs check: cannot construct the infinite type:
 x0 = TermFamily x0 x0
 Expected type: TermFamily x0 x0
 Actual type: TermFamily a a
 In the first argument of `prune', namely `t'
 In the expression: prune t (terms (undefined :: TermFamily a a))
 In an equation for `laws':
 laws t = prune t (terms (undefined :: TermFamily a a))

T4272.hs:11:19:
 Could not deduce (a ~ TermFamily x0 x0)
+T4272.hs:11:26:
+ Could not deduce (a ~ TermFamily a a)
from the context (TermLike a)
bound by the type signature for
laws :: TermLike a => TermFamily a a > b
@@ 31,7 +8,10 @@ T4272.hs:11:19:
`a' is a rigid type variable bound by
the type signature for laws :: TermLike a => TermFamily a a > b
at T4272.hs:10:16
 In the return type of a call of `terms'
+ Expected type: TermFamily a (TermFamily a a)
+ Actual type: TermFamily a a
+ In the first argument of `terms', namely
+ `(undefined :: TermFamily a a)'
In the second argument of `prune', namely
`(terms (undefined :: TermFamily a a))'
In the expression: prune t (terms (undefined :: TermFamily a a))
</pre>
TicketsimonpjThu, 27 Nov 2014 14:09:02 GMTstatus changed; resolution set; testcase deleted
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:10
http://ghc.haskell.org/trac/ghc/ticket/5763#comment:10
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>testcase</strong>
<em>indexedtypes/should_fail/T5763</em> deleted
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
</ul>
<p>
Well we indeed no longer use insoluble constraints to rewrite others, so yes, I think we can close this.
</p>
<p>
Simon
</p>
Ticket