PROPOSAL: toBoundedIntegral: an adaptation of fromIntegral that respects bounds

Herbert Valerio Riedel hvr at gnu.org
Mon Nov 17 08:42:20 UTC 2014


On 2014-11-16 at 11:51:11 +0100, Sean Leather wrote:

[...]

> I do, however, suggest renaming intCastMaybe. Edward mentioned
> fromBitsIntegral. I would suggest toSizedIntegral (or
> fromSizedIntegral/fromIntegralSized, but I think toSizedIntegral is
> meaningful since it describes the result, not the argument), since that
> indicates the real usage of Bits in the function (which use bitSizeMaybe).
> Other bikeshed colors?

Fwiw, I'd be fine with all of `{to,from}{SizedIntegral,IntegralSized}`.

(my only concern would about the (mathematical) term 'integral' which is
a bit overloaded (try searching for "bounded integral"), but given
Haskell already established a precedent by 'fromIntegral' I guess
there's little risk of confusion here)

> Also, assuming there is enough interest (how much is enough?), I'd like to
> know what the next steps should be.
>
> Should someone create a Phab diff for it? (I can try it; however, I haven't
> yet used Phab, so, Herbert, if you want to do it with your code and mine,
> you can.) Also, we have to consider the Natural proposal and the
> toBoundedIntegral RULEs for it.

about the RULEs... do we really need them for `toBoundedIntegral`? If
you make `toBoundedIntegral` INLINEABLE, shouldn't you be able to
inherit the ones from 'fromIntegral' (which is what `intCastMaybe`
exploits)?

> Where should the functions go? intCastMaybe/toSizedIntegral could go in
> Data.Bits. What about toBoundedIntegral?

There's also

  http://hackage.haskell.org/package/base-4.7.0.1/docs/Numeric.html

as a candidate


More information about the Libraries mailing list