Integer package:relude

Arbitrary precision integers. In contrast with fixed-size integral types such as Int, the Integer type represents the entire infinite range of integers. Integers are stored in a kind of sign-magnitude form, hence do not expect two's complement form when using bit operations. If the value is small (i.e., fits into an Int), the IS constructor is used. Otherwise IP and IN constructors are used to store a BigNat representing the positive or the negative value magnitude, respectively. Invariant: IP and IN are used iff the value does not fit in IS.
Transforms an integer number to a bounded integral. It returns Nothing for integers outside the bound of the return type.
>>> integerToBounded @Int 42
Just 42
>>> integerToBounded @Int8 1024
Nothing
>>> integerToBounded @Int (toInteger (minBound :: Int))
Just (-9223372036854775808)

>>> integerToBounded @Int $ (toInteger (minBound :: Int)) - 1
Nothing
>>> integerToBounded @Int (toInteger (maxBound :: Int))
Just 9223372036854775807

>>> integerToBounded @Int $ (toInteger (maxBound :: Int)) + 1
Nothing
If you want to convert Int or Word to a bounded type, take a look at toIntegralSized function instead.
Transforms an integer number to a natural. Only non-negative integers are considered natural, everything else will return Nothing.
>>> integerToNatural (-1)
Nothing
>>> integerToNatural 0
Just 0
>>> integerToNatural 10
Just 10
Conversion from an Integer. An integer literal represents the application of the function fromInteger to the appropriate value of type Integer, so such literals have type (Num a) => a.
Conversion to Integer.