[Haskell-cafe] instance Enum Double considered not entirely great?
cdsmith at gmail.com
Fri Sep 23 06:06:58 CEST 2011
On Fri, 2011-09-23 at 11:02 +1200, Richard O'Keefe wrote:
> I do think that '..' syntax for Float and Double could be useful,
> but the actual definition is such that, well, words fail me.
> [1.0..3.5] => [1.0,2.0,3.0,4.0] ???? Why did anyone ever think
> _that_ was a good idea?
In case you meant that as a question, the reason is this:
Prelude> [0.1, 0.2 .. 0.3]
Because of rounding error, an implementation that meets your proposed
law would have left out 0.3 from that sequence, when of course it was
intended to be there. This is messy for the properties you want to
state, but it's almost surely the right thing to do in practice. If the
list is longer, then the most likely way to get it right is to follow
the behavior as currently specified. Of course it's messy, but the
world is a messy place, especially when it comes to floating point
If you can clear this up with a better explanation of the properties,
great! But if you can't, then we ought to reject the kind of thinking
that would remove useful behavior when it doesn't fit some theoretical
properties that looked nice until you consider the edge cases.
More information about the Haskell-Cafe