on master help sign in
Move and rename some types to match their uses
381d7c2Bryan O'Sullivan
Data/Text/Internal/Fusion/Common.hs+28−18
@@ -187,6 +187,9 @@ cons !w (Stream next0 s0 len) = Stream next (C1 s0) (len+1)
187 Yield x s' -> Yield x (C0 s')
187 Yield x s' -> Yield x (C0 s')
188{-# INLINE [0] cons #-}
188{-# INLINE [0] cons #-}
189
189
190+data Snoc a = N
191+ | J !a
192+
190-- | /O(n)/ Adds a character to the end of a stream.
193-- | /O(n)/ Adds a character to the end of a stream.
191snoc :: Stream Char -> Char -> Stream Char
194snoc :: Stream Char -> Char -> Stream Char
192snoc (Stream next0 xs0 len) w = Stream next (J xs0) (len+1)
195snoc (Stream next0 xs0 len) w = Stream next (J xs0) (len+1)
@@ -762,24 +765,27 @@ take n0 (Stream next0 s0 len) =
762 Yield x s' -> Yield x ((n-1) :*: s')
765 Yield x s' -> Yield x ((n-1) :*: s')
763{-# INLINE [0] take #-}
766{-# INLINE [0] take #-}
764
767
768+data Drop a s = NS !s
769+ | JS !a !s
770+
765-- | /O(n)/ drop n, applied to a stream, returns the suffix of the
771-- | /O(n)/ drop n, applied to a stream, returns the suffix of the
766-- stream after the first @n@ characters, or the empty stream if @n@
772-- stream after the first @n@ characters, or the empty stream if @n@
767-- is greater than the length of the stream.
773-- is greater than the length of the stream.
768drop :: Integral a => a -> Stream Char -> Stream Char
774drop :: Integral a => a -> Stream Char -> Stream Char
769drop n0 (Stream next0 s0 len) =
775drop n0 (Stream next0 s0 len) =
770− Stream next (J n0 :*: s0) (len - fromIntegral (max 0 n0))
776+ Stream next (JS n0 s0) (len - fromIntegral (max 0 n0))
771 where
777 where
772 {-# INLINE next #-}
778 {-# INLINE next #-}
773− next (J n :*: s)
779+ next (JS n s)
774− | n <= 0 = Skip (N :*: s)
780+ | n <= 0 = Skip (NS s)
775 | otherwise = case next0 s of
781 | otherwise = case next0 s of
776 Done -> Done
782 Done -> Done
777− Skip s' -> Skip (J n :*: s')
783+ Skip s' -> Skip (JS n s')
778− Yield _ s' -> Skip (J (n-1) :*: s')
784+ Yield _ s' -> Skip (JS (n-1) s')
779− next (N :*: s) = case next0 s of
785+ next (NS s) = case next0 s of
780 Done -> Done
786 Done -> Done
781− Skip s' -> Skip (N :*: s')
787+ Skip s' -> Skip (NS s')
782− Yield x s' -> Yield x (N :*: s')
788+ Yield x s' -> Yield x (NS s')
783{-# INLINE [0] drop #-}
789{-# INLINE [0] drop #-}
784
790
785-- | takeWhile, applied to a predicate @p@ and a stream, returns the
791-- | takeWhile, applied to a predicate @p@ and a stream, returns the
@@ -915,21 +921,25 @@ findIndicesI p (Stream next s0 _len) = loop_findIndex 0 s0
915-------------------------------------------------------------------------------
921-------------------------------------------------------------------------------
916-- * Zipping
922-- * Zipping
917
923
924+-- | Strict triple.
925+data Zip a b m = Z1 !a !b
926+ | Z2 !a !b !m
927+
918-- | zipWith generalises 'zip' by zipping with the function given as
928-- | zipWith generalises 'zip' by zipping with the function given as
919-- the first argument, instead of a tupling function.
929-- the first argument, instead of a tupling function.
920zipWith :: (a -> a -> b) -> Stream a -> Stream a -> Stream b
930zipWith :: (a -> a -> b) -> Stream a -> Stream a -> Stream b
921zipWith f (Stream next0 sa0 len1) (Stream next1 sb0 len2) =
931zipWith f (Stream next0 sa0 len1) (Stream next1 sb0 len2) =
922− Stream next (T3 sa0 sb0 N) (smaller len1 len2)
932+ Stream next (Z1 sa0 sb0) (smaller len1 len2)
923 where
933 where
924− next (T3 sa sb N) = case next0 sa of
934+ next (Z1 sa sb) = case next0 sa of
925− Done -> Done
935+ Done -> Done
926− Skip sa' -> Skip (T3 sa' sb N)
936+ Skip sa' -> Skip (Z1 sa' sb)
927− Yield a sa' -> Skip (T3 sa' sb (J a))
937+ Yield a sa' -> Skip (Z2 sa' sb a)
928−
938+
929− next (T3 sa' sb (J a)) = case next1 sb of
939+ next (Z2 sa' sb a) = case next1 sb of
930− Done -> Done
940+ Done -> Done
931− Skip sb' -> Skip (T3 sa' sb' (J a))
941+ Skip sb' -> Skip (Z2 sa' sb' a)
932− Yield b sb' -> Yield (f a b) (T3 sa' sb' N)
942+ Yield b sb' -> Yield (f a b) (Z1 sa' sb')
933{-# INLINE [0] zipWith #-}
943{-# INLINE [0] zipWith #-}
934
944
935-- | /O(n)/ The 'countCharI' function returns the number of times the
945-- | /O(n)/ The 'countCharI' function returns the number of times the
Data/Text/Internal/Fusion/Types.hs−12
@@ -20,10 +20,7 @@
20module Data.Text.Internal.Fusion.Types
20module Data.Text.Internal.Fusion.Types
21 (
21 (
22 CC(..)
22 CC(..)
23− , M(..)
24− , M8
25 , PairS(..)
23 , PairS(..)
26− , T3(..)
27 , Scan(..)
24 , Scan(..)
28 , RS(..)
25 , RS(..)
29 , Step(..)
26 , Step(..)
@@ -38,12 +35,6 @@ import Data.Word (Word8)
38-- | Specialised tuple for case conversion.
35-- | Specialised tuple for case conversion.
39data CC s = CC !s {-# UNPACK #-} !Char {-# UNPACK #-} !Char
36data CC s = CC !s {-# UNPACK #-} !Char {-# UNPACK #-} !Char
40
37
41−-- | Specialised, strict Maybe-like type.
42−data M a = N
43− | J !a
44−
45−type M8 = M Word8
46−
47-- | Restreaming state.
38-- | Restreaming state.
48data RS s
39data RS s
49 = RS0 !s
40 = RS0 !s
@@ -56,9 +47,6 @@ data PairS a b = !a :*: !b
56 -- deriving (Eq, Ord, Show)
47 -- deriving (Eq, Ord, Show)
57infixl 2 :*:
48infixl 2 :*:
58
49
59−-- | Strict triple.
60−data T3 a b c = T3 !a !b !c
61−
62-- | An intermediate result in a scan.
50-- | An intermediate result in a scan.
63data Scan s = Scan1 {-# UNPACK #-} !Char !s
51data Scan s = Scan1 {-# UNPACK #-} !Char !s
64 | Scan2 {-# UNPACK #-} !Char !s
52 | Scan2 {-# UNPACK #-} !Char !s