# [Haskell-cafe] Odd list comprehension behaviour

Jesse Frankley number.dot.ten at gmail.com
Thu Mar 17 03:13:46 UTC 2016

```This can be seen with [1,1..2], [1,1..3], etc.

On Wed, Mar 16, 2016 at 8:10 PM, Kiss Csongor <kiss.csongor.kiss at gmail.com>
wrote:

> The syntax [a, b..c] in general produces a list which starts with “a",
> followed by “b", going
> up until reaching (possibly including) c in step sizes of (b - a).
> (For simplicity’s sake, I only described non-decreasing lists)
>
> So it is logical that a step size of 0 produces an infinite list, when
> [1,1..1] is given.
> Notice that [1,1..1] is not the same as [1..], but "repeat 1”.
>
> Csongor
>
> On 17 Mar 2016, at 02:58, Krisztian Pinter <pin.terminator at gmail.com>
> wrote:
>
> Hello,
>
> I noticed some odd behaviour with list comprehensions.
>
> [1..1] == 
> BUT
> [1,1..1] == [1..]
>
> I noticed this while writing a Clean program, but it seems Haskell
> inherited this as well.
> In the case of integer lists with step size >= 0 the up_list function
> is used:
>
> up_list :: Integer -> Integer -> Integer -> [Integer]
> up_list x0 delta lim = go (x0 :: Integer)
>                     where
>                         go x | x > lim   = []
>                              | otherwise = x : go (x+delta)
>
> In the case of [1,1..1] x0 == lim, so go will recurse infinitely,
> producing an infinite list.
>
> I think the reasonable behaviour would be [1,1..1] == . Is there a
> reason it doesn't work like this?
>
> 
>
> Thanks,
> Krisztián
> _______________________________________________
>
>
>
> _______________________________________________