billpmurphy/hask

No floating point ranges

Opened this issue · 2 comments

pya commented

Haskell allows floating point ranges:

Prelude> [0.1, 0.2 .. 0.5]
[0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001]

This does not work in Hask:

>>> L[0.1, 0.2, ..., 0.5]
TypeError Traceback (most recent call last)
....
TypeError: No instance for 0.1

Because floating point ranges are tricky:

Prelude> [0.1, 0.3 .. 1]
[0.1,0.3,0.5,0.7,0.8999999999999999,1.0999999999999999]

it might not be a good idea to implement them at all. In this case a more descriptive error message or even a own, new exception type might be helpful.

Good catch. I'd say float should probably be an instance of Enum, as it is in Haskell.

But which is the smallest "increment", i.e. how to implement succ?

In Haskell: succ 0.1 gives 1.1...