Add function for size-checked conversion of Integral types
Based on the discussion in this thread, I would like to add a function to the base
library that is similar to fromIntegral
but only successful if the argument fits in the result type.
If possible, I would like to get this into 7.10. My apologies for running late on it. Hopefully, since it is a relatively small change overall, the "only" controversy will be bikeshedding.
I have concluded that adding @hvr's intCastMaybe
from int-cast is the best possible option. Previously, I thought a Bounded
-based version was also useful; however, I realized that it did not deal optimally with conversions like Int<->Word
/Int8<->Word8
/etc. as well as intCastMaybe
does and would need specialized versions that intCastMaybe
provides automatically.