<div dir="ltr">This can be seen with [1,1..2], [1,1..3], etc.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 16, 2016 at 8:10 PM, Kiss Csongor <span dir="ltr"><<a href="mailto:kiss.csongor.kiss@gmail.com" target="_blank">kiss.csongor.kiss@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>The syntax [a, b..c] in general produces a list which starts with “a", followed by “b", going</div><div>up until reaching (possibly including) c in step sizes of (b - a).</div><div>(For simplicity’s sake, I only described non-decreasing lists)</div><div><br></div><div>So it is logical that a step size of 0 produces an infinite list, when [1,1..1] is given.</div><div>Notice that [1,1..1] is not the same as [1..], but "repeat 1”.</div><div><br></div><div>Csongor</div><br><div><blockquote type="cite"><div><div class="h5"><div>On 17 Mar 2016, at 02:58, Krisztian Pinter <<a href="mailto:pin.terminator@gmail.com" target="_blank">pin.terminator@gmail.com</a>> wrote:</div><br></div></div><div><div><div class="h5"><div dir="ltr">Hello,<div><br></div><div>I noticed some odd behaviour with list comprehensions.</div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">[1..1] == [1]</font></div><div>BUT</div><div><font face="monospace, monospace">[1,1..1] == [1..]</font></div><div><br></div><div>I noticed this while writing a Clean program, but it seems Haskell inherited this as well.</div><div>In the case of integer lists with step size >= 0 the <font face="monospace, monospace">up_list</font> function[1] is used:<br></div><div><br></div><div><div><font face="monospace, monospace">up_list :: Integer -> Integer -> Integer -> [Integer]</font></div><div><font face="monospace, monospace">up_list x0 delta lim = go (x0 :: Integer)</font></div><div><font face="monospace, monospace">                    where</font></div><div><font face="monospace, monospace">                        go x | x > lim   = []</font></div><div><font face="monospace, monospace">                             | otherwise = x : go (x+delta)</font></div></div><div><br></div><div>In the case of [1,1..1] x0 == lim, so <font face="monospace, monospace">go</font> will recurse infinitely, producing an infinite list.</div><div><br></div><div>I think the reasonable behaviour would be <font face="monospace, monospace">[1,1..1] == [1]</font>. Is there a reason it doesn't work like this?</div><div><br></div><div>[1] <a href="http://hackage.haskell.org/package/base-4.8.2.0/docs/src/GHC.Enum.html#up_list" target="_blank">http://hackage.haskell.org/package/base-4.8.2.0/docs/src/GHC.Enum.html#up_list</a></div><div><br></div><div>Thanks,</div><div>Krisztián</div></div></div></div>
_______________________________________________<br>Haskell-Cafe mailing list<br><a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br></div></blockquote></div><br></div><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>