GHC: Ticket #4921: report ambiguous type variables more consistently
http://ghc.haskell.org/trac/ghc/ticket/4921
<pre class="wiki">{-# LANGUAGE MultiParamTypeClasses #-}
module Amb where
class C a b where
f :: (a,b)
instance C Int Char where
f = undefined
{-
x = fst f
/home/saizan/snippets/Amb.hs:7:8:
Ambiguous type variables `a', `b' in the constraint:
`C a b'
arising from a use of `f' at /home/saizan/snippets/Amb.hs:7:8
Possible cause: the monomorphism restriction applied to the following:
x :: a (bound at /home/saizan/snippets/Amb.hs:7:0)
Probable fix: give these definition(s) an explicit type signature
or use -XNoMonomorphismRestriction
Failed, modules loaded: none.
-}
{-
y = fst f :: Int
/home/saizan/snippets/Amb.hs:21:8:
No instance for (C Int b)
arising from a use of `f' at /home/saizan/snippets/Amb.hs:21:8
Possible fix: add an instance declaration for (C Int b)
In the first argument of `fst', namely `f'
In the expression: fst f :: Int
In the definition of `y': y = fst f :: Int
Failed, modules loaded: none.
-}
</pre><p>
Both x and y have the same problem, there isn't enough type information to let the typechecker decide on an instance, so it seems they should produce similar error messages.
</p>
<p>
In particular, the error for y is quite confusing since it can be reasonably interpreted as saying there's no type b for which there's an instance C Int b, which in fact is not true, so i think explicitly mentioning the ambiguity like in the first message would help many to understand the problem better.
</p>
<p>
I can see though that an "instance C Int b" could make sense, more often than C a b, so maybe "Possible fix: add an instance declaration for (C Int b)" should be conserved, even if it still has the problem of expressing that the second argument needs to be a variable.
</p>
en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/4921
Trac 1.2.2iglooSun, 13 Feb 2011 22:05:20 GMTcomponent changed; milestone set
http://ghc.haskell.org/trac/ghc/ticket/4921#comment:1
http://ghc.haskell.org/trac/ghc/ticket/4921#comment:1
<ul>
<li><strong>component</strong>
changed from <em>Compiler</em> to <em>Compiler (Type checker)</em>
</li>
<li><strong>milestone</strong>
set to <em>7.2.1</em>
</li>
</ul>
<p>
Thanks for the report.
</p>
TicketiglooFri, 10 Feb 2012 16:15:47 GMTpriority, milestone changed
http://ghc.haskell.org/trac/ghc/ticket/4921#comment:2
http://ghc.haskell.org/trac/ghc/ticket/4921#comment:2
<ul>
<li><strong>priority</strong>
changed from <em>normal</em> to <em>low</em>
</li>
<li><strong>milestone</strong>
changed from <em>7.4.1</em> to <em>7.6.1</em>
</li>
</ul>
TicketiglooWed, 12 Sep 2012 11:13:24 GMTmilestone changed
http://ghc.haskell.org/trac/ghc/ticket/4921#comment:3
http://ghc.haskell.org/trac/ghc/ticket/4921#comment:3
<ul>
<li><strong>milestone</strong>
changed from <em>7.6.1</em> to <em>7.6.2</em>
</li>
</ul>
TicketthoughtpoliceMon, 14 Jul 2014 13:07:28 GMTmilestone changed
http://ghc.haskell.org/trac/ghc/ticket/4921#comment:4
http://ghc.haskell.org/trac/ghc/ticket/4921#comment:4
<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>
TicketthomieFri, 28 Nov 2014 19:33:34 GMTdifficulty set
http://ghc.haskell.org/trac/ghc/ticket/4921#comment:5
http://ghc.haskell.org/trac/ghc/ticket/4921#comment:5
<ul>
<li><strong>difficulty</strong>
set to <em>Unknown</em>
</li>
</ul>
<p>
This seems fixed, pending a regression test. The error messages for <code>x</code> and <code>y</code> are no longer completely different.
</p>
<p>
Ghc shows for <code>y</code>, since version 7.6.3: <code>The type variable ‘b0’ is ambiguous</code>. And since version 7.8.3 it doesn't show anymore: <code>Possible fix: add an instance declaration for (C Int b)</code>.
</p>
<p>
Here is the full error message with HEAD:
</p>
<pre class="wiki">$ ghc-7.9.20141125 test.hs
[1 of 1] Compiling Amb ( test.hs, test.o )
test.hs:10:9:
No instance for (C a0 b1) arising from a use of ‘f’
The type variables ‘a0’, ‘b1’ are ambiguous
Relevant bindings include x :: a0 (bound at test.hs:10:1)
Note: there is a potential instance available:
instance C Int Char -- Defined at test.hs:7:10
In the first argument of ‘fst’, namely ‘f’
In the expression: fst f
In an equation for ‘x’: x = fst f
test.hs:11:9:
No instance for (C Int b0) arising from a use of ‘f’
The type variable ‘b0’ is ambiguous
Note: there is a potential instance available:
instance C Int Char -- Defined at test.hs:7:10
In the first argument of ‘fst’, namely ‘f’
In the expression: fst f :: Int
In an equation for ‘y’: y = fst f :: Int
</pre>
TicketSimon Peyton Jones <simonpj@…>Tue, 02 Dec 2014 13:27:36 GMT
http://ghc.haskell.org/trac/ghc/ticket/4921#comment:6
http://ghc.haskell.org/trac/ghc/ticket/4921#comment:6
<p>
In <a class="changeset" href="http://ghc.haskell.org/trac/ghc/changeset/30d260586d46466419b109057ec87d4f097331a1/ghc" title="Test Trac #4921">30d260586d46466419b109057ec87d4f097331a1/ghc</a>:
</p>
<pre class="message">Test Trac #4921</pre>
TicketsimonpjTue, 02 Dec 2014 13:34:38 GMTstatus changed; testcase, resolution set
http://ghc.haskell.org/trac/ghc/ticket/4921#comment:7
http://ghc.haskell.org/trac/ghc/ticket/4921#comment:7
<ul>
<li><strong>testcase</strong>
set to <em>typecheck/should_fail/T4921</em>
</li>
<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>
Ticket