Add function for size-checked conversion of Integral types
authorSean Leather <sean.leather@gmail.com>
Fri, 21 Nov 2014 22:34:41 +0000 (23:34 +0100)
committerHerbert Valerio Riedel <hvr@gnu.org>
Fri, 21 Nov 2014 22:45:28 +0000 (23:45 +0100)
commit02f8f6ad7bd3d792459a1d33e8d0d57dcf1ea424
tree3a091f68b888b3c229f59765161d6febfb92bb74
parent3222b7ae347be092bdd414f7b43bee18861b0e1e
Add function for size-checked conversion of Integral types

The new function `Data.Bits.toIntegralSized` provides a similar
functionality to `fromIntegral` but adds validation that the
argument fits in the result type's size.

The implementation of `toIntegralSized` has been derived from `intCastMaybe`
(which is part of Herbert Valerio Riedel's `int-cast` package,
see http://hackage.haskell.org/package/int-cast)

Addresses #9816

Reviewed By: ekmett, austin

Differential Revision: https://phabricator.haskell.org/D512
libraries/base/Data/Bits.hs
libraries/base/changelog.md