@@ -75,6 +75,7 @@ module Data.Text.Fusion
7575 , replicate
7676 , unfoldr
7777 , unfoldrN
78+ , unfoldrN64
7879
7980 -- * Substrings
8081 -- ** Breaking strings
@@ -104,8 +105,8 @@ module Data.Text.Fusion
104105 , zipWith
105106 ) where
106107
107−import Prelude (Bool(..), Char, Either(..), Eq(..), Maybe(..), Monad(..),
108− Num(..), Ord(..), String, ($), (++), (.), (&&),
108+import Prelude (Bool(..), Char, Either(..), Eq(..), Integral, Maybe(..),
109+ Monad(..), Num(..), Ord(..), String, ($), (++), (.), (&&),
109110 fromIntegral, otherwise)
110111import qualified Data.List as L
111112import GHC.Exts (Int(..), (+#))
@@ -641,15 +642,33 @@ unfoldr f s0 = Stream next s0 1
641642-- value. However, the length of the result is limited by the
642643-- first argument to 'unfoldrN'. This function is more efficient than
643644-- 'unfoldr' when the length of the result is known.
644−unfoldrN :: Int -> (a -> Maybe (Char,a)) -> a -> Stream Char
645−unfoldrN n f s0 | n < 0 = empty
646− | otherwise = Stream next (0 :!: s0) (n*2)
645+unfoldrI :: Integral a => a -> (b -> Maybe (Char,b)) -> b -> Stream Char
646+unfoldrI n f s0 | n < 0 = empty
647+ | otherwise = Stream next (0 :!: s0) (fromIntegral (n*2))
647648 where
648649 {-# INLINE next #-}
649650 next (z :!: s) = case f s of
650651 Nothing -> Done
651652 Just (w, s') | z >= n -> Done
652653 | otherwise -> Yield w ((z + 1) :!: s')
654+{-# INLINE unfoldrI #-}
655+
656+-- | /O(n)/ Like 'unfoldr', 'unfoldrN' builds a stream from a seed
657+-- value. However, the length of the result is limited by the
658+-- first argument to 'unfoldrN'. This function is more efficient than
659+-- 'unfoldr' when the length of the result is known.
660+unfoldrN :: Int -> (a -> Maybe (Char,a)) -> a -> Stream Char
661+unfoldrN n = unfoldrI (fromIntegral n :: Int)
662+{-# INLINE [0] unfoldrN #-}
663+
664+-- | /O(n)/ Like 'unfoldr', 'unfoldrN64' builds a stream from a seed
665+-- value. However, the length of the result is limited by the
666+-- first argument to 'unfoldrN64'. This function is more efficient than
667+-- 'unfoldr' when the length of the result is known.
668+unfoldrN64 :: Int64 -> (a -> Maybe (Char,a)) -> a -> Stream Char
669+unfoldrN64 n = unfoldrI (fromIntegral n :: Int64)
670+{-# INLINE [0] unfoldrN64 #-}
671+
653672-------------------------------------------------------------------------------
654673-- * Substreams
655674