[Haskell-cafe] instance Enum Double considered not entirely great?

Daniel Fischer daniel.is.fischer at googlemail.com
Tue Sep 20 18:16:05 CEST 2011


On Tuesday 20 September 2011, 17:39:49, Ketil Malde wrote:
> Chris Smith <cdsmith at gmail.com> writes:
> > It would be a shame if we lost an occasionally useful and easy to read
> 
> You forgot "confusing"?  Expecting Enum to enumerate all inhabitants of
> a type seems very reasonable to me, and seems to hold for all
> non-floating point types.

And Rational (more generally, Ratio a). (Why does everybody forget that?)
Enumerating all inhabitants of a type (within some range) is only possible 
if there are well-defined successors and predecessors (modulo bounds).
For Double and Float, there are (excepting NaNs), so it could be done, but 
arguably that would be *far less* useful than the current instances.
For Rational, no such luck.

> A numeric range [a..a+n] might be expected
> to have a+n+1 elements, but that doesn't hold either for Float and
> Double.  I think Enum for floating point values is broken

Yes, it is. Like Eq and Ord.

> - but it is reality, so we need to deal with it.

Like Eq and Ord, it's just too damn convenient to have it.
So much nicer to write [0, 0.25 .. 1000] instead of
numericEnumFromThenTo 0 0.25 1000
and (x /= y) instead of
doublesDifferentOrNaN x y



More information about the Haskell-Cafe mailing list