@@ -212,6 +212,7 @@ import qualified Data.List as L
212212import Data.Char (isSpace)
213213import Data.Data (Data(gfoldl, toConstr, gunfold, dataTypeOf), constrIndex,
214214 Constr, mkConstr, DataType, mkDataType, Fixity(Prefix))
215+import Data.Binary (Binary(get, put))
215216import Data.Monoid (Monoid(..))
216217import Data.String (IsString(..))
217218import qualified Data.Text as T
@@ -224,6 +225,7 @@ import Data.Text.Internal.Lazy.Fusion (stream, unstream)
224225import Data.Text.Internal.Lazy (Text(..), chunk, empty, foldlChunks,
225226 foldrChunks, smallChunkSize)
226227import Data.Text.Internal (firstf, safe, text)
228+import Data.Text.Lazy.Encoding (decodeUtf8, encodeUtf8)
227229import qualified Data.Text.Internal.Functions as F
228230import Data.Text.Internal.Lazy.Search (indices)
229231#if __GLASGOW_HASKELL__ >= 702
@@ -353,6 +355,10 @@ instance NFData Text where
353355 rnf (Chunk _ ts) = rnf ts
354356#endif
355357
358+instance Binary Text where
359+ put t = put (encodeUtf8 t)
360+ get = P.fmap decodeUtf8 get
361+
356362-- | This instance preserves data abstraction at the cost of inefficiency.
357363-- We omit reflection services for the sake of data abstraction.
358364--
@@ -961,7 +967,7 @@ cycle t = let t' = foldrChunks Chunk t' t
961967
962968-- | @'iterate' f x@ returns an infinite 'Text' of repeated applications
963969-- of @f@ to @x@:
964−--
970+--
965971-- > iterate f x == [x, f x, f (f x), ...]
966972iterate :: (Char -> Char) -> Char -> Text
967973iterate f c = let t c' = Chunk (T.singleton c') (t (f c'))