on master help sign in
Fix a bug in Data.Text.Fusion.eq

The stream comparison was wrong in the case of trailing Skip steps before the Done constructor. As in: T.filter (=='a') (T.pack "ab") == T.pack "a" --HG-- extra : convert_revision : 77b3ba993ce06084da06316086842c945a2b3b56

commit8853e59f859815d076f202c8bfc220665c800e88 authorNicolas Pouillard <nicolas.pouillard@gmail.com> dateSat 28 Feb 2009, 16:24 (18 years ago) parentcc5a5d2
1 file changed+20
Data/Text/Fusion.hs+20
Data/Text/Fusion.hs+20
@@ -172,6 +172,26 @@ unstream (Stream next0 s0 len)
172172{-# INLINE [0] unstream #-}
173173{-# RULES "STREAM stream/unstream fusion" forall s. stream (unstream s) = s #-}
174174
175+-- | The empty stream.
176+empty :: Stream Char
177+empty = Stream next () 0
178+ where next _ = Done
179+{-# INLINE [0] empty #-}
180+
181+-- | /O(n)/ Determines if two streams are equal.
182+eq :: Ord a => Stream a -> Stream a -> Bool
183+eq (Stream next1 s1 _) (Stream next2 s2 _) = cmp (next1 s1) (next2 s2)
184+ where
185+ cmp Done Done = True
186+ cmp Done _ = False
187+ cmp _ Done = False
188+ cmp (Skip s1') (Skip s2') = cmp (next1 s1') (next2 s2')
189+ cmp (Skip s1') x2 = cmp (next1 s1') x2
190+ cmp x1 (Skip s2') = cmp x1 (next2 s2')
191+ cmp (Yield x1 s1') (Yield x2 s2') = x1 == x2 &&
192+ cmp (next1 s1') (next2 s2')
193+{-# SPECIALISE eq :: Stream Char -> Stream Char -> Bool #-}
194+
175195streamError :: String -> String -> a
176196streamError func msg = P.error $ "Data.Text.Fusion." ++ func ++ ": " ++ msg
177197