diff --git a/Data/Text.hs b/Data/Text.hs index f5d36b7c20d290553adedb41806a666a0c96e24e..91d3093dc3aabc2f98d3efe0897fc496c8e3f1f6 100644 --- a/Data/Text.hs +++ b/Data/Text.hs @@ -202,8 +202,8 @@ import Control.DeepSeq (NFData) import Control.Exception (assert) #endif import Data.Char (isSpace) -import Data.Data (Data(gfoldl, toConstr, gunfold, dataTypeOf)) -import Data.Data (mkNoRepType) +import Data.Data (Data(gfoldl, toConstr, gunfold, dataTypeOf), constrIndex, + Constr, mkConstr, DataType, mkDataType, Fixity(Prefix)) import Control.Monad (foldM) import qualified Data.Text.Array as A import qualified Data.List as L @@ -335,20 +335,31 @@ instance NFData Text -- | This instance preserves data abstraction at the cost of inefficiency. -- We omit reflection services for the sake of data abstraction. -- --- This instance was created by copying the behavior of Data.Set and --- Data.Map. If you feel a mistake has been made, please feel free to +-- This instance was created by copying the updated behavior of @Data.Set@ and +-- @Data.Map@. If you feel a mistake has been made, please feel free to -- submit improvements. -- -- Original discussion is archived here: -- --- "could we get a Data instance for Data.Text.Text?" --- http://groups.google.com/group/haskell-cafe/browse_thread/thread/b5bbb1b28a7e525d/0639d46852575b93 +-- <http://groups.google.com/group/haskell-cafe/browse_thread/thread/b5bbb1b28a7e525d/0639d46852575b93 could we get a Data instance for Data.Text.Text?> +-- +-- The followup discussion that changed the behavior of @Data.Set@ and @Data.Map@ is archived here +-- +-- <http://markmail.org/message/trovdc6zkphyi3cr#query:+page:1+mid:a46der3iacwjcf6n+state:results Proposal: Allow gunfold for Data.Map, ...> instance Data Text where gfoldl f z txt = z pack `f` (unpack txt) - toConstr _ = P.error "Data.Text.Text.toConstr" - gunfold _ _ = P.error "Data.Text.Text.gunfold" - dataTypeOf _ = mkNoRepType "Data.Text.Text" + toConstr _ = packConstr + gunfold k z c = case constrIndex c of + 1 -> k (z pack) + _ -> P.error "gunfold" + dataTypeOf _ = textDataType + +packConstr :: Constr +packConstr = mkConstr textDataType "pack" [] Prefix + +textDataType :: DataType +textDataType = mkDataType "Data.Text.Text" [packConstr] -- | /O(n)/ Compare two 'Text' values lexicographically. compareText :: Text -> Text -> Ordering diff --git a/text.cabal b/text.cabal index 4a4b35bc9c8d99210e209fd92cbcb63c1fc92153..b17096ba9c37f37792a99f44feec1b28f3c95795 100644 --- a/text.cabal +++ b/text.cabal @@ -1,5 +1,5 @@ name: text -version: 1.1.0.1 +version: 1.1.1 homepage: https://github.com/bos/text bug-reports: https://github.com/bos/text/issues synopsis: An efficient packed Unicode text type.