[Haskell-beginners] Defaulting the following constraint ....
Alan Buxton
alanbuxton
Thu Oct 3 18:48:45 UTC 2013
Thanks a lot
Best
A
??? ?? iPad ???
3 Oct 2013, 19:33, ?/? Brandon Allbery <allbery.b at gmail.com> ??????:
>> On Thu, Oct 3, 2013 at 1:52 PM, Alan Buxton <alanbuxton at gmail.com> wrote:
>> niceShow x = if isInt x then show (floor x :: Int) else show x
>>
>>
>> I get a warning about a ?too strict if?. If I then follow the recommendation and change niceShow to be
>>
>>
>>
>> show (if isInt x then (floor x :: Int) else x)
>>
>>
>>
>> Then I get an error that Couldn't match expected type `Int' with actual type `Double' which makes sense because floor x :: Int produces an Int but x alone is a Double. Surely hlint could have figured this out from the type signatures and not made the recommendation to change my if structure?
>>
>>
>
> hlint doesn't recognize types, only code structure to some extent (it is a parser, not a compiler). As such, it will sometimes produce bad advice like that.
>
> "Too strict if" pretty much means what you saw... that you have the same structure in both legs and it thinks you should abstract it out. But, as I noted, it doesn't know about types so it can't recognize that you can't type the refactored expression. In fact I'd generally claim that "Too strict if" is by far its worst designed diagnostic, because of its inability to recognize types and because the resulting message is incomprehensible.
>
> In short, take hlint's diagnostics with several grains of salt.
>
> --
> brandon s allbery kf8nh sine nomine associates
> allbery.b at gmail.com ballbery at sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20131003/c0aec0ba/attachment.html>
More information about the Beginners
mailing list