hask icon indicating copy to clipboard operation
hask copied to clipboard

No floating point ranges

Open pya opened this issue 10 years ago • 2 comments

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.

pya avatar Aug 01 '15 19:08 pya

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

billpmurphy avatar Aug 01 '15 22:08 billpmurphy

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

In Haskell: succ 0.1 gives 1.1...

mvaled avatar Jul 18 '18 15:07 mvaled