@@ -63,7 +63,7 @@ unstream :: Stream Char -> Text
63unstream (Stream next0 s0 len) = x `seq` Text (fst x) 0 (snd x)
63unstream (Stream next0 s0 len) = x `seq` Text (fst x) 0 (snd x)
65 x :: ((UArray Int Word16),Int)
65 x :: ((UArray Int Word16),Int)
66− x = runST ((unsafeNewArray_ (0,len+1) :: ST s (STUArray s Int Word16))
66+ x = runST ((unsafeNewArray_ (0,len+1) :: ST s (STUArray s Int Word16))
67 >>= (\arr -> loop arr 0 (len+1) s0))
67 >>= (\arr -> loop arr 0 (len+1) s0))
68 loop arr !i !max !s
68 loop arr !i !max !s
69 | i + 1 > max = do arr' <- unsafeNewArray_ (0,max*2)
69 | i + 1 > max = do arr' <- unsafeNewArray_ (0,max*2)
@@ -80,7 +80,7 @@ unstream (Stream next0 s0 len) = x `seq` Text (fst x) 0 (snd x)
80 | otherwise -> do
80 | otherwise -> do
81 unsafeWrite arr i l
81 unsafeWrite arr i l
82 unsafeWrite arr (i + 1) r
82 unsafeWrite arr (i + 1) r
83− loop arr (i+2) max s'
83+ loop arr (i+2) max s'
@@ -93,13 +93,13 @@ unstream (Stream next0 s0 len) = x `seq` Text (fst x) 0 (snd x)
93{-# INLINE [0] unstream #-}
93{-# INLINE [0] unstream #-}
96−copy src dest = (do
96+copy src dest = (do
97 (_,max) <- getBounds src
97 (_,max) <- getBounds src
98 copy_loop 0 max)
98 copy_loop 0 max)
100− copy_loop !i !max
100+ copy_loop !i !max
101 | i > max = return ()
101 | i > max = return ()
102− | otherwise = do v <- unsafeRead src i
102+ | otherwise = do v <- unsafeRead src i
103 unsafeWrite dest i v
103 unsafeWrite dest i v
104 copy_loop (i+1) max
104 copy_loop (i+1) max
@@ -113,7 +113,7 @@ eq (Stream next1 s1 _) (Stream next2 s2 _) = compare (next1 s1) (next2 s2)
113 compare (Skip s1') (Skip s2') = compare (next1 s1') (next2 s2')
113 compare (Skip s1') (Skip s2') = compare (next1 s1') (next2 s2')
114 compare (Skip s1') x2 = compare (next1 s1') x2
114 compare (Skip s1') x2 = compare (next1 s1') x2
115 compare x1 (Skip s2') = compare x1 (next2 s2')
115 compare x1 (Skip s2') = compare x1 (next2 s2')
116− compare (Yield x1 s1') (Yield x2 s2') = x1 == x2 &&
116+ compare (Yield x1 s1') (Yield x2 s2') = x1 == x2 &&
117 compare (next1 s1') (next2 s2')
117 compare (next1 s1') (next2 s2')
118{-# SPECIALISE eq :: Stream Char -> Stream Char -> Bool #-}
118{-# SPECIALISE eq :: Stream Char -> Stream Char -> Bool #-}
@@ -123,12 +123,12 @@ stream_bs :: Encoding -> ByteString -> Stream Char
123stream_bs ASCII bs = Stream next 0 (B.length bs)
123stream_bs ASCII bs = Stream next 0 (B.length bs)
125 {-# INLINE next #-}
125 {-# INLINE next #-}
127 | i >= l = Done
127 | i >= l = Done
128 | otherwise = Yield (unsafeChr8 x1) (i+1)
128 | otherwise = Yield (unsafeChr8 x1) (i+1)
130 l = B.length bs
130 l = B.length bs
131− x1 = B.index bs i
131+ x1 = B.index bs i
132stream_bs Utf8 bs = Stream next 0 (B.length bs)
132stream_bs Utf8 bs = Stream next 0 (B.length bs)
134 {-# INLINE next #-}
134 {-# INLINE next #-}
@@ -145,11 +145,11 @@ stream_bs Utf8 bs = Stream next 0 (B.length bs)
145 x2 = index (i + 1)
145 x2 = index (i + 1)
146 x3 = index (i + 2)
146 x3 = index (i + 2)
147 x4 = index (i + 3)
147 x4 = index (i + 3)
148− index = B.index bs
148+ index = B.index bs
149stream_bs Utf16LE bs = Stream next 0 (B.length bs)
149stream_bs Utf16LE bs = Stream next 0 (B.length bs)
151 {-# INLINE next #-}
151 {-# INLINE next #-}
153 | i >= l = Done
153 | i >= l = Done
154 | i+1 < l && U16.validate1 x1 = Yield (unsafeChr x1) (i+2)
154 | i+1 < l && U16.validate1 x1 = Yield (unsafeChr x1) (i+2)
155 | i+3 < l && U16.validate2 x1 x2 = Yield (U16.chr2 x1 x2) (i+4)
155 | i+3 < l && U16.validate2 x1 x2 = Yield (U16.chr2 x1 x2) (i+4)
@@ -159,12 +159,12 @@ stream_bs Utf16LE bs = Stream next 0 (B.length bs)
159 x1 = (shiftL (index (i + 1)) 8) + (index i)
159 x1 = (shiftL (index (i + 1)) 8) + (index i)
160 x2 :: Word16
160 x2 :: Word16
161 x2 = (shiftL (index (i + 3)) 8) + (index (i + 2))
161 x2 = (shiftL (index (i + 3)) 8) + (index (i + 2))
162− l = B.length bs
162+ l = B.length bs
163 index = fromIntegral . B.index bs :: Int -> Word16
163 index = fromIntegral . B.index bs :: Int -> Word16
164stream_bs Utf16BE bs = Stream next 0 (B.length bs)
164stream_bs Utf16BE bs = Stream next 0 (B.length bs)
166 {-# INLINE next #-}
166 {-# INLINE next #-}
168 | i >= l = Done
168 | i >= l = Done
169 | i+1 < l && U16.validate1 x1 = Yield (unsafeChr x1) (i+2)
169 | i+1 < l && U16.validate1 x1 = Yield (unsafeChr x1) (i+2)
170 | i+3 < l && U16.validate2 x1 x2 = Yield (U16.chr2 x1 x2) (i+4)
170 | i+3 < l && U16.validate2 x1 x2 = Yield (U16.chr2 x1 x2) (i+4)
@@ -179,7 +179,7 @@ stream_bs Utf16BE bs = Stream next 0 (B.length bs)
179stream_bs Utf32BE bs = Stream next 0 (B.length bs)
179stream_bs Utf32BE bs = Stream next 0 (B.length bs)
181 {-# INLINE next #-}
181 {-# INLINE next #-}
183 | i >= l = Done
183 | i >= l = Done
184 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
184 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
185 | otherwise = error "bsStream: bad UTF-32BE stream"
185 | otherwise = error "bsStream: bad UTF-32BE stream"
@@ -194,7 +194,7 @@ stream_bs Utf32BE bs = Stream next 0 (B.length bs)
194stream_bs Utf32LE bs = Stream next 0 (B.length bs)
194stream_bs Utf32LE bs = Stream next 0 (B.length bs)
196 {-# INLINE next #-}
196 {-# INLINE next #-}
198 | i >= l = Done
198 | i >= l = Done
199 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
199 | i+3 < l && U32.validate x = Yield (unsafeChr32 x) (i+4)
200 | otherwise = error "bsStream: bad UTF-32LE stream"
200 | otherwise = error "bsStream: bad UTF-32LE stream"
@@ -217,14 +217,14 @@ restream ASCII (Stream next0 s0 len) = Stream next s0 (len*2)
217 Skip s' -> Skip s'
217 Skip s' -> Skip s'
218 Yield x xs -> Yield x' xs
218 Yield x xs -> Yield x' xs
219 where x' = fromIntegral (ord x) :: Word8
219 where x' = fromIntegral (ord x) :: Word8
220−restream Utf8 (Stream next0 s0 len) =
220+restream Utf8 (Stream next0 s0 len) =
221 Stream next ((Just s0) :!: Nothing :!: Nothing :!: Nothing) (len*2)
221 Stream next ((Just s0) :!: Nothing :!: Nothing :!: Nothing) (len*2)
223 {-# INLINE next #-}
223 {-# INLINE next #-}
224− next ((Just s) :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
224+ next ((Just s) :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
225 Done -> Done
225 Done -> Done
226 Skip s' -> Skip ((Just s') :!: Nothing :!: Nothing :!: Nothing)
226 Skip s' -> Skip ((Just s') :!: Nothing :!: Nothing :!: Nothing)
227− Yield x xs
227+ Yield x xs
228 | n <= 0x7F -> Yield c ((Just xs) :!: Nothing :!: Nothing :!: Nothing)
228 | n <= 0x7F -> Yield c ((Just xs) :!: Nothing :!: Nothing :!: Nothing)
229 | n <= 0x07FF -> Yield (fst c2) ((Just xs) :!: (Just $ snd c2) :!: Nothing :!: Nothing)
229 | n <= 0x07FF -> Yield (fst c2) ((Just xs) :!: (Just $ snd c2) :!: Nothing :!: Nothing)
230 | n <= 0xFFFF -> Yield (fst3 c3) ((Just xs) :!: (Just $ snd3 c3) :!: (Just $ trd3 c3) :!: Nothing)
230 | n <= 0xFFFF -> Yield (fst3 c3) ((Just xs) :!: (Just $ snd3 c3) :!: (Just $ trd3 c3) :!: Nothing)
@@ -234,7 +234,7 @@ restream Utf8 (Stream next0 s0 len) =
234 c = fromIntegral n
234 c = fromIntegral n
235 c2 = U8.ord2 x
235 c2 = U8.ord2 x
236 c3 = U8.ord3 x
236 c3 = U8.ord3 x
237− c4 = U8.ord4 x
237+ c4 = U8.ord4 x
238 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
238 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
239 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
239 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
240 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
240 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
@@ -242,7 +242,7 @@ restream Utf16BE (Stream next0 s0 len) =
242 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
242 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
244 {-# INLINE next #-}
244 {-# INLINE next #-}
245− next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
245+ next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
246 Done -> Done
246 Done -> Done
247 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
247 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
248 Yield x xs
248 Yield x xs
@@ -250,12 +250,12 @@ restream Utf16BE (Stream next0 s0 len) =
250 | otherwise -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
250 | otherwise -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
252 n = ord x
252 n = ord x
253− n1 = n - 0x10000
253+ n1 = n - 0x10000
254 c1 = fromIntegral (shiftR n1 18 + 0xD8)
254 c1 = fromIntegral (shiftR n1 18 + 0xD8)
255− c2 = fromIntegral (shiftR n1 10)
255+ c2 = fromIntegral (shiftR n1 10)
256 n2 = n1 .&. 0x3FF
256 n2 = n1 .&. 0x3FF
257− c3 = fromIntegral (shiftR n2 8 + 0xDC)
257+ c3 = fromIntegral (shiftR n2 8 + 0xDC)
258− c4 = fromIntegral n2
258+ c4 = fromIntegral n2
259 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
259 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
260 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
260 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
261 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
261 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
@@ -263,7 +263,7 @@ restream Utf16LE (Stream next0 s0 len) =
263 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
263 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
265 {-# INLINE next #-}
265 {-# INLINE next #-}
266− next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
266+ next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
267 Done -> Done
267 Done -> Done
268 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
268 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
269 Yield x xs
269 Yield x xs
@@ -271,20 +271,20 @@ restream Utf16LE (Stream next0 s0 len) =
271 | otherwise -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
271 | otherwise -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
273 n = ord x
273 n = ord x
274− n1 = n - 0x10000
274+ n1 = n - 0x10000
275 c2 = fromIntegral (shiftR n1 18 + 0xD8)
275 c2 = fromIntegral (shiftR n1 18 + 0xD8)
276− c1 = fromIntegral (shiftR n1 10)
276+ c1 = fromIntegral (shiftR n1 10)
277 n2 = n1 .&. 0x3FF
277 n2 = n1 .&. 0x3FF
278− c4 = fromIntegral (shiftR n2 8 + 0xDC)
278+ c4 = fromIntegral (shiftR n2 8 + 0xDC)
279− c3 = fromIntegral n2
279+ c3 = fromIntegral n2
280 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
280 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
281 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
281 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
282 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
282 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
283−restream Utf32BE (Stream next0 s0 len) =
283+restream Utf32BE (Stream next0 s0 len) =
284 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
284 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
286 {-# INLINE next #-}
286 {-# INLINE next #-}
287− next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
287+ next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
288 Done -> Done
288 Done -> Done
289 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
289 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
290 Yield x xs -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
290 Yield x xs -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
@@ -297,11 +297,11 @@ restream Utf32BE (Stream next0 s0 len) =
297 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
297 next ((Just s) :!: (Just x2) :!: Nothing :!: Nothing) = Yield x2 ((Just s) :!: Nothing :!: Nothing :!: Nothing)
298 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
298 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
299 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
299 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
300−restream Utf32LE (Stream next0 s0 len) =
300+restream Utf32LE (Stream next0 s0 len) =
301 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
301 Stream next (Just s0 :!: Nothing :!: Nothing :!: Nothing) (len*2)
303 {-# INLINE next #-}
303 {-# INLINE next #-}
304− next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
304+ next (Just s :!: Nothing :!: Nothing :!: Nothing) = case next0 s of
305 Done -> Done
305 Done -> Done
306 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
306 Skip s' -> Skip (Just s' :!: Nothing :!: Nothing :!: Nothing)
307 Yield x xs -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
307 Yield x xs -> Yield c1 (Just xs :!: Just c2 :!: Just c3 :!: Just c4)
@@ -315,15 +315,15 @@ restream Utf32LE (Stream next0 s0 len) =
315 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
315 next ((Just s) :!: (Just x2) :!: x3 :!: Nothing) = Yield x2 ((Just s) :!: x3 :!: Nothing :!: Nothing)
316 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
316 next ((Just s) :!: (Just x2) :!: x3 :!: x4) = Yield x2 ((Just s) :!: x3 :!: x4 :!: Nothing)
317{-# INLINE restream #-}
317{-# INLINE restream #-}
320fst3 (x1,_,_) = x1
320fst3 (x1,_,_) = x1
321snd3 (_,x2,_) = x2
321snd3 (_,x2,_) = x2
322trd3 (_,_,x3) = x3
322trd3 (_,_,x3) = x3
323−fst4 (x1,_,_,_) = x1
323+fst4 (x1,_,_,_) = x1
324snd4 (_,x2,_,_) = x2
324snd4 (_,x2,_,_) = x2
325trd4 (_,_,x3,_) = x3
325trd4 (_,_,x3,_) = x3
326−fth4 (_,_,_,x4) = x4
326+fth4 (_,_,_,x4) = x4
328-- | /O(n)/ Convert a Stream Word8 to a ByteString
328-- | /O(n)/ Convert a Stream Word8 to a ByteString
329unstream_bs :: Stream Word8 -> ByteString
329unstream_bs :: Stream Word8 -> ByteString
@@ -359,13 +359,13 @@ unstream_bs (Stream next s0 len) = unsafePerformIO $ do
359-- ----------------------------------------------------------------------------
359-- ----------------------------------------------------------------------------
360-- * Basic stream functions
360-- * Basic stream functions
362−-- | /O(n)/ Adds a character to the front of a Stream Char.
362+-- | /O(n)/ Adds a character to the front of a Stream Char.
363cons :: Char -> Stream Char -> Stream Char
363cons :: Char -> Stream Char -> Stream Char
364cons w (Stream next0 s0 len) = Stream next (S2 :!: s0) (len+2)
364cons w (Stream next0 s0 len) = Stream next (S2 :!: s0) (len+2)
366 {-# INLINE next #-}
366 {-# INLINE next #-}
367 next (S2 :!: s) = Yield w (S1 :!: s)
367 next (S2 :!: s) = Yield w (S1 :!: s)
368− next (S1 :!: s) = case next0 s of
368+ next (S1 :!: s) = case next0 s of
369 Done -> Done
369 Done -> Done
370 Skip s' -> Skip (S1 :!: s')
370 Skip s' -> Skip (S1 :!: s')
371 Yield x s' -> Yield x (S1 :!: s')
371 Yield x s' -> Yield x (S1 :!: s')
@@ -385,11 +385,11 @@ snoc (Stream next0 xs0 len) w = Stream next (Just xs0) (len+2)
386-- | /O(n)/ Appends one Stream to the other.
386-- | /O(n)/ Appends one Stream to the other.
387append :: Stream Char -> Stream Char -> Stream Char
387append :: Stream Char -> Stream Char -> Stream Char
388−append (Stream next0 s01 len1) (Stream next1 s02 len2) =
388+append (Stream next0 s01 len1) (Stream next1 s02 len2) =
389 Stream next (Left s01) (len1 + len2)
389 Stream next (Left s01) (len1 + len2)
391 {-# INLINE next #-}
391 {-# INLINE next #-}
392− next (Left s1) = case next0 s1 of
392+ next (Left s1) = case next0 s1 of
393 Done -> Skip (Right s02)
393 Done -> Skip (Right s02)
394 Skip s1' -> Skip (Left s1')
394 Skip s1' -> Skip (Left s1')
395 Yield x s1' -> Yield x (Left s1')
395 Yield x s1' -> Yield x (Left s1')
@@ -403,8 +403,8 @@ append (Stream next0 s01 len1) (Stream next1 s02 len2) =
403-- Subject to array fusion.
403-- Subject to array fusion.
404head :: Stream Char -> Char
404head :: Stream Char -> Char
405head (Stream next s0 len) = loop_head s0
405head (Stream next s0 len) = loop_head s0
407− loop_head !s = case next s of
407+ loop_head !s = case next s of
408 Yield x _ -> x
408 Yield x _ -> x
409 Skip s' -> loop_head s'
409 Skip s' -> loop_head s'
410 Done -> error "head: Empty list"
410 Done -> error "head: Empty list"
@@ -433,7 +433,7 @@ tail (Stream next0 s0 len) = Stream next (False :!: s0) (len-1)
433 next (False :!: s) = case next0 s of
433 next (False :!: s) = case next0 s of
434 Done -> error "tail"
434 Done -> error "tail"
435 Skip s' -> Skip (False :!: s')
435 Skip s' -> Skip (False :!: s')
436− Yield _ s' -> Skip (True :!: s')
436+ Yield _ s' -> Skip (True :!: s')
437 next (True :!: s) = case next0 s of
437 next (True :!: s) = case next0 s of
438 Done -> Done
438 Done -> Done
439 Skip s' -> Skip (True :!: s')
439 Skip s' -> Skip (True :!: s')
@@ -441,7 +441,7 @@ tail (Stream next0 s0 len) = Stream next (False :!: s0) (len-1)
441{-# INLINE [0] tail #-}
441{-# INLINE [0] tail #-}
444−-- | /O(1)/ Returns all but the last character of a Stream Char, which
444+-- | /O(1)/ Returns all but the last character of a Stream Char, which
445-- must be non-empty.
445-- must be non-empty.
446init :: Stream Char -> Stream Char
446init :: Stream Char -> Stream Char
447init (Stream next0 s0 len) = Stream next (Nothing :!: s0) (len-1)
447init (Stream next0 s0 len) = Stream next (Nothing :!: s0) (len-1)
@@ -472,28 +472,28 @@ length :: Stream Char -> Int
472length (Stream next s0 len) = loop_length 0# s0
472length (Stream next s0 len) = loop_length 0# s0
475− loop_length z# !s = case next s of
475+ loop_length z# !s = case next s of
476 Done -> (I# z#)
476 Done -> (I# z#)
477− Skip s' -> loop_length z# s'
477+ Skip s' -> loop_length z# s'
478− Yield _ s' -> loop_length (z# +# 1#) s'
478+ Yield _ s' -> loop_length (z# +# 1#) s'
479{-# INLINE[0] length #-}
479{-# INLINE[0] length #-}
481-- ----------------------------------------------------------------------------
481-- ----------------------------------------------------------------------------
482-- * Stream transformations
482-- * Stream transformations
484−-- | /O(n)/ 'map' @f @xs is the Stream Char obtained by applying @f@ to each element of
484+-- | /O(n)/ 'map' @f @xs is the Stream Char obtained by applying @f@ to each element of
485−-- @xs@.
485+-- @xs@.
486map :: (Char -> Char) -> Stream Char -> Stream Char
486map :: (Char -> Char) -> Stream Char -> Stream Char
487map f (Stream next0 s0 len) = Stream next s0 len
487map f (Stream next0 s0 len) = Stream next s0 len
489 {-# INLINE next #-}
489 {-# INLINE next #-}
490− next !s = case next0 s of
490+ next !s = case next0 s of
491 Done -> Done
491 Done -> Done
492 Skip s' -> Skip s'
492 Skip s' -> Skip s'
493− Yield x s' -> Yield (f x) s'
493+ Yield x s' -> Yield (f x) s'
494{-# INLINE [0] map #-}
494{-# INLINE [0] map #-}
497 RULES "STREAM map/map fusion" forall f g s.
497 RULES "STREAM map/map fusion" forall f g s.
498 map f (map g s) = map (\x -> f (g x)) s
498 map f (map g s) = map (\x -> f (g x)) s
@@ -517,7 +517,7 @@ intersperse c (Stream next0 s0 len) = Stream next (s0 :!: Nothing :!: S1) len
517-- ----------------------------------------------------------------------------
517-- ----------------------------------------------------------------------------
518-- * Reducing Streams (folds)
518-- * Reducing Streams (folds)
520−-- | foldl, applied to a binary operator, a starting value (typically the
520+-- | foldl, applied to a binary operator, a starting value (typically the
521-- left-identity of the operator), and a Stream, reduces the Stream using the
521-- left-identity of the operator), and a Stream, reduces the Stream using the
522-- binary operator, from left to right.
522-- binary operator, from left to right.
523foldl :: (b -> Char -> b) -> b -> Stream Char -> b
523foldl :: (b -> Char -> b) -> b -> Stream Char -> b
@@ -539,7 +539,7 @@ foldl' f z0 (Stream next s0 len) = loop_foldl' z0 s0
539 Yield x s' -> loop_foldl' (f z x) s'
539 Yield x s' -> loop_foldl' (f z x) s'
540{-# INLINE [0] foldl' #-}
540{-# INLINE [0] foldl' #-}
542−-- | foldl1 is a variant of foldl that has no starting value argument,
542+-- | foldl1 is a variant of foldl that has no starting value argument,
543-- and thus must be applied to non-empty Streams.
543-- and thus must be applied to non-empty Streams.
544foldl1 :: (Char -> Char -> Char) -> Stream Char -> Char
544foldl1 :: (Char -> Char -> Char) -> Stream Char -> Char
545foldl1 f (Stream next s0 len) = loop0_foldl1 s0
545foldl1 f (Stream next s0 len) = loop0_foldl1 s0
@@ -568,7 +568,7 @@ foldl1' f (Stream next s0 len) = loop0_foldl1' s0
568 Yield x s' -> loop_foldl1' (f z x) s'
568 Yield x s' -> loop_foldl1' (f z x) s'
569{-# INLINE [0] foldl1' #-}
569{-# INLINE [0] foldl1' #-}
571−-- | 'foldr', applied to a binary operator, a starting value (typically the
571+-- | 'foldr', applied to a binary operator, a starting value (typically the
572-- right-identity of the operator), and a stream, reduces the stream using the
572-- right-identity of the operator), and a stream, reduces the stream using the
573-- binary operator, from right to left.
573-- binary operator, from right to left.
574foldr :: (Char -> b -> b) -> b -> Stream Char -> b
574foldr :: (Char -> b -> b) -> b -> Stream Char -> b
@@ -580,7 +580,7 @@ foldr f z (Stream next s0 len) = loop_foldr s0
580 Yield x s' -> f x (loop_foldr s')
580 Yield x s' -> f x (loop_foldr s')
581{-# INLINE [0] foldr #-}
581{-# INLINE [0] foldr #-}
583−-- | foldr1 is a variant of 'foldr' that has no starting value argument,
583+-- | foldr1 is a variant of 'foldr' that has no starting value argument,
584-- and thust must be applied to non-empty streams.
584-- and thust must be applied to non-empty streams.
585-- Subject to array fusion.
585-- Subject to array fusion.
586foldr1 :: (Char -> Char -> Char) -> Stream Char -> Char
586foldr1 :: (Char -> Char -> Char) -> Stream Char -> Char
@@ -596,7 +596,7 @@ foldr1 f (Stream next s0 len) = loop0_foldr1 s0
596 Skip s' -> loop_foldr1 x s'
596 Skip s' -> loop_foldr1 x s'
597 Yield x' s' -> f x (loop_foldr1 x' s')
597 Yield x' s' -> f x (loop_foldr1 x' s')
598{-# INLINE [0] foldr1 #-}
598{-# INLINE [0] foldr1 #-}
600-- ----------------------------------------------------------------------------
600-- ----------------------------------------------------------------------------
601-- ** Special folds
601-- ** Special folds
@@ -606,7 +606,7 @@ concat = L.foldr append (Stream next Done 0)
607 next Done = Done
607 next Done = Done
609−-- | Map a function over a stream that results in a steram and concatenate the
609+-- | Map a function over a stream that results in a steram and concatenate the
610-- results.
610-- results.
611concatMap :: (Char -> Stream Char) -> Stream Char -> Stream Char
611concatMap :: (Char -> Stream Char) -> Stream Char -> Stream Char
612concatMap f = foldr (append . f) (stream empty)
612concatMap f = foldr (append . f) (stream empty)
@@ -627,14 +627,14 @@ any p (Stream next0 s0 len) = loop_any s0
627all :: (Char -> Bool) -> Stream Char -> Bool
627all :: (Char -> Bool) -> Stream Char -> Bool
628all p (Stream next0 s0 len) = loop_all s0
628all p (Stream next0 s0 len) = loop_all s0
630− loop_all !s = case next0 s of
630+ loop_all !s = case next0 s of
631 Done -> True
631 Done -> True
632 Skip s' -> seq s' $ loop_all s'
632 Skip s' -> seq s' $ loop_all s'
633 Yield x s' | p x -> seq s' $ loop_all s'
633 Yield x s' | p x -> seq s' $ loop_all s'
634 | otherwise -> False
634 | otherwise -> False
636−-- | /O(n)/ maximum returns the maximum value from a stream, which must be
636+-- | /O(n)/ maximum returns the maximum value from a stream, which must be
637−-- non-empty.
637+-- non-empty.
638maximum :: Stream Char -> Char
638maximum :: Stream Char -> Char
639maximum (Stream next0 s0 len) = loop0_maximum s0
639maximum (Stream next0 s0 len) = loop0_maximum s0
@@ -648,8 +648,8 @@ maximum (Stream next0 s0 len) = loop0_maximum s0
648 Yield x s'
648 Yield x s'
649 | x > z -> seq s' $ loop_maximum x s'
649 | x > z -> seq s' $ loop_maximum x s'
650 | otherwise -> seq s' $ loop_maximum z s'
650 | otherwise -> seq s' $ loop_maximum z s'
652−-- | /O(n)/ minimum returns the minimum value from a 'Text', which must be
652+-- | /O(n)/ minimum returns the minimum value from a 'Text', which must be
653-- non-empty.
653-- non-empty.
654minimum :: Stream Char -> Char
654minimum :: Stream Char -> Char
655minimum (Stream next0 s0 len) = loop0_minimum s0
655minimum (Stream next0 s0 len) = loop0_minimum s0
@@ -666,8 +666,8 @@ minimum (Stream next0 s0 len) = loop0_minimum s0
666 | otherwise -> seq s' $ loop_minimum z s'
666 | otherwise -> seq s' $ loop_minimum z s'
671-- -----------------------------------------------------------------------------
671-- -----------------------------------------------------------------------------
672-- * Building streams
672-- * Building streams
@@ -694,8 +694,8 @@ unfoldr f s0 = Stream next s0 1
694-- first argument to unfoldrN. This function is more efficient than
694-- first argument to unfoldrN. This function is more efficient than
695-- unfoldr when the maximum length of the result and correct,
695-- unfoldr when the maximum length of the result and correct,
696-- otherwise its complexity performance is similar to 'unfoldr'
696-- otherwise its complexity performance is similar to 'unfoldr'
697−unfoldrN :: Int -> (a -> Maybe (Char,a)) -> a -> Stream Char
697+unfoldrN :: Int -> (a -> Maybe (Char,a)) -> a -> Stream Char
698−unfoldrN n f s0 = Stream next (0 :!: s0) (n*2)
698+unfoldrN n f s0 = Stream next (0 :!: s0) (n*2)
700 {-# INLINE next #-}
700 {-# INLINE next #-}
701 next (z :!: s) = case f s of
701 next (z :!: s) = case f s of
@@ -718,7 +718,7 @@ take n0 (Stream next0 s0 len) = Stream next (n0 :!: s0) len
718 Skip s' -> Skip (n :!: s')
718 Skip s' -> Skip (n :!: s')
719 Yield x s' -> Yield x ((n-1) :!: s')
719 Yield x s' -> Yield x ((n-1) :!: s')
720{-# INLINE [0] take #-}
720{-# INLINE [0] take #-}
722-- | /O(n)/ drop n, applied to a stream, returns the suffix of the
722-- | /O(n)/ drop n, applied to a stream, returns the suffix of the
723-- stream of length @n@, or the empty stream if @n@ is greater than the
723-- stream of length @n@, or the empty stream if @n@ is greater than the
724-- length of the stream.
724-- length of the stream.
@@ -768,7 +768,7 @@ dropWhile p (Stream next0 s0 len) = Stream next (S1 :!: s0) len
768{-# INLINE [0] dropWhile #-}
768{-# INLINE [0] dropWhile #-}
770-- ----------------------------------------------------------------------------
770-- ----------------------------------------------------------------------------
771−-- * Searching
771+-- * Searching
773-------------------------------------------------------------------------------
773-------------------------------------------------------------------------------
774-- ** Searching by equality
774-- ** Searching by equality
@@ -794,7 +794,7 @@ elem w (Stream next s0 len) = loop_elem s0
794find :: (Char -> Bool) -> Stream Char -> Maybe Char
794find :: (Char -> Bool) -> Stream Char -> Maybe Char
795find p (Stream next s0 len) = loop_find s0
795find p (Stream next s0 len) = loop_find s0
797− loop_find !s = case next s of
797+ loop_find !s = case next s of
798 Done -> Nothing
798 Done -> Nothing
799 Skip s' -> loop_find s'
799 Skip s' -> loop_find s'
800 Yield x s' | p x -> Just x
800 Yield x s' | p x -> Just x
@@ -851,7 +851,7 @@ findIndex p (Stream next s0 len) = loop_findIndex 0 s0
852-- | /O(n)/ The 'elemIndex' function returns the index of the first
852-- | /O(n)/ The 'elemIndex' function returns the index of the first
853-- element in the given stream which is equal to the query
853-- element in the given stream which is equal to the query
854−-- element, or 'Nothing' if there is no such element.
854+-- element, or 'Nothing' if there is no such element.
855elemIndex :: Char -> Stream Char -> Maybe Int
855elemIndex :: Char -> Stream Char -> Maybe Int
856elemIndex a (Stream next s0 len) = loop_elemIndex 0 s0
856elemIndex a (Stream next s0 len) = loop_elemIndex 0 s0
@@ -875,7 +875,7 @@ zipWith f (Stream next0 sa0 len1) (Stream next1 sb0 len2) = Stream next (sa0 :!:
875 Done -> Done
875 Done -> Done
876 Skip sa' -> Skip (sa' :!: sb :!: Nothing)
876 Skip sa' -> Skip (sa' :!: sb :!: Nothing)
877 Yield a sa' -> Skip (sa' :!: sb :!: Just a)
877 Yield a sa' -> Skip (sa' :!: sb :!: Just a)
879 next (sa' :!: sb :!: Just a) = case next1 sb of
879 next (sa' :!: sb :!: Just a) = case next1 sb of
880 Done -> Done
880 Done -> Done
881 Skip sb' -> Skip (sa' :!: sb' :!: Just a)
881 Skip sb' -> Skip (sa' :!: sb' :!: Just a)
@@ -884,4 +884,4 @@ zipWith f (Stream next0 sa0 len1) (Stream next1 sb0 len2) = Stream next (sa0 :!:
885errorEmptyList :: String -> a
885errorEmptyList :: String -> a
886errorEmptyList fun =
886errorEmptyList fun =
887− error ("Prelude." ++ fun ++ ": empty list")
887+ error ("Prelude." ++ fun ++ ": empty list")