In what cases does NegativeLiterals change behavior?
The difference of negative literals is the difference of if we negate the integer then call fromInteger
or call fromInteger
then negate the type of the codomain. That is, fromInteger . negate
is not the same as negate . fromInteger
. I would expect this to happen when you are on the bounds of some type - one might saturate while another wraps.
For example I have a pretty trivially bad type:
data Bad = Bad Integer
deriving (Show)
instance Num Bad where
negate (Bad a) = Bad (a + 1)
fromInteger = Bad
And the result:
*Main> (-1) :: Bad
Bad 2
*Main> :set -XNegativeLiterals
*Main> (-1) :: Bad
Bad (-1)
*Main>