[commit: ghc] ghc-7.10: Restore invariant in `Data (Ratio a)` instance (dde5561)

git at git.haskell.org git at git.haskell.org
Wed Jan 21 18:32:07 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-7.10
Link       : http://ghc.haskell.org/trac/ghc/changeset/dde5561b77b5b5703ddcd43fd8917a12f9d207e5/ghc

>---------------------------------------------------------------

commit dde5561b77b5b5703ddcd43fd8917a12f9d207e5
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date:   Wed Jan 21 08:21:36 2015 +0100

    Restore invariant in `Data (Ratio a)` instance
    
    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
    
    (cherry picked from commit 79b0d0e633af8302d2dd907663a4a231cd889b67)


>---------------------------------------------------------------

dde5561b77b5b5703ddcd43fd8917a12f9d207e5
 libraries/base/Data/Data.hs | 6 +++---
 libraries/base/changelog.md | 2 ++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/libraries/base/Data/Data.hs b/libraries/base/Data/Data.hs
index 8f1e5f4..2ca3a0c 100644
--- a/libraries/base/Data/Data.hs
+++ b/libraries/base/Data/Data.hs
@@ -1059,15 +1059,15 @@ instance Data Word64 where
 ------------------------------------------------------------------------------
 
 ratioConstr :: Constr
-ratioConstr = mkConstr ratioDataType ":%" [] Infix
+ratioConstr = mkConstr ratioDataType "%" [] Infix
 
 ratioDataType :: DataType
 ratioDataType = mkDataType "GHC.Real.Ratio" [ratioConstr]
 
 instance (Data a, Integral a) => Data (Ratio a) where
-  gfoldl k z (a :% b) = z (:%) `k` a `k` b
+  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
 
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index 83ae5e4..0d7ebcf 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -140,6 +140,8 @@
 
   * Add `callocArray` and `callocArray0` to `Foreign.Marshal.Array`. (#9859)
 
+  * Restore invariant in `Data (Ratio a)` instance (#10011)
+
 ## 4.7.0.2  *Dec 2014*
 
   * Bundled with GHC 7.8.4



More information about the ghc-commits mailing list