[Haskell-cafe] Odd list comprehension behaviour
targen at gmail.com
Thu Mar 17 06:25:00 UTC 2016
> On 17/03/16 5:27 pm, Manuel Gómez wrote:
> 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.
On Thu, Mar 17, 2016 at 12:18 AM, Richard A. O'Keefe <ok at cs.otago.ac.nz> wrote:
> From experience in other programming languages, I don't have that intuition.
> Indeed, from experience in Haskell, I don't expect [a,b..c] to end at c.
> [1,3..6] ends at 5, not 6.
I apologize — I believe I failed to convey what I tried to say.
Perhaps I should instead have said «ends at c at the furthest».
The intuition I refer to is that c is a possibly included bound for
the list [a,b..c], so that the list [a,b..c] certainly shall not have
any element beyond c, but if it does actually get to c, that’s where
In that sense I find it natural that [1,3..6] ends at 5: otherwise it
would have elements beyond 6, namely 7.
[0,2..6], on the other hand, ends at 6, and indeed does not have any
element beyond 6.
[6,6..6] would have the initial 6, and then it should have no other
element beyond 6, so it should in fact equal  under this intuition.
More information about the Haskell-Cafe