unsafeShift operations for Data.Bits

Bulat Ziganshin bulat.ziganshin at gmail.com
Mon Nov 6 04:59:31 EST 2006


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
  

-- 
Best regards,
 Bulat                          mailto:Bulat.Ziganshin at gmail.com



More information about the Libraries mailing list