GHC: Ticket #1455: Wildcard pattern _ generates defaulting warning
http://ghc.haskell.org/trac/ghc/ticket/1455
<p>
The <em>second</em> use of properFraction generates a Defaulting warning, even though the Integral value in question is being thrown away:
</p>
<pre class="wiki">module Main where
r :: Double
r = pi
main :: IO ()
main =
let (_,x) = properFraction r :: (Integer,Double)
(_,y) = properFraction r
in putStrLn $ show (x,y)
</pre><p>
It is clearly trivial to work around this issue. However, if one takes the point of view that all of one's final code should compile using the -Wall -Werror flags, then the work around confirms dynamic typers' worst fears about Haskell. One shouldn't have to say anything about a value that's being thrown away; the compiler should make the most efficient call what to do, not e.g. some tightly wound mathematician who believes that Integer is the only valid Integral type.
</p>
<p>
Here is the compiler output:
</p>
<pre class="wiki">% ghc -v -Wall -Werror Bug.hs
Glasgow Haskell Compiler, Version 6.6, for Haskell 98, compiled by GHC version 6.6
Using package config file: /usr/local/lib/ghc-6.6/package.conf
wired-in package base mapped to base-2.0
wired-in package rts mapped to rts-1.0
wired-in package haskell98 mapped to haskell98-1.0
wired-in package template-haskell mapped to template-haskell-2.0
Hsc static flags: -static
Created temporary directory: /tmp/ghc12130_0
*** Checking old interface for main:Main:
*** Parser:
*** Renamer/typechecker:
Bug.hs:9:15:
Warning: Defaulting the following constraint(s) to type `Integer'
`Integral t' arising from use of `properFraction' at Bug.hs:9:15-30
In the expression: properFraction r
In a pattern binding: (_, y) = properFraction r
In the expression:
let
(_, x) = properFraction r :: (Integer, Double)
(_, y) = properFraction r
in putStrLn $ (show (x, y))
*** Deleting temp files:
Deleting: /tmp/ghc12130_0/ghc12130_0.s
Warning: deleting non-existent /tmp/ghc12130_0/ghc12130_0.s
*** Deleting temp dirs:
Deleting: /tmp/ghc12130_0
</pre>en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/1455
Trac 1.0.1Isaac DupreeFri, 22 Jun 2007 19:01:20 GMT
http://ghc.haskell.org/trac/ghc/ticket/1455#comment:1
http://ghc.haskell.org/trac/ghc/ticket/1455#comment:1
<p>
Unfortunately, the type-class could be used in some way that determines other parts of the result. For example
</p>
<pre class="wiki">properFractionNOT :: (RealFrac a, Integral b) => a -> (b, a)
properFractionNOT a = (b', a')
where
a' = a + (fromIntegral (5000000000000000 `asTypeOf` b'))
b' = 2
</pre><p>
produces different answers depending on the type of b:
</p>
<pre class="wiki">> snd $ (properFractionNOT:: Rational -> (Integer,Rational)) 3
5000000000000003%1
> snd $ (properFractionNOT:: Rational -> (Int,Rational)) 3
937459715%1
</pre><p>
So it is, at least, not _easy_ to detect situations where the class-constraint is used only to determine the very same result...
</p>
TicketiglooSun, 24 Jun 2007 21:42:18 GMTstatus changed; resolution set
http://ghc.haskell.org/trac/ghc/ticket/1455#comment:2
http://ghc.haskell.org/trac/ghc/ticket/1455#comment:2
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>wontfix</em>
</li>
</ul>
<p>
Isaac is right, the type chosen really can matter.
</p>
Ticket