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

Chris Smith cdsmith at gmail.com
Tue Sep 20 16:59:07 CEST 2011

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.

I'm not sure where you read that "Enum is supposed to enumerate every
value between the two points".  It's not in the API documentation, and I
don't see it in the Haskell Report.

The better way to look at this is that the notion of `succ` and `pred`
is dependent on the type, much like `mappend` has no particular meaning
until a Monoid instance is given for the type.  It's fairly well
established, though undocumented, that Num types ought to have succ =
(+1) and pred = (subtract 1), so if your fixed point type doesn't do
that, I'd suggest it is the problematic part of this.

It would be a shame if we lost an occasionally useful and easy to read
language feature because of concerns with the disadvantages of some
hypothetical bad implementation.

> Is there any support for the idea of removing Enum instances for
> floating point numbers?

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.


More information about the Haskell-Cafe mailing list