Unclear explanation of why Float and Double do not have additive identities
Summary
Location of documentation issue: the Haddock comments for the Float
and Double
instances of Num
in GHC.Float (search for the word "additive").
This example gives the impression that -0 :: Float
could be the additive identity. After all,
x + (-0 :: Float) == x || isNaN x
holds for all x :: Float
. Besides, GHCi reports that (-0 :: Float) == 0
holds, as required by the IEEE-754 standard, so they're sometimes considered to be equivalent values.
Wouldn't it be clearer to use the existence of NaN
values to prove that the additive identity doesn't exist? I.e. neither e=0
nor e=(-0 :: Float)
satisfies
let x = (0/0 :: Float) in x + e == x
Proposed improvements or changes
It would be clearer to say:
-- Also note that due to the presence of @NaN@, `Float`'s 'Num' instance doesn't
-- have an additive identity
--
-- >>> let nan = (0/0 :: Float) in nan + 0 == nan
-- False
and to make a similar change to the comment for the Double
instance.
I'd be happy to create a pull request if the relevant developers agree to this change.