Commits

Nicolas Pouillard committed deaf0b3

Annotate the precision of hints in fusions for documentation purpose.

Comments (0)

Files changed (3)

Data/Text/Fusion.hs

 -- | /O(n)/ Perform the equivalent of 'scanr' over a list, only with
 -- the input and result reversed.
 reverseScanr :: (Char -> Char -> Char) -> Char -> Stream Char -> Stream Char
-reverseScanr f z0 (Stream next0 s0 len) = Stream next (S1 :!: z0 :!: s0) (len+1)
+reverseScanr f z0 (Stream next0 s0 len) = Stream next (S1 :!: z0 :!: s0) (len+1) -- HINT maybe too low
   where
     {-# INLINE next #-}
     next (S1 :!: z :!: s) = Yield z (S2 :!: z :!: s)

Data/Text/Fusion/Common.hs

 import Data.Text.Fusion.Internal
 
 singleton :: Char -> Stream Char
-singleton c = Stream next False 1
+singleton c = Stream next False 1 -- HINT maybe too low
     where next False = Yield c True
           next True  = Done
 {-# INLINE singleton #-}
 streamList s  = Stream next s unknownLength
     where next []       = Done
           next (x:xs)   = Yield x xs
-          unknownLength = 8
+          unknownLength = 8 -- random HINT
 
 unstreamList :: Stream a -> [a]
 {-# INLINE unstreamList #-}
 
 -- | /O(n)/ Adds a character to the front of a Stream Char.
 cons :: Char -> Stream Char -> Stream Char
-cons w (Stream next0 s0 len) = Stream next (S2 :!: s0) (len+2)
+cons w (Stream next0 s0 len) = Stream next (S2 :!: s0) (len+2) -- HINT maybe too high
     where
       {-# INLINE next #-}
       next (S2 :!: s) = Yield w (S1 :!: s)
 
 -- | /O(n)/ Adds a character to the end of a stream.
 snoc :: Stream Char -> Char -> Stream Char
-snoc (Stream next0 xs0 len) w = Stream next (Just xs0) (len+2)
+snoc (Stream next0 xs0 len) w = Stream next (Just xs0) (len+2) -- HINT maybe too high
   where
     {-# INLINE next #-}
     next (Just xs) = case next0 xs of
 uncons (Stream next s0 len) = loop_uncons s0
     where
       loop_uncons !s = case next s of
-                         Yield x s1 -> Just (x, Stream next s1 (len-1))
+                         Yield x s1 -> Just (x, Stream next s1 (len-1)) -- HINT maybe too high
                          Skip s'    -> loop_uncons s'
                          Done       -> Nothing
 {-# INLINE [0] uncons #-}
 -- | /O(1)/ Returns all characters after the head of a Stream Char, which must
 -- be non-empty.
 tail :: Stream Char -> Stream Char
-tail (Stream next0 s0 len) = Stream next (False :!: s0) (len-1)
+tail (Stream next0 s0 len) = Stream next (False :!: s0) (len-1) -- HINT maybe too high
     where
       {-# INLINE next #-}
       next (False :!: s) = case next0 s of
 -- | /O(1)/ Returns all but the last character of a Stream Char, which
 -- must be non-empty.
 init :: Stream Char -> Stream Char
-init (Stream next0 s0 len) = Stream next (Nothing :!: s0) (len-1)
+init (Stream next0 s0 len) = Stream next (Nothing :!: s0) (len-1) -- HINT maybe too high
     where
       {-# INLINE next #-}
       next (Nothing :!: s) = case next0 s of
 -- | /O(n)/ 'map' @f @xs is the Stream Char obtained by applying @f@ to each element of
 -- @xs@.
 map :: (Char -> Char) -> Stream Char -> Stream Char
-map f (Stream next0 s0 len) = Stream next s0 len
+map f (Stream next0 s0 len) = Stream next s0 len -- HINT depends on f
     where
       {-# INLINE next #-}
       next !s = case next0 s of
 -- | /O(n)/ Take a character and place it between each of the
 -- characters of a 'Stream Char'.
 intersperse :: Char -> Stream Char -> Stream Char
-intersperse c (Stream next0 s0 len) = Stream next (s0 :!: Nothing :!: S1) len
+intersperse c (Stream next0 s0 len) = Stream next (s0 :!: Nothing :!: S1) len -- HINT maybe too low
     where
       {-# INLINE next #-}
       next (s :!: Nothing :!: S1) = case next0 s of
 -- * Building streams
 
 scanl :: (Char -> Char -> Char) -> Char -> Stream Char -> Stream Char
-scanl f z0 (Stream next0 s0 len) = Stream next (S1 :!: z0 :!: s0) (len+1)
+scanl f z0 (Stream next0 s0 len) = Stream next (S1 :!: z0 :!: s0) (len+1) -- HINT maybe too low
   where
     {-# INLINE next #-}
     next (S1 :!: z :!: s) = Yield z (S2 :!: z :!: s)
 -- return a final value for the accumulator, because the nature of
 -- streams precludes it.
 mapAccumL :: (a -> b -> (a,b)) -> a -> Stream b -> Stream b
-mapAccumL f z0 (Stream next0 s0 len) = Stream next (s0 :!: z0) len
+mapAccumL f z0 (Stream next0 s0 len) = Stream next (s0 :!: z0) len -- HINT depends on f
   where
     {-# INLINE next #-}
     next (s :!: z) = case next0 s of
 replicate :: Int -> Char -> Stream Char
 replicate n c
     | n < 0     = empty
-    | otherwise = Stream next 0 n
+    | otherwise = Stream next 0 n -- HINT maybe too low
   where
     {-# INLINE next #-}
     next i | i >= n    = Done
 -- (a,b), in which case, a is the next Char in the string, and b is
 -- the seed value for further production.
 unfoldr :: (a -> Maybe (Char,a)) -> a -> Stream Char
-unfoldr f s0 = Stream next s0 1
+unfoldr f s0 = Stream next s0 1 -- HINT maybe too low
     where
       {-# INLINE next #-}
       next !s = case f s of
 -- 'unfoldr' when the length of the result is known.
 unfoldrNI :: Integral a => a -> (b -> Maybe (Char,b)) -> b -> Stream Char
 unfoldrNI n f s0 | n <  0    = empty
-                | otherwise = Stream next (0 :!: s0) (fromIntegral (n*2))
+                 | otherwise = Stream next (0 :!: s0) (fromIntegral (n*2)) -- HINT maybe too high
     where
       {-# INLINE next #-}
       next (z :!: s) = case f s of
 -- stream of length @n@, or the stream itself if @n@ is greater than the
 -- length of the stream.
 take :: Integral a => a -> Stream Char -> Stream Char
-take n0 (Stream next0 s0 len) = Stream next (n0 :!: s0) len
+take n0 (Stream next0 s0 len) = Stream next (n0 :!: s0) (min 0 (len - fromIntegral n0)) -- HINT maybe too high
     where
       {-# INLINE next #-}
       next (n :!: s) | n <= 0    = Done
 -- length of the stream.
 drop :: Integral a => a -> Stream Char -> Stream Char
 drop n0 (Stream next0 s0 len) =
-    Stream next (Just ((max 0 n0)) :!: s0) (len - fromIntegral n0)
+    Stream next (Just ((max 0 n0)) :!: s0) (len - fromIntegral n0) -- HINT maybe too high
   where
     {-# INLINE next #-}
     next (Just !n :!: s)
 -- | takeWhile, applied to a predicate @p@ and a stream, returns the
 -- longest prefix (possibly empty) of elements that satisfy p.
 takeWhile :: (Char -> Bool) -> Stream Char -> Stream Char
-takeWhile p (Stream next0 s0 len) = Stream next s0 len
+takeWhile p (Stream next0 s0 len) = Stream next s0 len -- HINT maybe too high
     where
       {-# INLINE next #-}
       next !s = case next0 s of
 
 -- | dropWhile @p @xs returns the suffix remaining after takeWhile @p @xs.
 dropWhile :: (Char -> Bool) -> Stream Char -> Stream Char
-dropWhile p (Stream next0 s0 len) = Stream next (S1 :!: s0) len
+dropWhile p (Stream next0 s0 len) = Stream next (S1 :!: s0) len -- HINT maybe too high
     where
     {-# INLINE next #-}
     next (S1 :!: s)  = case next0 s of
 -- returns a stream containing those characters that satisfy the
 -- predicate.
 filter :: (Char -> Bool) -> Stream Char -> Stream Char
-filter p (Stream next0 s0 len) = Stream next s0 len
+filter p (Stream next0 s0 len) = Stream next s0 len -- HINT maybe too high
   where
     {-# INLINE next #-}
     next !s = case next0 s of

Data/Text/Lazy/Fusion.hs

 
 -- | /O(n)/ Convert a 'Text' into a 'Stream Char'.
 stream :: Text -> Stream Char
-stream text = Stream next (text :!: 0) 4
+stream text = Stream next (text :!: 0) 4 -- random HINT
   where
     next (Empty :!: _) = Done
     next (txt@(Chunk t@(I.Text _ _ len) ts) :!: i)