[Haskell-cafe] instance Enum Double considered not entirely great?

Richard O'Keefe ok at cs.otago.ac.nz
Wed Sep 21 05:29:39 CEST 2011


On 21/09/2011, at 2:59 AM, Chris Smith wrote:

> On Mon, 2011-09-19 at 22:09 -0700, Evan Laforge wrote:
>> Then I tried switching to a fixed point format, and discovered my
>> mistake.  Enum is supposed to enumerate every value between the two
>> points, and the result is memory exhaustion.

% ghci
Prelude> [1.0..2.0]::[Double]
[1.0,2.0]

(..) for Doubles is using (+1), not nextAfter, and is NOT enumerating
every value between 1.0 and 2.0

> import Ratio
Prelude Ratio> [1%2..7%2] :: [Ratio Int]
[1 % 2,3 % 2,5 % 2,7 % 2]

(..) for (Ratio a) is using (+1), and is NOT enumerating the infinitely
many values between 1.5 and 3.5.

Why should your fixed point format behave any differently?

> I certainly hope not.  Instead, perhaps the issue should be brought up
> with the fixed-point number library you're using, and they could fix
> their Enum instance to be more helpful.

So Chris Smith's response is absolutely right here; the problem is
the fixed-point library implementing enumeration incompatibly with
the built-in numeric types.




More information about the Haskell-Cafe mailing list