Overflow in Ratio
dbenbenn at gmail.com
Sun Jul 22 11:49:30 EDT 2007
On 7/22/07, haskell at list.mightyreason.com <haskell at list.mightyreason.com> wrote:
> I am going to take a guess and say that the library policy is that (Num Integer)
> and (Ratio Integer) are known to follow the axioms, but anyone who uses
> (Num Int) and (Ratio Int) did so to get the size and performance and does not
> want to cast to Integer.
The current implementation of < for Ratio Int is no better than a coin
flip. That is, if you take two elements of Ratio Int at random and
compare them with <, the answer will be right 50% of the time, and
wrong 50% of the time. I would assume that if someone is comparing
two elements of Ratio Int with <, they're doing so because they want
the right answer. If they don't care what answer they get, they can
just assume True and be even more efficient.
Also, I don't think it's generally well known that the overflow
problems are as bad as they are. For example, the documentation at
doesn't include any warnings that Ratio Int doesn't obey the
documented behavior of Ord.
More information about the Libraries