[commit: bytestring] master: Add proper Data class instances that actually contain the data. (70e24a2)
Ian Lynagh
igloo at earth.li
Wed Feb 22 21:57:24 CET 2012
Repository : ssh://darcs.haskell.org//srv/darcs/packages/bytestring
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/70e24a2039239eb99ff4db364070f78191655bd1
>---------------------------------------------------------------
commit 70e24a2039239eb99ff4db364070f78191655bd1
Author: Duncan Coutts <duncan at community.haskell.org>
Date: Sun Nov 6 17:57:37 2011 +0000
Add proper Data class instances that actually contain the data.
Same style as instances for Data.Text.
>---------------------------------------------------------------
Data/ByteString/Internal.hs | 26 +++++++++++++++++++++-----
Data/ByteString/Lazy/Internal.hs | 25 +++++++++++++++++++------
2 files changed, 40 insertions(+), 11 deletions(-)
diff --git a/Data/ByteString/Internal.hs b/Data/ByteString/Internal.hs
index 9f7eb16..1c66d53 100644
--- a/Data/ByteString/Internal.hs
+++ b/Data/ByteString/Internal.hs
@@ -88,13 +88,19 @@ import Control.Exception (assert)
import Data.Char (ord)
import Data.Word (Word8)
-#if defined(__GLASGOW_HASKELL__)
import Data.Typeable (Typeable)
-#if __GLASGOW_HASKELL__ >= 610
-import Data.Data (Data)
+#if MIN_VERSION_base(4,1,0)
+import Data.Data (Data(..))
+#if MIN_VERSION_base(4,2,0)
+import Data.Data (mkNoRepType)
+#else
+import Data.Data (mkNorepType)
+#endif
#else
-import Data.Generics (Data)
+import Data.Generics (Data(..), mkNorepType)
#endif
+
+#ifdef __GLASGOW_HASKELL__
import GHC.Base (realWorld#,unsafeChr)
#if __GLASGOW_HASKELL__ >= 611
import GHC.IO (IO(IO))
@@ -164,7 +170,7 @@ data ByteString = PS {-# UNPACK #-} !(ForeignPtr Word8) -- payload
{-# UNPACK #-} !Int -- length
#if defined(__GLASGOW_HASKELL__)
- deriving (Data, Typeable)
+ deriving (Typeable)
#endif
instance NFData ByteString
@@ -175,6 +181,16 @@ instance Show ByteString where
instance Read ByteString where
readsPrec p str = [ (packChars x, y) | (x, y) <- readsPrec p str ]
+instance Data ByteString where
+ gfoldl f z txt = z packBytes `f` (unpackBytes txt)
+ toConstr _ = error "Data.ByteString.ByteString.toConstr"
+ gunfold _ _ = error "Data.ByteString.ByteString.gunfold"
+#if __GLASGOW_HASKELL__ >= 612
+ dataTypeOf _ = mkNoRepType "Data.ByteString.ByteString"
+#else
+ dataTypeOf _ = mkNorepType "Data.ByteString.ByteString"
+#endif
+
------------------------------------------------------------------------
-- Packing and unpacking from lists
diff --git a/Data/ByteString/Lazy/Internal.hs b/Data/ByteString/Lazy/Internal.hs
index 356b670..fddfd45 100644
--- a/Data/ByteString/Lazy/Internal.hs
+++ b/Data/ByteString/Lazy/Internal.hs
@@ -47,13 +47,16 @@ import Foreign.Storable (Storable(sizeOf))
import Control.DeepSeq (NFData, rnf)
-#if defined(__GLASGOW_HASKELL__)
-import Data.Typeable (Typeable)
-#if __GLASGOW_HASKELL__ >= 610
-import Data.Data (Data)
+import Data.Typeable (Typeable)
+#if MIN_VERSION_base(4,1,0)
+import Data.Data (Data(..))
+#if MIN_VERSION_base(4,2,0)
+import Data.Data (mkNoRepType)
#else
-import Data.Generics (Data)
+import Data.Data (mkNorepType)
#endif
+#else
+import Data.Generics (Data(..), mkNorepType)
#endif
-- | A space-efficient representation of a Word8 vector, supporting many
@@ -64,7 +67,7 @@ import Data.Generics (Data)
data ByteString = Empty | Chunk {-# UNPACK #-} !S.ByteString ByteString
#if defined(__GLASGOW_HASKELL__)
- deriving (Data, Typeable)
+ deriving (Typeable)
#endif
instance NFData ByteString where
@@ -77,6 +80,16 @@ instance Show ByteString where
instance Read ByteString where
readsPrec p str = [ (packChars x, y) | (x, y) <- readsPrec p str ]
+instance Data ByteString where
+ gfoldl f z txt = z packBytes `f` unpackBytes txt
+ toConstr _ = error "Data.ByteString.Lazy.ByteString.toConstr"
+ gunfold _ _ = error "Data.ByteString.Lazy.ByteString.gunfold"
+#if MIN_VERSION_base(4,2,0)
+ dataTypeOf _ = mkNoRepType "Data.ByteString.Lazy.ByteString"
+#else
+ dataTypeOf _ = mkNorepType "Data.ByteString.Lazy.ByteString"
+#endif
+
------------------------------------------------------------------------
-- Packing and unpacking from lists
More information about the Cvs-libraries
mailing list