Overflow in Ratio

David Benbennick dbenbenn at gmail.com
Sun Jul 22 12:32:11 EDT 2007

On 7/22/07, Ian Lynagh <igloo at earth.li> wrote:
> * This would give different behaviour to what the Haskell 98 report
>   specifies

As I said earlier, the Report is self-contradictory on this issue, so
it's not entirely well-defined what the Report specifies.

> * This would give unexpected behaviour if the Ord or Num instance
>   for your ratio type don't match those for Integer

I don't understand this comment.  Could you clarify?

> I think we just have to accept that anything involving Int has these
> sorts of problems.
> For example, you could equally say that
> x > 0 => y + x > y
> should hold, but it doesn't due to Int wrapping.

Well, the question is what properties can you achieve, and what
properties are not achievable?  You're right that "x > 0 => y + x > y"
is not achievable for Ratio Int, but the documentation doesn't assert
that property anywhere, and no one would reasonably expect that
property, since it isn't possible.

On the other hand, it IS possible to achieve the property that "a < b
&& b < c => a < c".  And since the documentation says that Ratio Int
satisfies this property, it is entirely reasonable to expect that it
actually does.

More information about the Libraries mailing list