[commit: ghc] master: Use Data.Functor.Const to implement Data.Data internals (7a2e933)

git at git.haskell.org git at git.haskell.org
Sat Aug 6 15:11:03 UTC 2016


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/7a2e933b77a67d64e80559674852c5a308cde976/ghc

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

commit 7a2e933b77a67d64e80559674852c5a308cde976
Author: Ryan Scott <ryan.gl.scott at gmail.com>
Date:   Sat Aug 6 11:08:31 2016 -0400

    Use Data.Functor.Const to implement Data.Data internals
    
    Summary:
    `Data.Data` uses an internal datatype `CONST`, which can be replaced
    completely by `Const` from `Data.Functor.Const`.
    
    Reviewers: austin, bgamari, hvr
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D2396


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

7a2e933b77a67d64e80559674852c5a308cde976
 libraries/base/Data/Data.hs | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/libraries/base/Data/Data.hs b/libraries/base/Data/Data.hs
index 0e40b17..df37ab1 100644
--- a/libraries/base/Data/Data.hs
+++ b/libraries/base/Data/Data.hs
@@ -114,6 +114,7 @@ module Data.Data (
 
 ------------------------------------------------------------------------------
 
+import Data.Functor.Const
 import Data.Either
 import Data.Eq
 import Data.Maybe
@@ -323,12 +324,12 @@ class Typeable a => Data a where
 
   -- | A generic query with a left-associative binary operator
   gmapQl :: forall r r'. (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r
-  gmapQl o r f = unCONST . gfoldl k z
+  gmapQl o r f = getConst . gfoldl k z
     where
-      k :: Data d => CONST r (d->b) -> d -> CONST r b
-      k c x = CONST $ (unCONST c) `o` f x
-      z :: g -> CONST r g
-      z _   = CONST r
+      k :: Data d => Const r (d->b) -> d -> Const r b
+      k c x = Const $ (getConst c) `o` f x
+      z :: g -> Const r g
+      z _   = Const r
 
   -- | A generic query with a right-associative binary operator
   gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r
@@ -424,10 +425,6 @@ was transformed successfully.
              )
 
 
--- | The constant type constructor needed for the definition of gmapQl
-newtype CONST c a = CONST { unCONST :: c }
-
-
 -- | Type constructor for adding counters to queries
 data Qi q a = Qi Int (Maybe q)
 



More information about the ghc-commits mailing list