[commit: packages/base] master: Add `Data` instance for `Data.Version` (e17549c)

git at git.haskell.org git at git.haskell.org
Fri Sep 13 17:56:58 CEST 2013


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/e17549c80425f3c8a8a672c65bbff00290839f3c/base

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

commit e17549c80425f3c8a8a672c65bbff00290839f3c
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date:   Fri Sep 13 11:19:36 2013 +0200

    Add `Data` instance for `Data.Version`
    
    See also
    
      http://permalink.gmane.org/gmane.comp.lang.haskell.libraries/20269
    
    Patch from Edward Kmett (essentially.)
    
    Authored-by: Edward Kmett <ekmett at gmail.com>
    Signed-off-by: Herbert Valerio Riedel <hvr at gnu.org>


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

e17549c80425f3c8a8a672c65bbff00290839f3c
 Data/Data.hs |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/Data/Data.hs b/Data/Data.hs
index 29760b2..2813886 100644
--- a/Data/Data.hs
+++ b/Data/Data.hs
@@ -110,6 +110,7 @@ import Prelude -- necessary to get dependencies right
 
 import Data.Typeable
 import Data.Maybe
+import Data.Version( Version(..) )
 import Control.Monad
 
 -- Imports for the instances
@@ -1338,3 +1339,20 @@ instance (Typeable a, Data a) => Data (a :=: a) where
                       _ -> error "Data.Data.gunfold(:=:)"
   dataTypeOf _    = equalityDataType
   dataCast2 f     = gcast2 f
+
+-----------------------------------------------------------------------
+-- instance for Data.Version
+
+versionConstr :: Constr
+versionConstr = mkConstr versionDataType "Version" ["versionBranch","versionTags"] Prefix
+
+versionDataType :: DataType
+versionDataType = mkDataType "Data.Version.Version" [versionConstr]
+
+instance Data Version where
+  gfoldl k z (Version bs ts) = z Version `k` bs `k` ts
+  toConstr (Version _ _) = versionConstr
+  gunfold k z c = case constrIndex c of
+                    1 -> k (k (z Version))
+                    _ -> error "Data.Data.gunfold(Version)"
+  dataTypeOf _  = versionDataType




More information about the ghc-commits mailing list