<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">The syntax [a, b..c] in general produces a list which starts with “a", followed by “b", going</div><div class="">up until reaching (possibly including) c in step sizes of (b - a).</div><div class="">(For simplicity’s sake, I only described non-decreasing lists)</div><div class=""><br class=""></div><div class="">So it is logical that a step size of 0 produces an infinite list, when [1,1..1] is given.</div><div class="">Notice that [1,1..1] is not the same as [1..], but "repeat 1”.</div><div class=""><br class=""></div><div class="">Csongor</div><br class=""><div><blockquote type="cite" class=""><div class="">On 17 Mar 2016, at 02:58, Krisztian Pinter <<a href="mailto:pin.terminator@gmail.com" class="">pin.terminator@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hello,<div class=""><br class=""></div><div class="">I noticed some odd behaviour with list comprehensions.</div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class="">[1..1] == [1]</font></div><div class="">BUT</div><div class=""><font face="monospace, monospace" class="">[1,1..1] == [1..]</font></div><div class=""><br class=""></div><div class="">I noticed this while writing a Clean program, but it seems Haskell inherited this as well.</div><div class="">In the case of integer lists with step size >= 0 the <font face="monospace, monospace" class="">up_list</font> function[1] is used:<br class=""></div><div class=""><br class=""></div><div class=""><div class=""><font face="monospace, monospace" class="">up_list :: Integer -> Integer -> Integer -> [Integer]</font></div><div class=""><font face="monospace, monospace" class="">up_list x0 delta lim = go (x0 :: Integer)</font></div><div class=""><font face="monospace, monospace" class="">                    where</font></div><div class=""><font face="monospace, monospace" class="">                        go x | x > lim   = []</font></div><div class=""><font face="monospace, monospace" class="">                             | otherwise = x : go (x+delta)</font></div></div><div class=""><br class=""></div><div class="">In the case of [1,1..1] x0 == lim, so <font face="monospace, monospace" class="">go</font> will recurse infinitely, producing an infinite list.</div><div class=""><br class=""></div><div class="">I think the reasonable behaviour would be <font face="monospace, monospace" class="">[1,1..1] == [1]</font>. Is there a reason it doesn't work like this?</div><div class=""><br class=""></div><div class="">[1] <a href="http://hackage.haskell.org/package/base-4.8.2.0/docs/src/GHC.Enum.html#up_list" target="_blank" class="">http://hackage.haskell.org/package/base-4.8.2.0/docs/src/GHC.Enum.html#up_list</a></div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Krisztián</div></div>
_______________________________________________<br class="">Haskell-Cafe mailing list<br class=""><a href="mailto:Haskell-Cafe@haskell.org" class="">Haskell-Cafe@haskell.org</a><br class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe<br class=""></div></blockquote></div><br class=""></body></html>