<div dir="ltr">This behaviour follows directly from the language report [1]:<div><ul class="gmail-itemize1" style="color:rgb(0,0,0);font-family:"times new roman";font-size:medium"><li class="gmail-itemize">The sequence <span class="gmail-pcrr7t-" style="font-family:monospace">enumFromThenTo</span><span class="gmail-cmmi-10" style="font-style:italic"> e</span><sub style="font-size:16px"><span class="gmail-cmr-7" style="font-size:11.2px">1</span></sub><span class="gmail-cmmi-10" style="font-style:italic"> e</span><sub style="font-size:16px"><span class="gmail-cmr-7" style="font-size:11.2px">2</span></sub><span class="gmail-cmmi-10" style="font-style:italic"> e</span><sub style="font-size:16px"><span class="gmail-cmr-7" style="font-size:11.2px">3</span></sub> is the list <span class="gmail-pcrr7t-" style="font-family:monospace">[</span><span class="gmail-cmmi-10" style="font-style:italic">e</span><sub style="font-size:16px"><span class="gmail-cmr-7" style="font-size:11.2px">1</span></sub><span class="gmail-pcrr7t-" style="font-family:monospace">,</span><span class="gmail-cmmi-10" style="font-style:italic">e</span><sub style="font-size:16px"><span class="gmail-cmr-7" style="font-size:11.2px">1</span></sub> <span class="gmail-cmr-10">+ </span><span class="gmail-cmmi-10" style="font-style:italic">i</span><span class="gmail-pcrr7t-" style="font-family:monospace">,</span><span class="gmail-cmmi-10" style="font-style:italic">e</span><sub style="font-size:16px"><span class="gmail-cmr-7" style="font-size:11.2px">1</span></sub> <span class="gmail-cmr-10">+ 2</span><span class="gmail-cmmi-10" style="font-style:italic">i</span><span class="gmail-pcrr7t-" style="font-family:monospace">,</span><span class="gmail-cmmi-10" style="font-style:italic">…</span><span class="gmail-cmmi-10" style="font-style:italic">e</span><sub style="font-size:16px"><span class="gmail-cmr-7" style="font-size:11.2px">3</span></sub><span class="gmail-pcrr7t-" style="font-family:monospace">]</span>, where the increment, <span class="gmail-cmmi-10" style="font-style:italic">i</span>, is <span class="gmail-cmmi-10" style="font-style:italic">e</span><sub style="font-size:16px"><span class="gmail-cmr-7" style="font-size:11.2px">2</span></sub> <span class="gmail-cmsy-10">− </span><span class="gmail-cmmi-10" style="font-style:italic">e</span><sub style="font-size:16px"><span class="gmail-cmr-7" style="font-size:11.2px">1</span></sub>. If the increment is positive or zero, the list terminates when the next element would be greater than <span class="gmail-cmmi-10" style="font-style:italic">e</span><sub style="font-size:16px"><span class="gmail-cmr-7" style="font-size:11.2px">3</span></sub>; the list is empty if <span class="gmail-cmmi-10" style="font-style:italic">e</span><sub style="font-size:16px"><span class="gmail-cmr-7" style="font-size:11.2px">1</span></sub><span class="gmail-cmmi-10" style="font-style:italic"> ></span> <span class="gmail-cmmi-10" style="font-style:italic"> e</span><sub style="font-size:16px"><span class="gmail-cmr-7" style="font-size:11.2px">3</span></sub>. If the increment is negative, the list terminates when the next element would be less than <span class="gmail-cmmi-10" style="font-style:italic">e</span><sub style="font-size:16px"><span class="gmail-cmr-7" style="font-size:11.2px">3</span></sub>; the list is empty if <span class="gmail-cmmi-10" style="font-style:italic">e</span><span class="gmail-cmr-10">1</span><span class="gmail-cmmi-10" style="font-style:italic"> <</span> <span class="gmail-cmmi-10" style="font-style:italic"> e</span><sub style="font-size:16px"><span class="gmail-cmr-7" style="font-size:11.2px">3</span></sub>.</li></ul><div>In both "enumFromThenTo 3 3 5" and "enumFromThenTo 3 3 1" the increment is 0. So the list must terminate when the next element would be greater than 5 or 1 respectively. </div><div>In this first case 3 > 5 == False, so you get an unbounded list. </div><div>In the second case 3 > 1 == True, so you get an empty list.</div><div><br></div><div>The above is only specified for the types Int and Integer.</div><div><br></div><div>It would be nice to have some laws that govern the behaviour of all Enum instances (not just Int and Integer). Not just in relation with the Bounded class.</div><div><br></div><div>1 - <a href="https://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1310006.3.4">https://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1310006.3.4</a><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-03-24 4:27 GMT+01:00 Clinton Mead <span dir="ltr"><<a href="mailto:clintonmead@gmail.com" target="_blank">clintonmead@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm implementing Enum for a type I have, and I figured it should replicate what ordinary Enum types, so I did some tests on how Enum behaves.<br><br>I noticed that:<div><br></div><div>"enumFromThenTo 3 3 5" is not the same as "enumFromThenTo 3 3 1". </div><div><br></div><div>This seems bizarre to me. Generally increasing the stepsize increases the length of the list.</div><div><br></div><div>For example, </div><div><br></div><div>"length (enumFromThenTo 0 10 1000) == 101"</div><div>"length (enumFromThenTo 0 2 1000) == 501"<br></div><div>"length (enumFromThenTo 0 1 1000) == 1001"<br></div><div><div>"length (enumFromThenTo 0 0 1000) == infinite"<br></div></div><div><br></div><div>but</div><div><br></div><div><div>"length (enumFromThenTo 0 (-10) (-1000)) == 101"</div><div>"length (enumFromThenTo 0 (-2) (-1000)) == 501"<br></div><div>"length (enumFromThenTo 0 (-1) (-1000)) == 1001"<br></div><div>"length (enumFromThenTo 0 0 1000) == 0"<br></div></div><div><br></div><div>It would seem to me that "enumFromThenTo x y z == map negate (enumFromThenTo (-x) (-y) (-z))" should be an invariant that should hold but in this case it clearly doesn't. </div><div><br></div><div>Is this intentional, and if so, for what reason? Or is this a GHC bug?</div></div>
<br>______________________________<wbr>_________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/haskell-<wbr>cafe</a><br>
Only members subscribed via the mailman list are allowed to post.<br></blockquote></div><br></div>