@@ -1,6 +1,4 @@
11{-# LANGUAGE ExistentialQuantification, BangPatterns, MagicHash #-}
2−--TODO: eliminate the need to supress these warnings:
3−{-# OPTIONS_GHC -fno-warn-incomplete-patterns -fno-warn-unused-matches #-}
42
53module Data.Text.Fusion where
64
@@ -209,6 +207,9 @@ stream_bs Utf32LE bs = Stream next 0 l
209207 index = fromIntegral . B.unsafeIndex bs :: Int -> Word32
210208{-# INLINE [0] stream_bs #-}
211209
210+internalError :: String -> a
211+internalError func = error $ "Data.Text.Fusion." ++ func ++ ": internal error"
212+
212213-- | /O(n)/ Convert a Stream Char into a Stream Word8 using the specified encoding standard.
213214restream :: Encoding -> Stream Char -> Stream Word8
214215restream ASCII (Stream next0 s0 len) = Stream next s0 (len*2)
@@ -239,6 +240,7 @@ restream Utf8 (Stream next0 s0 len) =
239240 next (T4 (Just s) (Just x2) Nothing Nothing) = Yield x2 (T4 (Just s) Nothing Nothing Nothing)
240241 next (T4 (Just s) (Just x2) x3 Nothing) = Yield x2 (T4 (Just s) x3 Nothing Nothing)
241242 next (T4 (Just s) (Just x2) x3 x4) = Yield x2 (T4 (Just s) x3 x4 Nothing)
243+ next _ = internalError "restream Utf8"
242244restream Utf16BE (Stream next0 s0 len) =
243245 Stream next (T4 (Just s0) Nothing Nothing Nothing) (len*2)
244246 where
@@ -260,6 +262,7 @@ restream Utf16BE (Stream next0 s0 len) =
260262 next (T4 (Just s) (Just x2) Nothing Nothing) = Yield x2 (T4 (Just s) Nothing Nothing Nothing)
261263 next (T4 (Just s) (Just x2) x3 Nothing) = Yield x2 (T4 (Just s) x3 Nothing Nothing)
262264 next (T4 (Just s) (Just x2) x3 x4) = Yield x2 (T4 (Just s) x3 x4 Nothing)
265+ next _ = internalError "restream Utf16BE"
263266restream Utf16LE (Stream next0 s0 len) =
264267 Stream next (T4 (Just s0) Nothing Nothing Nothing) (len*2)
265268 where
@@ -281,6 +284,7 @@ restream Utf16LE (Stream next0 s0 len) =
281284 next (T4 (Just s) (Just x2) Nothing Nothing) = Yield x2 (T4 (Just s) Nothing Nothing Nothing)
282285 next (T4 (Just s) (Just x2) x3 Nothing) = Yield x2 (T4 (Just s) x3 Nothing Nothing)
283286 next (T4 (Just s) (Just x2) x3 x4) = Yield x2 (T4 (Just s) x3 x4 Nothing)
287+ next _ = internalError "restream Utf16LE"
284288restream Utf32BE (Stream next0 s0 len) =
285289 Stream next (T4 (Just s0) Nothing Nothing Nothing) (len*2)
286290 where
@@ -298,6 +302,7 @@ restream Utf32BE (Stream next0 s0 len) =
298302 next (T4 (Just s) (Just x2) Nothing Nothing) = Yield x2 (T4 (Just s) Nothing Nothing Nothing)
299303 next (T4 (Just s) (Just x2) x3 Nothing) = Yield x2 (T4 (Just s) x3 Nothing Nothing)
300304 next (T4 (Just s) (Just x2) x3 x4) = Yield x2 (T4 (Just s) x3 x4 Nothing)
305+ next _ = internalError "restream Utf32BE"
301306restream Utf32LE (Stream next0 s0 len) =
302307 Stream next (T4 (Just s0) Nothing Nothing Nothing) (len*2)
303308 where
@@ -315,6 +320,7 @@ restream Utf32LE (Stream next0 s0 len) =
315320 next (T4 (Just s) (Just x2) Nothing Nothing) = Yield x2 (T4 (Just s) Nothing Nothing Nothing)
316321 next (T4 (Just s) (Just x2) x3 Nothing) = Yield x2 (T4 (Just s) x3 Nothing Nothing)
317322 next (T4 (Just s) (Just x2) x3 x4) = Yield x2 (T4 (Just s) x3 x4 Nothing)
323+ next _ = internalError "restream Utf32LE"
318324{-# INLINE restream #-}
319325
320326
@@ -403,7 +409,7 @@ append (Stream next0 s01 len1) (Stream next1 s02 len2) =
403409-- | /O(1)/ Returns the first character of a Text, which must be non-empty.
404410-- Subject to array fusion.
405411head :: Stream Char -> Char
406−head (Stream next s0 len) = loop_head s0
412+head (Stream next s0 _len) = loop_head s0
407413 where
408414 loop_head !s = case next s of
409415 Yield x _ -> x
@@ -413,7 +419,7 @@ head (Stream next s0 len) = loop_head s0
413419
414420-- | /O(n)/ Returns the last character of a Stream Char, which must be non-empty.
415421last :: Stream Char -> Char
416−last (Stream next s0 len) = loop0_last s0
422+last (Stream next s0 _len) = loop0_last s0
417423 where
418424 loop0_last !s = case next s of
419425 Done -> error "last: Empty list"
@@ -460,7 +466,7 @@ init (Stream next0 s0 len) = Stream next (Nothing :!: s0) (len-1)
460466
461467-- | /O(1)/ Tests whether a Stream Char is empty or not.
462468null :: Stream Char -> Bool
463−null (Stream next s0 len) = loop_null s0
469+null (Stream next s0 _len) = loop_null s0
464470 where
465471 loop_null !s = case next s of
466472 Done -> True
@@ -470,7 +476,7 @@ null (Stream next s0 len) = loop_null s0
470476
471477-- | /O(n)/ Returns the number of characters in a text.
472478length :: Stream Char -> Int
473−length (Stream next s0 len) = loop_length 0# s0
479+length (Stream next s0 _len) = loop_length 0# s0
474480 where
475481
476482 loop_length z# s = case next s of
@@ -514,6 +520,7 @@ intersperse c (Stream next0 s0 len) = Stream next (s0 :!: Nothing :!: S1) len
514520 Done -> Done
515521 Skip s' -> Skip (s' :!: Nothing :!: S2)
516522 Yield x s' -> Yield c (s' :!: Just x :!: S1)
523+ next _ = internalError "intersperse"
517524
518525-- ----------------------------------------------------------------------------
519526-- * Reducing Streams (folds)
@@ -522,7 +529,7 @@ intersperse c (Stream next0 s0 len) = Stream next (s0 :!: Nothing :!: S1) len
522529-- left-identity of the operator), and a Stream, reduces the Stream using the
523530-- binary operator, from left to right.
524531foldl :: (b -> Char -> b) -> b -> Stream Char -> b
525−foldl f z0 (Stream next s0 len) = loop_foldl z0 s0
532+foldl f z0 (Stream next s0 _len) = loop_foldl z0 s0
526533 where
527534 loop_foldl z !s = case next s of
528535 Done -> z
@@ -532,7 +539,7 @@ foldl f z0 (Stream next s0 len) = loop_foldl z0 s0
532539
533540-- | A strict version of foldl.
534541foldl' :: (b -> Char -> b) -> b -> Stream Char -> b
535−foldl' f z0 (Stream next s0 len) = loop_foldl' z0 s0
542+foldl' f z0 (Stream next s0 _len) = loop_foldl' z0 s0
536543 where
537544 loop_foldl' !z !s = case next s of
538545 Done -> z
@@ -543,7 +550,7 @@ foldl' f z0 (Stream next s0 len) = loop_foldl' z0 s0
543550-- | foldl1 is a variant of foldl that has no starting value argument,
544551-- and thus must be applied to non-empty Streams.
545552foldl1 :: (Char -> Char -> Char) -> Stream Char -> Char
546−foldl1 f (Stream next s0 len) = loop0_foldl1 s0
553+foldl1 f (Stream next s0 _len) = loop0_foldl1 s0
547554 where
548555 loop0_foldl1 !s = case next s of
549556 Skip s' -> loop0_foldl1 s'
@@ -557,7 +564,7 @@ foldl1 f (Stream next s0 len) = loop0_foldl1 s0
557564
558565-- | A strict version of foldl1.
559566foldl1' :: (Char -> Char -> Char) -> Stream Char -> Char
560−foldl1' f (Stream next s0 len) = loop0_foldl1' s0
567+foldl1' f (Stream next s0 _len) = loop0_foldl1' s0
561568 where
562569 loop0_foldl1' !s = case next s of
563570 Skip s' -> loop0_foldl1' s'
@@ -573,7 +580,7 @@ foldl1' f (Stream next s0 len) = loop0_foldl1' s0
573580-- right-identity of the operator), and a stream, reduces the stream using the
574581-- binary operator, from right to left.
575582foldr :: (Char -> b -> b) -> b -> Stream Char -> b
576−foldr f z (Stream next s0 len) = loop_foldr s0
583+foldr f z (Stream next s0 _len) = loop_foldr s0
577584 where
578585 loop_foldr !s = case next s of
579586 Done -> z
@@ -585,7 +592,7 @@ foldr f z (Stream next s0 len) = loop_foldr s0
585592-- and thust must be applied to non-empty streams.
586593-- Subject to array fusion.
587594foldr1 :: (Char -> Char -> Char) -> Stream Char -> Char
588−foldr1 f (Stream next s0 len) = loop0_foldr1 s0
595+foldr1 f (Stream next s0 _len) = loop0_foldr1 s0
589596 where
590597 loop0_foldr1 !s = case next s of
591598 Done -> error "foldr1"
@@ -606,6 +613,7 @@ concat :: [Stream Char] -> Stream Char
606613concat = L.foldr append (Stream next Done 0)
607614 where
608615 next Done = Done
616+ next _ = internalError "concat"
609617
610618-- | Map a function over a stream that results in a steram and concatenate the
611619-- results.
@@ -615,7 +623,7 @@ concatMap f = foldr (append . f) (stream empty)
615623-- | /O(n)/ any @p @xs determines if any character in the stream
616624-- @xs@ satisifes the predicate @p@.
617625any :: (Char -> Bool) -> Stream Char -> Bool
618−any p (Stream next0 s0 len) = loop_any s0
626+any p (Stream next0 s0 _len) = loop_any s0
619627 where
620628 loop_any !s = case next0 s of
621629 Done -> False
@@ -626,7 +634,7 @@ any p (Stream next0 s0 len) = loop_any s0
626634-- | /O(n)/ all @p @xs determines if all characters in the 'Text'
627635-- @xs@ satisify the predicate @p@.
628636all :: (Char -> Bool) -> Stream Char -> Bool
629−all p (Stream next0 s0 len) = loop_all s0
637+all p (Stream next0 s0 _len) = loop_all s0
630638 where
631639 loop_all !s = case next0 s of
632640 Done -> True
@@ -637,7 +645,7 @@ all p (Stream next0 s0 len) = loop_all s0
637645-- | /O(n)/ maximum returns the maximum value from a stream, which must be
638646-- non-empty.
639647maximum :: Stream Char -> Char
640−maximum (Stream next0 s0 len) = loop0_maximum s0
648+maximum (Stream next0 s0 _len) = loop0_maximum s0
641649 where
642650 loop0_maximum !s = case next0 s of
643651 Done -> errorEmptyList "maximum"
@@ -653,7 +661,7 @@ maximum (Stream next0 s0 len) = loop0_maximum s0
653661-- | /O(n)/ minimum returns the minimum value from a 'Text', which must be
654662-- non-empty.
655663minimum :: Stream Char -> Char
656−minimum (Stream next0 s0 len) = loop0_minimum s0
664+minimum (Stream next0 s0 _len) = loop0_minimum s0
657665 where
658666 loop0_minimum !s = case next0 s of
659667 Done -> errorEmptyList "minimum"
@@ -776,7 +784,7 @@ dropWhile p (Stream next0 s0 len) = Stream next (S1 :!: s0) len
776784
777785-- | /O(n)/ elem is the stream membership predicate.
778786elem :: Char -> Stream Char -> Bool
779−elem w (Stream next s0 len) = loop_elem s0
787+elem w (Stream next s0 _len) = loop_elem s0
780788 where
781789 loop_elem !s = case next s of
782790 Done -> False
@@ -793,7 +801,7 @@ elem w (Stream next s0 len) = loop_elem s0
793801-- if there is no such element.
794802
795803find :: (Char -> Bool) -> Stream Char -> Maybe Char
796−find p (Stream next s0 len) = loop_find s0
804+find p (Stream next s0 _len) = loop_find s0
797805 where
798806 loop_find !s = case next s of
799807 Done -> Nothing
@@ -826,7 +834,7 @@ filter p (Stream next0 s0 len) = Stream next s0 len
826834
827835-- | /O(1)/ stream index (subscript) operator, starting from 0.
828836index :: Stream Char -> Int -> Char
829−index (Stream next s0 len) n0
837+index (Stream next s0 _len) n0
830838 | n0 < 0 = error "Stream.(!!): negative index"
831839 | otherwise = loop_index n0 s0
832840 where
@@ -841,7 +849,7 @@ index (Stream next s0 len) n0
841849-- returns the index of the first element in the stream
842850-- satisfying the predicate.
843851findIndex :: (Char -> Bool) -> Stream Char -> Maybe Int
844−findIndex p (Stream next s0 len) = loop_findIndex 0 s0
852+findIndex p (Stream next s0 _len) = loop_findIndex 0 s0
845853 where
846854 loop_findIndex !i !s = case next s of
847855 Done -> Nothing
@@ -854,7 +862,7 @@ findIndex p (Stream next s0 len) = loop_findIndex 0 s0
854862-- element in the given stream which is equal to the query
855863-- element, or 'Nothing' if there is no such element.
856864elemIndex :: Char -> Stream Char -> Maybe Int
857−elemIndex a (Stream next s0 len) = loop_elemIndex 0 s0
865+elemIndex a (Stream next s0 _len) = loop_elemIndex 0 s0
858866 where
859867 loop_elemIndex !i !s = case next s of
860868 Done -> Nothing