Make `fromIntegralNoOverflow` safe
Clarification and motivation
fromIntegralNoOverflow
uses Universum.Base.fromIntegral
, which may fail with arithmetic underflow
exception, e.g.
> fromIntegralNoOverflow @Integer @Natural (-1)`
`*** Exception: arithmetic underflow`
However, fromIntegralNoOverflow
checks for overflow/underflow and returns Either
value. As a result, it is semi-unsafe, semi-explicitly-failing conversion function, which is confusing.
There is one idea how to make it statically safe - use spoonWithHandles
to obtain the ArithException
. Nevertheless, there still could be better ideas.
Acceptance criteria
fromIntegralNoOverflow
is
- is statically safe function
- placed in
Prelude
module instead ofUnsafe