@@ -202,8 +202,8 @@ import Control.DeepSeq (NFData)
202import Control.Exception (assert)
202import Control.Exception (assert)
204import Data.Char (isSpace)
204import Data.Char (isSpace)
205−import Data.Data (Data(gfoldl, toConstr, gunfold, dataTypeOf))
205+import Data.Data (Data(gfoldl, toConstr, gunfold, dataTypeOf), constrIndex,
206−import Data.Data (mkNoRepType)
206+ Constr, mkConstr, DataType, mkDataType, Fixity(Prefix))
207import Control.Monad (foldM)
207import Control.Monad (foldM)
208import qualified Data.Text.Array as A
208import qualified Data.Text.Array as A
209import qualified Data.List as L
209import qualified Data.List as L
@@ -335,20 +335,31 @@ instance NFData Text
335-- | This instance preserves data abstraction at the cost of inefficiency.
335-- | This instance preserves data abstraction at the cost of inefficiency.
336-- We omit reflection services for the sake of data abstraction.
336-- We omit reflection services for the sake of data abstraction.
338−-- This instance was created by copying the behavior of Data.Set and
338+-- This instance was created by copying the updated behavior of @Data.Set@ and
339−-- Data.Map. If you feel a mistake has been made, please feel free to
339+-- @Data.Map@. If you feel a mistake has been made, please feel free to
340-- submit improvements.
340-- submit improvements.
342-- Original discussion is archived here:
342-- Original discussion is archived here:
344−-- "could we get a Data instance for Data.Text.Text?"
345−-- http://groups.google.com/group/haskell-cafe/browse_thread/thread/b5bbb1b28a7e525d/0639d46852575b93
344+-- <http://groups.google.com/group/haskell-cafe/browse_thread/thread/b5bbb1b28a7e525d/0639d46852575b93 could we get a Data instance for Data.Text.Text?>
346+-- The followup discussion that changed the behavior of @Data.Set@ and @Data.Map@ is archived here
348+-- <http://markmail.org/message/trovdc6zkphyi3cr#query:+page:1+mid:a46der3iacwjcf6n+state:results Proposal: Allow gunfold for Data.Map, ...>
347instance Data Text where
350instance Data Text where
348 gfoldl f z txt = z pack `f` (unpack txt)
351 gfoldl f z txt = z pack `f` (unpack txt)
349− toConstr _ = P.error "Data.Text.Text.toConstr"
352+ toConstr _ = packConstr
353+ gunfold k z c = case constrIndex c of
350− gunfold _ _ = P.error "Data.Text.Text.gunfold"
355+ _ -> P.error "gunfold"
351− dataTypeOf _ = mkNoRepType "Data.Text.Text"
356+ dataTypeOf _ = textDataType
359+packConstr = mkConstr textDataType "pack" [] Prefix
361+textDataType :: DataType
362+textDataType = mkDataType "Data.Text.Text" [packConstr]
353-- | /O(n)/ Compare two 'Text' values lexicographically.
364-- | /O(n)/ Compare two 'Text' values lexicographically.
354compareText :: Text -> Text -> Ordering
365compareText :: Text -> Text -> Ordering