summaryrefslogtreecommitdiff
path: root/libraries/base/Data/Data.hs
diff options
context:
space:
mode:
authorHerbert Valerio Riedel <hvr@gnu.org>2015-01-21 08:21:36 +0100
committerHerbert Valerio Riedel <hvr@gnu.org>2015-01-22 22:36:24 +0100
commit3df429e29b6fabda12af71091ba4ad1360f49b44 (patch)
tree3fece93d426fbcd1d9e778d1f086318654a57839 /libraries/base/Data/Data.hs
parente6756640bb410258837d186e8c2e339d6746dc11 (diff)
downloadhaskell-3df429e29b6fabda12af71091ba4ad1360f49b44.tar.gz
Restore invariant in `Data (Ratio a)` instance
(2nd attempt, this time leaving the `Constr` using `":%"`) The Data instance for `Ratio` just uses the raw `:%` constructor and doesn't check that the result is reduced to normal form. The fix is to add back the `Integral` constraint on the Data instance (which was dropped in c409b6f30373535) and to use `%` rather than `:%` in the `gfoldl` and `gunfold` implementation. This restores the invariant and matches the behavior of "virtual constructors" we've used to patch up such problems elsewhere. This addresses #10011 Reviewed By: ekmett, austin Differential Revision: https://phabricator.haskell.org/D625
Diffstat (limited to 'libraries/base/Data/Data.hs')
-rw-r--r--libraries/base/Data/Data.hs6
1 files changed, 3 insertions, 3 deletions
diff --git a/libraries/base/Data/Data.hs b/libraries/base/Data/Data.hs
index dce610b1d7..6961b250b5 100644
--- a/libraries/base/Data/Data.hs
+++ b/libraries/base/Data/Data.hs
@@ -1064,10 +1064,10 @@ ratioConstr = mkConstr ratioDataType ":%" [] Infix
ratioDataType :: DataType
ratioDataType = mkDataType "GHC.Real.Ratio" [ratioConstr]
-instance Data a => Data (Ratio a) where
- gfoldl k z (a :% b) = z (:%) `k` a `k` b
+instance (Data a, Integral a) => Data (Ratio a) where
+ gfoldl k z (a :% b) = z (%) `k` a `k` b
toConstr _ = ratioConstr
- gunfold k z c | constrIndex c == 1 = k (k (z (:%)))
+ gunfold k z c | constrIndex c == 1 = k (k (z (%)))
gunfold _ _ _ = error "Data.Data.gunfold(Ratio)"
dataTypeOf _ = ratioDataType