We should probably use a Bounded a constraint and make sum terminate if it overflows beyond the bound. Currently overflows give wrong sum silently.
The currentsum can be renamed to sumUnsafe, and can be used if it gives noticeable perf advantage in perf sensitive code.
For Integer type (unbounded) we can have sumInteger. For (Num a, Floating a) we can have a sumFloating. Or we can create an Unbounded type class for such types? And then have a sumUnbounded. To begin with we can just use sumUnsafe for these use cases and leave this as a TODO.
Data.Fold.product
Overflow applies to product as well in the same way as sum.
Data.Fold.minimum (maximum/minimumBy/maximumBy)
minimum/maximum and minimumBy/maximumBy would terminate if the value reached the min/max possible value for the type.
Data.Fold.sum
We should probably use a
Bounded a
constraint and makesum
terminate if it overflows beyond the bound. Currently overflows give wrong sum silently.The current
sum
can be renamed tosumUnsafe
, and can be used if it gives noticeable perf advantage in perf sensitive code.For
Integer
type (unbounded) we can havesumInteger
. For (Num a
,Floating a
) we can have asumFloating
. Or we can create anUnbounded
type class for such types? And then have asumUnbounded
. To begin with we can just usesumUnsafe
for these use cases and leave this as a TODO.Data.Fold.product
Overflow applies to
product
as well in the same way assum
.Data.Fold.minimum (maximum/minimumBy/maximumBy)
minimum/maximum and minimumBy/maximumBy would terminate if the value reached the min/max possible value for the type.