Deprecating fromIntegral

Niklas Hamb├╝chen mail at nh2.me
Thu Sep 21 13:10:44 UTC 2017


Also, just to make that clear, the purpose here is not to to remove a
function that does something useful without providing a replacement.

It is to make sure that functions have appropriate names for what they
do, so that you don't use a function accidentally that has different
behaviour from what you expect.

For example, in the use of `ready` in GHC's Handle code


https://github.com/ghc/ghc/blob/ghc-8.2.1-release/libraries/base/GHC/IO/FD.hs#L399

the author certainly did not intend to have any wrapping behaviour, but
nothing in that code looks wrong unless you think really, really hard.

Because it looks correct.

(And has looked correct for 17 years:
https://github.com/ghc/ghc/blame/b83cfb91b4d36d148ebe171d31e2676c8f10f371/libraries/base/GHC/IO.hsc#L61)

If you wanted wrapping behaviour, a `wrapIntegral` would be your friend.

If a `wrapIntegral` is used in a place that shouldn't have it, that gets
noticed immediately in review.

On 21/09/17 14:53, Niklas Hamb├╝chen wrote:
> On 21/09/17 14:35, amindfv at gmail.com wrote:
>> I'm -1 on this (there are lots of places where you need to know the bounds of the numeric type you're using)
> 
> I don't quite understand what you mean with "you need to know the
> bounds", or what role `fromIntegral` has in that, can you elaborate?


More information about the Libraries mailing list