Inspired by conversations recent [1] and not-so-recent [2] and by my own past wish for this, I propose adding the following function to base:toBoundedIntegral :: (Integral a, Integral b, Bounded b) => a -> Maybe b
Discussion period: ~10 days if there is a strong desire to get it in GHC 7.10. (I would certainly like to see it get in.)
So is there any reason not to settle on 'toIntegralBounded' and 'toIntegralSized'?
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)?I didn't try that. I'll give it a shot.
> 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
Works for me. We could rename the section “Miscellaneous” to “Conversion” and put both functions there. Also, we should probably revise the module description since there is already a lot more than “functions for reading and showing RealFloat-like kind of values.”