@@ -0,0 +1,53 @@
1+{-# OPTIONS_GHC -fno-warn-orphans #-}
2+
3+module Data.Text.Lazy
4+ (
5+ Text
6+ , pack
7+ , unpack
8+ -- * Basic interface
9+ , append
10+ ) where
11+
12+import Data.String (IsString(..))
13+import qualified Data.Text.Fusion as S
14+import Data.Text.Fusion.Internal as S
15+import Data.Text.Lazy.Fusion
16+import Data.Text.Lazy.Internal
17+
18+instance Eq Text where
19+ t1 == t2 = stream t1 `S.eq` stream t2
20+
21+instance Show Text where
22+ showsPrec p ps r = showsPrec p (unpack ps) r
23+
24+instance Read Text where
25+ readsPrec p str = [(pack x,y) | (x,y) <- readsPrec p str]
26+
27+instance IsString Text where
28+ fromString = pack
29+
30+-- | /O(n)/ Convert a 'String' into a 'Text'.
31+--
32+-- This function is subject to array fusion.
33+pack :: String -> Text
34+pack = unstream . S.streamList
35+{-# INLINE [1] pack #-}
36+
37+-- | /O(n)/ Convert a 'Text' into a 'String'.
38+-- Subject to array fusion.
39+unpack :: Text -> String
40+unpack = unstreamList . stream
41+{-# INLINE [1] unpack #-}
42+
43+-- | /O(n\/c)/ Append two 'Text's
44+append :: Text -> Text -> Text
45+append xs ys = foldrChunks Chunk ys xs
46+{-# INLINE append #-}
47+
48+{-# RULES
49+"TEXT append -> fused" [~1] forall t1 t2.
50+ append t1 t2 = unstream (S.append (stream t1) (stream t2))
51+"TEXT append -> unfused" [1] forall t1 t2.
52+ unstream (S.append (stream t1) (stream t2)) = append t1 t2
53+ #-}