unsafeShift operations for Data.Bits
Samuel Bronson
naesten at gmail.com
Mon Nov 6 12:38:06 EST 2006
On 11/6/06, Bulat Ziganshin <bulat.ziganshin at gmail.com> wrote:
> Hello libraries,
>
> fast shift operations that don't verify shift amount is rather popular
> demand. how about providing them in the Data.Bits?
>
>
> -- |Shifts its first operand left by the amount of bits specified in
> -- second operand. Result of shifting by negative/too large amount
> -- is not specified. Should be used only in situations when you may
> -- guarantee correct value of second operand or don't care about result :)
> unsafeShiftL :: Int -> Int -> Int
>
> unsafeShiftR :: Int -> Int -> Int
>
> #ifdef __GLASGOW_HASKELL__
> unsafeShiftL (I# a) (I# b) = (I# (a `iShiftL#` b))
> unsafeShiftR (I# a) (I# b) = (I# (a `uncheckedIShiftRL#` b))
> #else /* ! __GLASGOW_HASKELL__ */
> unsafeShiftL = shiftL
> unsafeShiftR = shiftR
> #endif /* ! __GLASGOW_HASKELL__ */
>
>
> it may be even better to include them in Bits class with obvious
> default definition
And use them for the default implementation of rotate, while we are at it.
More information about the Libraries
mailing list