Skip to content

Ratio is dangerous

From https://www.fpcomplete.com/blog/hidden-dangers-of-ratio/:

λ> let r = 1 % 12 :: Ratio Int8 in r - r == 0
False

Eek! The problem is that subtraction of Ratios multiplies the two denominators, and 12 * 12 overflows, leading to a negative denominator, and thence chaos. Read the blog post.

One possible fix is to normalize more aggressively. Another is to document this infelicity carefully: there's no way I can predict, reading the documentation, that 1 % 12 - 1 % 12 multiplies the two 12s. (It might find the least common multiple of 12 and 12, for example.) I don't much care which solution is adopted, but I agree that the status quo is... surprising.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information