on master help sign in
Turn Stream equality into an Eq instance
7565180Bryan O'Sullivan
Data/Text.hs+2−1
@@ -174,7 +174,8 @@ import qualified Data.Text.Encoding.Utf16 as U16
174-- one 'Text' value.
174-- one 'Text' value.
175
175
176instance Eq Text where
176instance Eq Text where
177− t1 == t2 = (stream t1) `S.eq` (stream t2)
177+ t1 == t2 = stream t1 == stream t2
178+ {-# INLINE (==) #-}
178
179
179instance Show Text where
180instance Show Text where
180 showsPrec p ps r = showsPrec p (unpack ps) r
181 showsPrec p ps r = showsPrec p (unpack ps) r
Data/Text/Fusion.hs−2
@@ -38,7 +38,6 @@ module Data.Text.Fusion
38 , init
38 , init
39 , null
39 , null
40 , length
40 , length
41− , eq
42
41
43 -- * Transformations
42 -- * Transformations
44 , map
43 , map
@@ -718,7 +717,6 @@ isPrefixOf (Stream next1 s1 _) (Stream next2 s2 _) = loop (next1 s1) (next2 s2)
718 loop (next1 s1') (next2 s2')
717 loop (next1 s1') (next2 s2')
719{-# INLINE [0] isPrefixOf #-}
718{-# INLINE [0] isPrefixOf #-}
720{-# SPECIALISE isPrefixOf :: Stream Char -> Stream Char -> Bool #-}
719{-# SPECIALISE isPrefixOf :: Stream Char -> Stream Char -> Bool #-}
721−
722-- ----------------------------------------------------------------------------
720-- ----------------------------------------------------------------------------
723-- * Searching
721-- * Searching
724
722
Data/Text/Fusion/Internal.hs+9−1
@@ -23,11 +23,11 @@ module Data.Text.Fusion.Internal
23 , empty
23 , empty
24 , streamList
24 , streamList
25 , unstreamList
25 , unstreamList
26− , eq
27 ) where
26 ) where
28
27
29infixl 2 :!:
28infixl 2 :!:
30data PairS a b = !a :!: !b
29data PairS a b = !a :!: !b
30+ deriving (Eq, Ord, Read, Show)
31
31
32-- | Allow a function over a stream to switch between two states.
32-- | Allow a function over a stream to switch between two states.
33data Switch = S1 | S2
33data Switch = S1 | S2
@@ -36,6 +36,14 @@ data Step s a = Done
36 | Skip !s
36 | Skip !s
37 | Yield !a !s
37 | Yield !a !s
38
38
39+instance Show a => Show (Step s a)
40+ where show Done = "Done"
41+ show (Skip _) = "Skip"
42+ show (Yield x _) = "Yield " ++ show x
43+
44+instance Eq a => Eq (Stream a) where
45+ (==) = eq
46+
39-- The length hint in a Stream has two roles. If its value is zero,
47-- The length hint in a Stream has two roles. If its value is zero,
40-- we trust it, and treat the stream as empty. Otherwise, we treat it
48-- we trust it, and treat the stream as empty. Otherwise, we treat it
41-- as a hint: it should usually be accurate, so we use it when
49-- as a hint: it should usually be accurate, so we use it when
Data/Text/Lazy.hs+2−1
@@ -154,7 +154,8 @@ import Data.Text.Lazy.Fusion
154import Data.Text.Lazy.Internal
154import Data.Text.Lazy.Internal
155
155
156instance Eq Text where
156instance Eq Text where
157− t1 == t2 = stream t1 `S.eq` stream t2
157+ t1 == t2 = stream t1 == stream t2
158+ {-# INLINE (==) #-}
158
159
159instance Show Text where
160instance Show Text where
160 showsPrec p ps r = showsPrec p (unpack ps) r
161 showsPrec p ps r = showsPrec p (unpack ps) r