on master help sign in
Annotate the precision of hints in fusions for documentation purpose.

--HG-- extra : convert_revision : bf74421ec4479dca2225700696d133f98889f4ce

commitabe55a2fe68877be27241bdb3dcca4d73142955e authorNicolas Pouillard <nicolas.pouillard@gmail.com> dateFri 6 Mar 2009, 10:53 (18 years ago) parentd7fa7d1
3 files changed+21−21
Data/Text/Fusion.hs+1−1 Data/Text/Fusion/Common.hs+19−19 Data/Text/Lazy/Fusion.hs+1−1
Data/Text/Fusion.hs+1−1
@@ -159,7 +159,7 @@ reverse (Stream next s len0)
159159-- | /O(n)/ Perform the equivalent of 'scanr' over a list, only with
160160-- the input and result reversed.
161161reverseScanr :: (Char -> Char -> Char) -> Char -> Stream Char -> Stream Char
162−reverseScanr f z0 (Stream next0 s0 len) = Stream next (S1 :!: z0 :!: s0) (len+1)
162+reverseScanr f z0 (Stream next0 s0 len) = Stream next (S1 :!: z0 :!: s0) (len+1) -- HINT maybe too low
163163 where
164164 {-# INLINE next #-}
165165 next (S1 :!: z :!: s) = Yield z (S2 :!: z :!: s)
Data/Text/Fusion/Common.hs+19−19
@@ -92,7 +92,7 @@ import qualified Prelude as P
9292import Data.Text.Fusion.Internal
9393
9494singleton :: Char -> Stream Char
95−singleton c = Stream next False 1
95+singleton c = Stream next False 1 -- HINT maybe too low
9696 where next False = Yield c True
9797 next True = Done
9898{-# INLINE singleton #-}
@@ -103,7 +103,7 @@ streamList [] = empty
103103streamList s = Stream next s unknownLength
104104 where next [] = Done
105105 next (x:xs) = Yield x xs
106− unknownLength = 8
106+ unknownLength = 8 -- random HINT
107107
108108unstreamList :: Stream a -> [a]
109109{-# INLINE unstreamList #-}
@@ -118,7 +118,7 @@ unstreamList (Stream next s0 _len) = unfold s0
118118
119119-- | /O(n)/ Adds a character to the front of a Stream Char.
120120cons :: Char -> Stream Char -> Stream Char
121−cons w (Stream next0 s0 len) = Stream next (S2 :!: s0) (len+2)
121+cons w (Stream next0 s0 len) = Stream next (S2 :!: s0) (len+2) -- HINT maybe too high
122122 where
123123 {-# INLINE next #-}
124124 next (S2 :!: s) = Yield w (S1 :!: s)
@@ -130,7 +130,7 @@ cons w (Stream next0 s0 len) = Stream next (S2 :!: s0) (len+2)
130130
131131-- | /O(n)/ Adds a character to the end of a stream.
132132snoc :: Stream Char -> Char -> Stream Char
133−snoc (Stream next0 xs0 len) w = Stream next (Just xs0) (len+2)
133+snoc (Stream next0 xs0 len) w = Stream next (Just xs0) (len+2) -- HINT maybe too high
134134 where
135135 {-# INLINE next #-}
136136 next (Just xs) = case next0 xs of
@@ -173,7 +173,7 @@ uncons :: Stream Char -> Maybe (Char, Stream Char)
173173uncons (Stream next s0 len) = loop_uncons s0
174174 where
175175 loop_uncons !s = case next s of
176− Yield x s1 -> Just (x, Stream next s1 (len-1))
176+ Yield x s1 -> Just (x, Stream next s1 (len-1)) -- HINT maybe too high
177177 Skip s' -> loop_uncons s'
178178 Done -> Nothing
179179{-# INLINE [0] uncons #-}
@@ -196,7 +196,7 @@ last (Stream next s0 _len) = loop0_last s0
196196-- | /O(1)/ Returns all characters after the head of a Stream Char, which must
197197-- be non-empty.
198198tail :: Stream Char -> Stream Char
199−tail (Stream next0 s0 len) = Stream next (False :!: s0) (len-1)
199+tail (Stream next0 s0 len) = Stream next (False :!: s0) (len-1) -- HINT maybe too high
200200 where
201201 {-# INLINE next #-}
202202 next (False :!: s) = case next0 s of
@@ -213,7 +213,7 @@ tail (Stream next0 s0 len) = Stream next (False :!: s0) (len-1)
213213-- | /O(1)/ Returns all but the last character of a Stream Char, which
214214-- must be non-empty.
215215init :: Stream Char -> Stream Char
216−init (Stream next0 s0 len) = Stream next (Nothing :!: s0) (len-1)
216+init (Stream next0 s0 len) = Stream next (Nothing :!: s0) (len-1) -- HINT maybe too high
217217 where
218218 {-# INLINE next #-}
219219 next (Nothing :!: s) = case next0 s of
@@ -252,7 +252,7 @@ lengthI (Stream next s0 _len) = loop_length 0 s0
252252-- | /O(n)/ 'map' @f @xs is the Stream Char obtained by applying @f@ to each element of
253253-- @xs@.
254254map :: (Char -> Char) -> Stream Char -> Stream Char
255−map f (Stream next0 s0 len) = Stream next s0 len
255+map f (Stream next0 s0 len) = Stream next s0 len -- HINT depends on f
256256 where
257257 {-# INLINE next #-}
258258 next !s = case next0 s of
@@ -269,7 +269,7 @@ map f (Stream next0 s0 len) = Stream next s0 len
269269-- | /O(n)/ Take a character and place it between each of the
270270-- characters of a 'Stream Char'.
271271intersperse :: Char -> Stream Char -> Stream Char
272−intersperse c (Stream next0 s0 len) = Stream next (s0 :!: Nothing :!: S1) len
272+intersperse c (Stream next0 s0 len) = Stream next (s0 :!: Nothing :!: S1) len -- HINT maybe too low
273273 where
274274 {-# INLINE next #-}
275275 next (s :!: Nothing :!: S1) = case next0 s of
@@ -448,7 +448,7 @@ minimum (Stream next0 s0 _len) = loop0_minimum s0
448448-- * Building streams
449449
450450scanl :: (Char -> Char -> Char) -> Char -> Stream Char -> Stream Char
451−scanl f z0 (Stream next0 s0 len) = Stream next (S1 :!: z0 :!: s0) (len+1)
451+scanl f z0 (Stream next0 s0 len) = Stream next (S1 :!: z0 :!: s0) (len+1) -- HINT maybe too low
452452 where
453453 {-# INLINE next #-}
454454 next (S1 :!: z :!: s) = Yield z (S2 :!: z :!: s)
@@ -470,7 +470,7 @@ scanl f z0 (Stream next0 s0 len) = Stream next (S1 :!: z0 :!: s0) (len+1)
470470-- return a final value for the accumulator, because the nature of
471471-- streams precludes it.
472472mapAccumL :: (a -> b -> (a,b)) -> a -> Stream b -> Stream b
473−mapAccumL f z0 (Stream next0 s0 len) = Stream next (s0 :!: z0) len
473+mapAccumL f z0 (Stream next0 s0 len) = Stream next (s0 :!: z0) len -- HINT depends on f
474474 where
475475 {-# INLINE next #-}
476476 next (s :!: z) = case next0 s of
@@ -486,7 +486,7 @@ mapAccumL f z0 (Stream next0 s0 len) = Stream next (s0 :!: z0) len
486486replicate :: Int -> Char -> Stream Char
487487replicate n c
488488 | n < 0 = empty
489− | otherwise = Stream next 0 n
489+ | otherwise = Stream next 0 n -- HINT maybe too low
490490 where
491491 {-# INLINE next #-}
492492 next i | i >= n = Done
@@ -500,7 +500,7 @@ replicate n c
500500-- (a,b), in which case, a is the next Char in the string, and b is
501501-- the seed value for further production.
502502unfoldr :: (a -> Maybe (Char,a)) -> a -> Stream Char
503−unfoldr f s0 = Stream next s0 1
503+unfoldr f s0 = Stream next s0 1 -- HINT maybe too low
504504 where
505505 {-# INLINE next #-}
506506 next !s = case f s of
@@ -514,7 +514,7 @@ unfoldr f s0 = Stream next s0 1
514514-- 'unfoldr' when the length of the result is known.
515515unfoldrNI :: Integral a => a -> (b -> Maybe (Char,b)) -> b -> Stream Char
516516unfoldrNI n f s0 | n < 0 = empty
517− | otherwise = Stream next (0 :!: s0) (fromIntegral (n*2))
517+ | otherwise = Stream next (0 :!: s0) (fromIntegral (n*2)) -- HINT maybe too high
518518 where
519519 {-# INLINE next #-}
520520 next (z :!: s) = case f s of
@@ -530,7 +530,7 @@ unfoldrNI n f s0 | n < 0 = empty
530530-- stream of length @n@, or the stream itself if @n@ is greater than the
531531-- length of the stream.
532532take :: Integral a => a -> Stream Char -> Stream Char
533−take n0 (Stream next0 s0 len) = Stream next (n0 :!: s0) len
533+take n0 (Stream next0 s0 len) = Stream next (n0 :!: s0) (min 0 (len - fromIntegral n0)) -- HINT maybe too high
534534 where
535535 {-# INLINE next #-}
536536 next (n :!: s) | n <= 0 = Done
@@ -545,7 +545,7 @@ take n0 (Stream next0 s0 len) = Stream next (n0 :!: s0) len
545545-- length of the stream.
546546drop :: Integral a => a -> Stream Char -> Stream Char
547547drop n0 (Stream next0 s0 len) =
548− Stream next (Just ((max 0 n0)) :!: s0) (len - fromIntegral n0)
548+ Stream next (Just ((max 0 n0)) :!: s0) (len - fromIntegral n0) -- HINT maybe too high
549549 where
550550 {-# INLINE next #-}
551551 next (Just !n :!: s)
@@ -563,7 +563,7 @@ drop n0 (Stream next0 s0 len) =
563563-- | takeWhile, applied to a predicate @p@ and a stream, returns the
564564-- longest prefix (possibly empty) of elements that satisfy p.
565565takeWhile :: (Char -> Bool) -> Stream Char -> Stream Char
566−takeWhile p (Stream next0 s0 len) = Stream next s0 len
566+takeWhile p (Stream next0 s0 len) = Stream next s0 len -- HINT maybe too high
567567 where
568568 {-# INLINE next #-}
569569 next !s = case next0 s of
@@ -575,7 +575,7 @@ takeWhile p (Stream next0 s0 len) = Stream next s0 len
575575
576576-- | dropWhile @p @xs returns the suffix remaining after takeWhile @p @xs.
577577dropWhile :: (Char -> Bool) -> Stream Char -> Stream Char
578−dropWhile p (Stream next0 s0 len) = Stream next (S1 :!: s0) len
578+dropWhile p (Stream next0 s0 len) = Stream next (S1 :!: s0) len -- HINT maybe too high
579579 where
580580 {-# INLINE next #-}
581581 next (S1 :!: s) = case next0 s of
@@ -642,7 +642,7 @@ find p (Stream next s0 _len) = loop_find s0
642642-- returns a stream containing those characters that satisfy the
643643-- predicate.
644644filter :: (Char -> Bool) -> Stream Char -> Stream Char
645−filter p (Stream next0 s0 len) = Stream next s0 len
645+filter p (Stream next0 s0 len) = Stream next s0 len -- HINT maybe too high
646646 where
647647 {-# INLINE next #-}
648648 next !s = case next0 s of
Data/Text/Lazy/Fusion.hs+1−1
@@ -33,7 +33,7 @@ default(Int64)
3333
3434-- | /O(n)/ Convert a 'Text' into a 'Stream Char'.
3535stream :: Text -> Stream Char
36−stream text = Stream next (text :!: 0) 4
36+stream text = Stream next (text :!: 0) 4 -- random HINT
3737 where
3838 next (Empty :!: _) = Done
3939 next (txt@(Chunk t@(I.Text _ _ len) ts) :!: i)