Skip to content

Data.Bits.shiftL should generate overflow exception for Integer operand

Summary

Data.Bits.shiftL doc says shiftL should never be called with negative value. Int instance returns an overflow exception, but Integer returns something reasonable. It's confusing to see behaviour change by slightly changing the type of a program:

GHCi, version 8.8.4: https://www.haskell.org/ghc/  :? for help
Prelude> Data.Bits.shiftL (1 :: Integer) ((-1) :: Int)
0
Prelude> Data.Bits.shiftL (1 :: Int) ((-1) :: Int)
*** Exception: arithmetic overflow

Should Integer instance also throw an exception?

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information