[Haskell-cafe] Odd list comprehension behaviour

Manuel Gómez targen at gmail.com
Thu Mar 17 04:27:39 UTC 2016


On Wed, Mar 16, 2016 at 10:56 PM, Francesco Ariis <fa-ml at ariis.it> wrote:
>     from the Haskell report (enumFromThenTo is longhand for [a,b..c]
> notation) [1]:
>
>    The sequence enumFromThenTo e1 e2 e3 is the list [e1,e1+i,e1+2i,...e3],
>    where the increment, i, is e2-e1. If the increment is positive or zero,
>    the list terminates when the next element would be greater than e3; the
>    list is empty if e1 > e3. If the increment is negative, the list
>    terminates when the next element would be less than e3; the list is
>    empty if e1 < e3.
>
> The important bit being "the list terminates when the next element would
> be greater than e3". Unfortunate in my opinion (I agree with you the
> fact that `[1..1] /= [1,1..1]` is puzzling), but specs compliant
>
> [1] https://www.haskell.org/onlinereport/basic.html

I'm not necessarily proposing this, but would it not be also
reasonable for this to read "the list terminates when the current
element equals e3 or the next element would be greater than e3"?  It's
slightly more wordy, but it captures the intuition that [a,b..c] ends
at c.


More information about the Haskell-Cafe mailing list