on master help sign in
Add a Data instance for lazy Text.
8b5710bBryan O'Sullivan
Data/Text/Lazy.hs+17−1
@@ -167,7 +167,7 @@ module Data.Text.Lazy
167import Prelude (Char, Bool(..), Maybe(..), String,
167import Prelude (Char, Bool(..), Maybe(..), String,
168 Eq(..), Ord(..), Read(..), Show(..),
168 Eq(..), Ord(..), Read(..), Show(..),
169 (&&), (+), (-), (.), ($), (++),
169 (&&), (+), (-), (.), ($), (++),
170− div, flip, fromIntegral, not, otherwise)
170+ div, error, flip, fromIntegral, not, otherwise)
171import qualified Prelude as P
171import qualified Prelude as P
172#if defined(HAVE_DEEPSEQ)
172#if defined(HAVE_DEEPSEQ)
173import Control.DeepSeq (NFData(..))
173import Control.DeepSeq (NFData(..))
@@ -175,6 +175,12 @@ import Control.DeepSeq (NFData(..))
175import Data.Int (Int64)
175import Data.Int (Int64)
176import qualified Data.List as L
176import qualified Data.List as L
177import Data.Char (isSpace)
177import Data.Char (isSpace)
178+import Data.Data (Data(gfoldl, toConstr, gunfold, dataTypeOf))
179+#if __GLASGOW_HASKELL__ >= 612
180+import Data.Data (mkNoRepType)
181+#else
182+import Data.Data (mkNorepType)
183+#endif
178import Data.Monoid (Monoid(..))
184import Data.Monoid (Monoid(..))
179import Data.String (IsString(..))
185import Data.String (IsString(..))
180import qualified Data.Text as T
186import qualified Data.Text as T
@@ -216,6 +222,16 @@ instance NFData Text where
216 rnf (Chunk _ ts) = rnf ts
222 rnf (Chunk _ ts) = rnf ts
217#endif
223#endif
218
224
225+instance Data Text where
226+ gfoldl f z txt = z pack `f` (unpack txt)
227+ toConstr _ = error "Data.Text.Lazy.Text.toConstr"
228+ gunfold _ _ = error "Data.Text.Lazy.Text.gunfold"
229+#if __GLASGOW_HASKELL__ >= 612
230+ dataTypeOf _ = mkNoRepType "Data.Text.Lazy.Text"
231+#else
232+ dataTypeOf _ = mkNorepType "Data.Text.Lazy.Text"
233+#endif
234+
219-- | /O(n)/ Convert a 'String' into a 'Text'.
235-- | /O(n)/ Convert a 'String' into a 'Text'.
220--
236--
221-- This function is subject to array fusion.
237-- This function is subject to array fusion.