Hi Mark,
| Prelude> [1.0,0.9..(-1.0)]
| [1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.0999998, -2.38419e-07,
| -0.1, -0.2, -0.3, -0.4, -0.5, -0.6, -0.7, -0.8, -0.9]
| Prelude>
In fact there were suggestions that Float and Double should be removed from
the Enum class altogether because of potentially confusing behaviour in
examples like this. But I don't think it is a bug, just a fact of life
when you're working with floating point numbers. I've found that students
can run into problems like this because they forget that the `real' numbers
that we see in most computer languages don't obey even the simplest of laws
that we expect of the real real numbers in mathematics. I class that I
taught last year were astounded when I mentioned that floating point
addition
wasn't associative; they had seen so many lecturers talking about
associativity,
and had thought the law so `obvious' that they hadn't given it any serious
consideration.
Of course it's irritatiting, especially if you're not really interested in
teaching people about numerical methods. But it can also be quite
instructive
to look at examples like this, and to figure out what happened to the 0.1,
0.0,
and -1.0 values, and to compare this with other ways that you might like to
compute the same list:
map (/10) [10, 9 .. -10]
take 21 [1.0, 0.9 .. -1.0]
All the best,
Mark