@@ -212,6 +212,7 @@ import qualified Data.List as L
212import Data.Char (isSpace)
212import Data.Char (isSpace)
213import Data.Data (Data(gfoldl, toConstr, gunfold, dataTypeOf), constrIndex,
213import Data.Data (Data(gfoldl, toConstr, gunfold, dataTypeOf), constrIndex,
214 Constr, mkConstr, DataType, mkDataType, Fixity(Prefix))
214 Constr, mkConstr, DataType, mkDataType, Fixity(Prefix))
215+import Data.Binary (Binary(get, put))
215import Data.Monoid (Monoid(..))
216import Data.Monoid (Monoid(..))
216import Data.String (IsString(..))
217import Data.String (IsString(..))
217import qualified Data.Text as T
218import qualified Data.Text as T
@@ -224,6 +225,7 @@ import Data.Text.Internal.Lazy.Fusion (stream, unstream)
224import Data.Text.Internal.Lazy (Text(..), chunk, empty, foldlChunks,
225import Data.Text.Internal.Lazy (Text(..), chunk, empty, foldlChunks,
225 foldrChunks, smallChunkSize)
226 foldrChunks, smallChunkSize)
226import Data.Text.Internal (firstf, safe, text)
227import Data.Text.Internal (firstf, safe, text)
228+import Data.Text.Lazy.Encoding (decodeUtf8, encodeUtf8)
227import qualified Data.Text.Internal.Functions as F
229import qualified Data.Text.Internal.Functions as F
228import Data.Text.Internal.Lazy.Search (indices)
230import Data.Text.Internal.Lazy.Search (indices)
229#if __GLASGOW_HASKELL__ >= 702
231#if __GLASGOW_HASKELL__ >= 702
@@ -353,6 +355,10 @@ instance NFData Text where
353 rnf (Chunk _ ts) = rnf ts
355 rnf (Chunk _ ts) = rnf ts
358+instance Binary Text where
359+ put t = put (encodeUtf8 t)
360+ get = P.fmap decodeUtf8 get
356-- | This instance preserves data abstraction at the cost of inefficiency.
362-- | This instance preserves data abstraction at the cost of inefficiency.
357-- We omit reflection services for the sake of data abstraction.
363-- We omit reflection services for the sake of data abstraction.
@@ -961,7 +967,7 @@ cycle t = let t' = foldrChunks Chunk t' t
962-- | @'iterate' f x@ returns an infinite 'Text' of repeated applications
968-- | @'iterate' f x@ returns an infinite 'Text' of repeated applications
963-- of @f@ to @x@:
969-- of @f@ to @x@:
965-- > iterate f x == [x, f x, f (f x), ...]
971-- > iterate f x == [x, f x, f (f x), ...]
966iterate :: (Char -> Char) -> Char -> Text
972iterate :: (Char -> Char) -> Char -> Text
967iterate f c = let t c' = Chunk (T.singleton c') (t (f c'))
973iterate f c = let t c' = Chunk (T.singleton c') (t (f c'))