
19 Sep
2014
19 Sep
'14
9:58 a.m.
The Monoid instances for Sum and Product do not respect the Monoid laws. The instances are: Num a => instance Monoid (Sum a) Num a => instance Monoid (Product a) Float and Double are instances of the Num typeclass, however, floating point addition and multiplication are not associative. Here's an example:
(Sum 1234.567 `mappend` Sum 45.67834) `mappend` Sum 0.0004 Sum {getSum = 1280.2457399999998}
Sum 1234.567 `mappend` (Sum 45.67834 `mappend` Sum 0.0004) Sum {getSum = 1280.24574}
Shouldn't these instances be constrained to Integral types? Jason