[commit: ghc] master: Define `Data` instance for `Natural` type (#9818) (4bf055c)
git at git.haskell.org
git at git.haskell.org
Wed Nov 26 08:05:07 UTC 2014
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/4bf055c70d07b98be1e7749e0306e406dfbbc006/ghc
>---------------------------------------------------------------
commit 4bf055c70d07b98be1e7749e0306e406dfbbc006
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date: Tue Nov 25 23:23:08 2014 +0100
Define `Data` instance for `Natural` type (#9818)
This follows the same style as the other integral `Data` instances
defined in the `Data.Data` module.
Reviewed By: ekmett
Differential Revision: https://phabricator.haskell.org/D526
>---------------------------------------------------------------
4bf055c70d07b98be1e7749e0306e406dfbbc006
libraries/base/GHC/Natural.hs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/libraries/base/GHC/Natural.hs b/libraries/base/GHC/Natural.hs
index e9b37b1..221bc31 100644
--- a/libraries/base/GHC/Natural.hs
+++ b/libraries/base/GHC/Natural.hs
@@ -67,6 +67,7 @@ import GHC.Enum
import GHC.List
import Data.Bits
+import Data.Data
default ()
@@ -588,3 +589,16 @@ naturalToWordMaybe (Natural i)
where
maxw = toInteger (maxBound :: Word)
#endif
+
+-- This follows the same style as the other integral 'Data' instances
+-- defined in "Data.Data"
+naturalType :: DataType
+naturalType = mkIntType "Numeric.Natural.Natural"
+
+instance Data Natural where
+ toConstr x = mkIntegralConstr naturalType x
+ gunfold _ z c = case constrRep c of
+ (IntConstr x) -> z (fromIntegral x)
+ _ -> error $ "Data.Data.gunfold: Constructor " ++ show c
+ ++ " is not of type Natural"
+ dataTypeOf _ = naturalType
More information about the ghc-commits
mailing list