on master help sign in
Turn Stream equality into an Eq instance

--HG-- extra : convert_revision : a34e19ee30c7ade98398c9f463ae903d3c8430b5

commit75651801e5d01fe767b7193cb4a52ea9d8c2f4bd authorBryan O'Sullivan <bos@serpentine.com> dateSat 28 Feb 2009, 21:48 (18 years ago) parentcdc3bec
4 files changed+13−5
Data/Text.hs+2−1 Data/Text/Fusion.hs−2 Data/Text/Fusion/Internal.hs+9−1 Data/Text/Lazy.hs+2−1
Data/Text.hs+2−1
@@ -174,7 +174,8 @@ import qualified Data.Text.Encoding.Utf16 as U16
174174-- one 'Text' value.
175175
176176instance Eq Text where
177− t1 == t2 = (stream t1) `S.eq` (stream t2)
177+ t1 == t2 = stream t1 == stream t2
178+ {-# INLINE (==) #-}
178179
179180instance Show Text where
180181 showsPrec p ps r = showsPrec p (unpack ps) r
Data/Text/Fusion.hs−2
@@ -38,7 +38,6 @@ module Data.Text.Fusion
3838 , init
3939 , null
4040 , length
41− , eq
4241
4342 -- * Transformations
4443 , map
@@ -718,7 +717,6 @@ isPrefixOf (Stream next1 s1 _) (Stream next2 s2 _) = loop (next1 s1) (next2 s2)
718717 loop (next1 s1') (next2 s2')
719718{-# INLINE [0] isPrefixOf #-}
720719{-# SPECIALISE isPrefixOf :: Stream Char -> Stream Char -> Bool #-}
721−
722720-- ----------------------------------------------------------------------------
723721-- * Searching
724722
Data/Text/Fusion/Internal.hs+9−1
@@ -23,11 +23,11 @@ module Data.Text.Fusion.Internal
2323 , empty
2424 , streamList
2525 , unstreamList
26− , eq
2726 ) where
2827
2928infixl 2 :!:
3029data PairS a b = !a :!: !b
30+ deriving (Eq, Ord, Read, Show)
3131
3232-- | Allow a function over a stream to switch between two states.
3333data Switch = S1 | S2
@@ -36,6 +36,14 @@ data Step s a = Done
3636 | Skip !s
3737 | Yield !a !s
3838
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+
3947-- The length hint in a Stream has two roles. If its value is zero,
4048-- we trust it, and treat the stream as empty. Otherwise, we treat it
4149-- 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
154154import Data.Text.Lazy.Internal
155155
156156instance Eq Text where
157− t1 == t2 = stream t1 `S.eq` stream t2
157+ t1 == t2 = stream t1 == stream t2
158+ {-# INLINE (==) #-}
158159
159160instance Show Text where
160161 showsPrec p ps r = showsPrec p (unpack ps) r