
It is because you do a floor on x, returning a where a is an Integral, but
which Integral is it? Is it an Int or an Integer? Well it decides to
default it to integer because that is what ghci does as it is the safe
option, but it decided to warn you about it just so you are aware.
Afterall integers are slower than ints, and you might have wanted an int.
You can silence the warning by telling it what to do:
niceShow x = if (isInt x) then show (floor x :: Int) else show x
niceShow x = if (isInt x) then show (floor x :: Integer) else show x
On Mon, Sep 30, 2013 at 4:06 PM, Alan Buxton
Hi****
** **
I have something like this – purpose is that I need to drop redundant .0 in a whole number – so to show 1.2345 as 1.2345 and to show 1.0 as 1****
** **
*module Test where*
* *
*niceShow x = if (isInt x) then show (floor x) else show x*
* *
*isInt x = x == fromInteger (floor x)*****
**
But the hlint in my vim plugin keeps warning me that****
** **
test.hs|3 col 38 warning| Defaulting the following constraint(s) to type `Integer'****
|| (Integral a0) arising from a use of `floor' at /tmp/test.hs:3:38-42****
|| (Show a0) arising from a use of `show' at /tmp/test.hs:3:32-35****
|| In the first argument of `show', namely `(floor x)'****
|| In the expression: show (floor x)****
|| In the expression: if (isInt x) then show (floor x) else show x****
** **
What does this mean? And what would I need to do in order to prevent this warning?****
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners