<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>
<div class="gmail_quote">On Jun 1, 2015 12:41 PM, "Nikita Karetnikov" <<a href="mailto:nikita@karetnikov.org">nikita@karetnikov.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;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>
<br>
<a href="https://hackage.haskell.org/package/base-4.8.0.0/docs/src/GHC-Real.html" target="_blank">https://hackage.haskell.org/package/base-4.8.0.0/docs/src/GHC-Real.html</a><br>
<br>
Note, however, that there is a case when quot and div result in an<br>
arithmetic overflow:<br>
<br>
Prelude> (minBound :: Int) `quot` (-1)<br>
*** Exception: arithmetic overflow<br>
Prelude> (minBound :: Int) `div` (-1)<br>
*** Exception: arithmetic overflow<br>
<br>
while rem and mod don't:<br>
<br>
Prelude> (minBound :: Int) `rem` (-1)<br>
0<br>
Prelude> (minBound :: Int) `mod` (-1)<br>
0<br>
<br>
Is this a mistake?<br>
<br>
For the record, I'm aware of the safeint package, which raises the error<br>
for rem and mod, and this ticket:<br>
<br>
<a href="https://ghc.haskell.org/trac/ghc/ticket/8695" target="_blank">https://ghc.haskell.org/trac/ghc/ticket/8695</a><br>
_______________________________________________<br>
Glasgow-haskell-users mailing list<br>
<a href="mailto:Glasgow-haskell-users@haskell.org">Glasgow-haskell-users@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users</a><br>
</blockquote></div>