Commit 1da8b9b9 authored by bos's avatar bos
Browse files

Merge pull request #119 from christiaanb/data-instance-lazy-text

Add feature parity Data instance Text and Text.Lazy
parents c5689ec5 29686315
......@@ -210,8 +210,8 @@ import Control.DeepSeq (NFData(..))
import Data.Int (Int64)
import qualified Data.List as L
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 Data.Monoid (Monoid(..))
import Data.String (IsString(..))
import qualified Data.Text as T
......@@ -353,11 +353,24 @@ instance NFData Text where
rnf (Chunk _ ts) = rnf ts
-- | 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 updated behavior of
-- @"Data.Text".@'Data.Text.Text'
instance Data Text where
gfoldl f z txt = z pack `f` (unpack txt)
toConstr _ = error "Data.Text.Lazy.Text.toConstr"
gunfold _ _ = error "Data.Text.Lazy.Text.gunfold"
dataTypeOf _ = mkNoRepType "Data.Text.Lazy.Text"
toConstr _ = packConstr
gunfold k z c = case constrIndex c of
1 -> k (z pack)
_ -> error "Data.Text.Lazy.Text.gunfold"
dataTypeOf _ = textDataType
packConstr :: Constr
packConstr = mkConstr textDataType "pack" [] Prefix
textDataType :: DataType
textDataType = mkDataType "Data.Text.Lazy.Text" [packConstr]
-- | /O(n)/ Convert a 'String' into a 'Text'.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment