[Haskell-cafe] Odd list comprehension behaviour

Francesco Ariis fa-ml at ariis.it
Thu Mar 17 03:26:34 UTC 2016


On Thu, Mar 17, 2016 at 03:58:06AM +0100, Krisztian Pinter wrote:
> Hello,
> 
> I noticed some odd behaviour with list comprehensions.
> 
> [1..1] == [1]
> BUT
> [1,1..1] == [1..]

Hello Krisztian,
    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
-F

[1] https://www.haskell.org/onlinereport/basic.html

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160317/330cf87f/attachment.sig>


More information about the Haskell-Cafe mailing list