When evaluating the expression:
*main> [0, 0.1 .. 1]
I was actually expecting:
[0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]
But I was quite shocked to see the output be
[0.0,0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001,0.6000000000000001,0.7000000000000001,0.8,0.9,1.0]
Why does Haskell produce that result upon evaluation?
Refer to this other post. As it states, floating point numbers aren't precise in the CPU.
This is a result of the imprecision of floating point values, it isn't particular to Haskell. If you can't deal with the approximation inherent in floating point then you can use Rational at a high performance cost:
Just to hammer the point home, here's Python:
And here's C: