[Haskell-cafe] [m..n] question

Evan Laforge qdunkan at gmail.com
Sun Sep 21 21:51:24 EDT 2008

> In Haskell,
> "The sequence enumFromTo e1 e3 is the list [e1,e1+1,e1+2,...e3].
>  The list is empty if e1 > e3."

I like it, since it means that things like [n .. n + length m - 1]
work as expected when m is [].  Or say 'map (array!) [bsearch x ..
bsearch y - 1]'.

Tangent:  Of course, I would prefer the range be half-open, which is a
pretty consistent standard in the rest of the world.  I've had a
number of off by one errors from this, and from Array.bounds.  I guess
it's too late to fix those, though, even if there were agreement that
they need to be fixed.

This is similar to the way python considers that xs[4:2] is valid, and
is [].  Of course python uses half-open ranges so xs[4:4] is still [].

More information about the Haskell-Cafe mailing list