on master help sign in
added Data instance for Data.Text.Text

For more information see: "could we get a Data instance for Data.Text.Text?" http://groups.google.com/group/haskell-cafe/browse_thread/thread/b5bbb1b28a7e525d/0639d46852575b93 --HG-- extra : convert_revision : 8138deb5d76ee7fcafaccb2ce420f7f841f356c9

commitcfa6aa2e9dde342b66d9aef47d65d596f571ed5a authorJeremy Shaw <jeremy@seereason.com> dateMon 1 Feb 2010, 20:05 (17 years ago) parentff15b23
1 file changed+20−1
Data/Text.hs+20−1
Data/Text.hs+20−1
@@ -166,12 +166,13 @@ import Prelude (Char, Bool(..), Functor(..), Int, Maybe(..), String,
166166 Eq(..), Ord(..), (++),
167167 Read(..), Show(..),
168168 (&&), (||), (+), (-), (.), ($), (>>), (*),
169− div, not, return, otherwise)
169+ div, error, not, return, otherwise)
170170#if defined(HAVE_DEEPSEQ)
171171import Control.DeepSeq (NFData)
172172#endif
173173import Control.Exception (assert)
174174import Data.Char (isSpace)
175+import Data.Data (Data(gfoldl, toConstr, gunfold, dataTypeOf), mkNoRepType)
175176import Control.Monad (foldM)
176177import Control.Monad.ST (ST)
177178import qualified Data.Text.Array as A
@@ -221,6 +222,24 @@ instance IsString Text where
221222instance NFData Text
222223#endif
223224
225+-- This instance preserves data abstraction at the cost of inefficiency.
226+-- We omit reflection services for the sake of data abstraction.
227+--
228+-- This instance was created by copying the behavior of Data.Set and
229+-- Data.Map. If you feel a mistake has been made, please feel free to
230+-- submit improvements.
231+--
232+-- Original discussion is archived here:
233+
234+-- "could we get a Data instance for Data.Text.Text?"
235+-- http://groups.google.com/group/haskell-cafe/browse_thread/thread/b5bbb1b28a7e525d/0639d46852575b93
236+--
237+instance Data Text where
238+ gfoldl f z txt = z pack `f` (unpack txt)
239+ toConstr _ = error "Data.Text.Text:toConstr"
240+ gunfold _ _ = error "Data.Text.Text:gunfold"
241+ dataTypeOf _ = mkNoRepType "Data.Text.Text"
242+
224243-- -----------------------------------------------------------------------------
225244-- * Conversion to/from 'Text'
226245