<div dir="ltr">The current behavior is quite intentional.<br><div><br>On Mon, Jun 1, 2015 at 1:23 PM, David Feuer <span dir="ltr"><<a href="mailto:david.feuer@gmail.com" target="_blank">david.feuer@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><p dir="ltr">I think this is a mistake, yes. They should not raise such exceptions, but rather just wrap around—minBound `quot` (-1) should be -minBound=minBound. That would justify the behavior of rem and mod, and makes much more sense than the current behavior for Int as a ring.</p></blockquote><div>Well, div has no relation to any ring operation of Int at all. It relies on a particular choice of representatives for the equivalence classes that the members of Int-as-a-ring are, and the ring operations do not depend on the choice of representatives. For example Int and Word are isomorphic as rings, but have different div operations when identified under this isomorphism.<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class="h5">
<div class="gmail_quote">On Jun 1, 2015 12:41 PM, "Nikita Karetnikov" <<a href="mailto:nikita@karetnikov.org" target="_blank">nikita@karetnikov.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">According to the documentation, rem and mod must satisfy the following<br>
laws:<br>
<br>
    -- > (x `quot` y)*y + (x `rem` y) == x<br>
    rem<br>
<br>
    -- > (x `div` y)*y + (x `mod` y) == x<br>
    mod<br></blockquote></div></div></div></blockquote><div><br></div><div>The real law that defines the behavior of `div` on Int, though, is (the uglier to write in Haskell)<br><br></div><div>    toInteger (x `div` y) * toInteger y + toInteger (x `mod` y) == toInteger x<br><br></div><div>together with the conditions that x `mod` y has the same sign as y and |x `mod` y| < |y| (here again |n| = abs (toInteger n)).<br><br></div><div>With the condition that (x `div` y) * y + (x `mod` y) == x interpreted only as an equality of Ints, that is, as an equality mod (say) 2^64, there's no reason why we couldn't have for example<br><br></div><div>    1 `mod` 3 = 0, 1 `div` 3 = 12297829382473034411    -- (2*2^64+1)/3<br><br></div><div>so the equality of Integers is really needed.<br><br></div><div>When x = minBound :: Int and y = -1, the integers that would satisfy the div/mod law are -x and 0. I'm not sure whether you are intending to suggest that x `div` y be defined (as minBound :: Int), or that x `mod` y raise an exception. But given we should have toInteger (x `div` y) = -toInteger (minBound :: Int), toInteger (x `mod` y) = 0, setting x `div` y = _|_, x `mod` y = 0 is the most sensible definition.<br><br></div><div>If the objection is that since x `div` y is _|_, then so too should be x `mod` y, because of the law (x `div` y)*y + (x `mod` y) == x, I don't think that follows. After all the law is already violated as written when y = 0 since x `div` 0 and x `mod` 0 are both _|_, so the equation takes the form _|_ + _|_ == x. I don't think it is a worse violation of the law to have _|_ + 0 == x when x = minBound and y = -1.<br></div><div><br></div><div>Regards,<br></div><div>Reid Barton<br></div></div></div></div></div>