Skip to content

The Data instance for Ratio violates internal invariants.

I found this when Simon was cleaning up unused dependencies in

https://phabricator.haskell.org/rGHCc409b6f30373535b6eed92e55d4695688d32be9e#10730

The Data instance for Ratio just uses the raw (:%) constructor and doesn't check that the result is reduced to normal form.

It strikes me that the fix is to add back the Integral constraint on the Data instance and to use (%) rather than (:%) in the gfoldl and gunfold code.

This restores the invariant and matches the behavior of "virtual constructors" we've used to patch up such problems elsewhere.

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