[Haskell-cafe] Why does "enumFromThenTo x x y" depend on "y"?

Clinton Mead clintonmead at gmail.com
Fri Mar 24 03:27:09 UTC 2017


I'm implementing Enum for a type I have, and I figured it should replicate
what ordinary Enum types, so I did some tests on how Enum behaves.

I noticed that:

"enumFromThenTo 3 3 5" is not the same as "enumFromThenTo 3 3 1".

This seems bizarre to me. Generally increasing the stepsize increases the
length of the list.

For example,

"length (enumFromThenTo 0 10 1000) == 101"
"length (enumFromThenTo 0 2 1000) == 501"
"length (enumFromThenTo 0 1 1000) == 1001"
"length (enumFromThenTo 0 0 1000) == infinite"

but

"length (enumFromThenTo 0 (-10) (-1000)) == 101"
"length (enumFromThenTo 0 (-2) (-1000)) == 501"
"length (enumFromThenTo 0 (-1) (-1000)) == 1001"
"length (enumFromThenTo 0 0 1000) == 0"

It would seem to me that "enumFromThenTo x y z == map negate
(enumFromThenTo (-x) (-y) (-z))" should be an invariant that should hold
but in this case it clearly doesn't.

Is this intentional, and if so, for what reason? Or is this a GHC bug?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170324/ef37d181/attachment.html>


More information about the Haskell-Cafe mailing list