Deprecating fromIntegral
dominic at steinitz.org
dominic at steinitz.org
Fri Sep 22 12:45:00 UTC 2017
> On 22 Sep 2017, at 13:43, Dominic <dominic.steinitz at blueyonder.co.uk> wrote:
>
> Coincidentally, I was playing with this a few days ago. I didn’t seem to have to do anything to get a warning.
>
>> GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
>> Prelude Data.Word> :m Data.Int
>> Prelude Data.Int> 0x80000000 :: Int32
>>
>> <interactive>:27:1: warning: [-Woverflowed-literals]
>> Literal 2147483648 is out of the Int32 range -2147483648..2147483647
>> If you are trying to write a large negative literal, use NegativeLiterals
>> -2147483648
>> Prelude Data.Int> :set -XNegativeLiterals
>> Prelude Data.Int> 0x80000000 :: Int32
>>
>> <interactive>:29:1: warning: [-Woverflowed-literals]
>> Literal 2147483648 is out of the Int32 range -2147483648..2147483647
>> -2147483648
>
> I am not clear why it wanted me to use NegativeLiterals but still give the same warning. Does anyone understand the intent here?
>
>> Message: 1
>> Date: Fri, 22 Sep 2017 14:14:12 +0200
>> From: Herbert Valerio Riedel <hvriedel at gmail.com>
>> To: Niklas Hambüchen <mail at nh2.me>
>> Cc: Haskell Libraries <libraries at haskell.org>
>> Subject: Re: Deprecating fromIntegral
>> Message-ID:
>> <CAOFsArv1rDT1=KsM_z1vDOf_CW-jamOT8nzGzHk3VnxuEvjMug at mail.gmail.com>
>> Content-Type: text/plain; charset="UTF-8"
>>
>> ...there's one minor detail I'd like to point out as it doesn't seem
>> to have been mentioned so far:
>>
>> On Thu, Sep 21, 2017 at 5:34 PM, Niklas Hambüchen <mail at nh2.me> wrote:
>>
>>> (Though, in practice the current `fromInteger is not partial, e.g.
>>> `(fromInteger 256 :: Word8) == 0` without error
>>
>> That's true. However, here's something you can do already now with
>> recent GHCs which gives turns literal-overflows GHC is able to detect into
>> hard compile errors:
>>
>>
>> $ ghci -Wall -Werror=overflowed-literals
>> GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help
>> Prelude> (256 :: Data.Word.Word8) == 0
>>
>> <interactive>:1:2: warning: [-Woverflowed-literals]
>> Literal 256 is out of the GHC.Word.Word8 range 0..255
>>
>> <no location info>: error:
>> Failing due to -Werror.
>> Prelude>
>>
>>
>> ------------------------------
>>
>> Subject: Digest Footer
>>
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>
>>
>> ------------------------------
>>
>> End of Libraries Digest, Vol 169, Issue 30
>> ******************************************
>
Dominic Steinitz
dominic at steinitz.org
http://idontgetoutmuch.wordpress.com
More information about the Libraries
mailing list