GHC: Ticket #589: Various poor type error messages
http://ghc.haskell.org/trac/ghc/ticket/589
<p>
Hello,
</p>
<p>
I read the summary of the survey and noticed you wanted feedback on
where error messages could be improved. I looked up some (simple)
examples of type errors and ran them through ghc. I do not make any
claims to be an HCI expert, just a mere mortal with an opinion.
</p>
<p>
<strong>Type error 1</strong>
</p>
<p>
Code:
</p>
<pre class="wiki">1 module Test2 where
2
3 fib n = if (3 > n) then 1 else (fib (n - 1) + fib (n - 2))
4 k = fib 's'
</pre><p>
Error message:
</p>
<pre class="wiki">Test2.hs:4:
No instance for (Num Char)
arising from use of `fib' at Test2.hs:4
In the definition of `k': k = fib 's'
</pre><p>
This isn't a bad error message in my humble opinion, it does pinpoint
that I'm doing something wrong in line 4, and that there isn't an
instance for Num Char doesn't come as a surprise. However I think it
could have been more helpful by telling me that I tried to pass a Char
to a function which expected an (Ord a, Num a) => a as its parameter.
</p>
<p>
<strong>Type error 2</strong>
</p>
<p>
Code:
</p>
<pre class="wiki">1 module Test4 where
2
3 k :: Int -> Int
4 k l = 2.0*l
</pre><p>
Error message:
</p>
<pre class="wiki">Test4.hs:4:
No instance for (Fractional Int)
arising from the literal `2.0' at Test4.hs:4
In the first argument of `(*)', namely `2.0'
In the definition of `k': k l = 2.0 * l
</pre><p>
One reason this kind of error could happen is an inexperienced user
declaring the wrong type for his function, or not knowing that 2.0
would be interpreted as a Fractional.
</p>
<p>
<strong>Type error 3</strong>
</p>
<p>
Code:
</p>
<pre class="wiki">1 module Test7 where
2
3 len' xs = head (xs) + (length xs)
4 o = len' "GH"
</pre><p>
Error message:
</p>
<pre class="wiki">Test7.hs:4:
Couldn't match `Int' against `Char'
Expected type: [Int]
Inferred type: [Char]
In the first argument of `len'', namely `"GH"'
In the definition of `o': o = len' "GH"
</pre><p>
I ran this through Hugs version November 2002 and got this error
message:
</p>
<pre class="wiki">ERROR "Test7.hs":4 - Type error in application
*** Expression : len' "GH"
*** Term : "GH"
*** Type : String
*** Does not match : [Int]
</pre><p>
I find the Hugs message more clear, but that might be my background.
</p>
<p>
<strong>Type error 4</strong>
</p>
<p>
Code:
</p>
<pre class="wiki">1 module Test8 where
2
3 f = head 3
</pre><p>
Error message:
</p>
<pre class="wiki">Test8.hs:3:
No instance for (Num [a])
arising from the literal `3' at Test8.hs:3
Possible cause: the monomorphism restriction applied to the following:
f :: a (bound at Test8.hs:3)
Probable fix: give these definition(s) an explicit type signature
In the first argument of `head', namely `3'
In the definition of `f': f = head 3
</pre><p>
This one I find outright scary. For "wrong = div 3 8 + 1/2" it gives
an error message that somewhat helps me guess the error, but the above
doesn't even come close to helping me.
</p>
<p>
/ Peter
</p>
en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/589
Trac 1.2.2iglooThu, 25 Jan 2007 13:33:17 GMTdifficulty, os, architecture, milestone set
http://ghc.haskell.org/trac/ghc/ticket/589#comment:1
http://ghc.haskell.org/trac/ghc/ticket/589#comment:1
<ul>
<li><strong>difficulty</strong>
set to <em>Unknown</em>
</li>
<li><strong>os</strong>
set to <em>Unknown</em>
</li>
<li><strong>architecture</strong>
set to <em>Unknown</em>
</li>
<li><strong>milestone</strong>
set to <em>6.8</em>
</li>
</ul>
TicketguestTue, 03 Jul 2007 10:54:22 GMTcc set
http://ghc.haskell.org/trac/ghc/ticket/589#comment:2
http://ghc.haskell.org/trac/ghc/ticket/589#comment:2
<ul>
<li><strong>cc</strong>
<em>ganesh@…</em> added
</li>
</ul>
TicketguestTue, 03 Jul 2007 11:05:16 GMTcc changed
http://ghc.haskell.org/trac/ghc/ticket/589#comment:3
http://ghc.haskell.org/trac/ghc/ticket/589#comment:3
<ul>
<li><strong>cc</strong>
<em>ganesh.sittampalam@…</em> added; <em>ganesh@…</em> removed
</li>
</ul>
TicketsimonmarTue, 13 Nov 2007 15:19:37 GMTmilestone changed
http://ghc.haskell.org/trac/ghc/ticket/589#comment:4
http://ghc.haskell.org/trac/ghc/ticket/589#comment:4
<ul>
<li><strong>milestone</strong>
changed from <em>6.8 branch</em> to <em>_|_</em>
</li>
</ul>
TicketsimonpjWed, 14 Nov 2007 08:01:37 GMT
http://ghc.haskell.org/trac/ghc/ticket/589#comment:5
http://ghc.haskell.org/trac/ghc/ticket/589#comment:5
<p>
See also <a class="closed ticket" href="http://ghc.haskell.org/trac/ghc/ticket/451" title="#451: bug: GHC poor type-checker error message (closed: wontfix)">#451</a>
</p>
TicketsimonmarTue, 30 Sep 2008 15:37:41 GMTarchitecture changed
http://ghc.haskell.org/trac/ghc/ticket/589#comment:6
http://ghc.haskell.org/trac/ghc/ticket/589#comment:6
<ul>
<li><strong>architecture</strong>
changed from <em>Unknown</em> to <em>Unknown/Multiple</em>
</li>
</ul>
TicketsimonmarTue, 30 Sep 2008 15:52:04 GMTos changed
http://ghc.haskell.org/trac/ghc/ticket/589#comment:7
http://ghc.haskell.org/trac/ghc/ticket/589#comment:7
<ul>
<li><strong>os</strong>
changed from <em>Unknown</em> to <em>Unknown/Multiple</em>
</li>
</ul>
TicketiglooSat, 02 Jan 2010 20:09:17 GMTdescription changed; failure set
http://ghc.haskell.org/trac/ghc/ticket/589#comment:8
http://ghc.haskell.org/trac/ghc/ticket/589#comment:8
<ul>
<li><strong>failure</strong>
set to <em>None/Unknown</em>
</li>
<li><strong>description</strong>
modified (<a href="/trac/ghc/ticket/589?action=diff&version=8">diff</a>)
</li>
</ul>
TicketiglooSat, 02 Jan 2010 20:23:55 GMTfailure changed
http://ghc.haskell.org/trac/ghc/ticket/589#comment:9
http://ghc.haskell.org/trac/ghc/ticket/589#comment:9
<ul>
<li><strong>failure</strong>
changed from <em>None/Unknown</em> to <em>Other</em>
</li>
</ul>
<p>
The errors are essentially unchanged in 6.12.1.
</p>
Ticket