on master help sign in
Fix module dependencies due to Stream.Prelude
7ce1771Harendra Kumar
benchmark/Streamly/Benchmark/Data/Stream/StreamK.hs+8−3
@@ -30,7 +30,6 @@ import qualified Prelude as P
30import qualified Data.List as List
30import qualified Data.List as List
31
31
32import qualified Streamly.Internal.Data.Stream.StreamK as S
32import qualified Streamly.Internal.Data.Stream.StreamK as S
33−import qualified Streamly.Internal.Data.Stream.Prelude as SP
34import qualified Streamly.Internal.Data.SVar as S
33import qualified Streamly.Internal.Data.SVar as S
35
34
36import Gauge (bench, nfIO, bgroup, Benchmark, defaultMain)
35import Gauge (bench, nfIO, bgroup, Benchmark, defaultMain)
@@ -119,13 +118,19 @@ sourceFromFoldableM :: S.MonadAsync m => Int -> Stream m Int
119sourceFromFoldableM n =
118sourceFromFoldableM n =
120 Prelude.foldr S.consM S.nil (Prelude.fmap return [n..n+value])
119 Prelude.foldr S.consM S.nil (Prelude.fmap return [n..n+value])
121
120
121+{-# INLINABLE concatMapFoldableWith #-}
122+concatMapFoldableWith :: (S.IsStream t, Foldable f)
123+ => (t m b -> t m b -> t m b) -> (a -> t m b) -> f a -> t m b
124+concatMapFoldableWith f g = Prelude.foldr (f . g) S.nil
125+
122{-# INLINE sourceFoldMapWith #-}
126{-# INLINE sourceFoldMapWith #-}
123sourceFoldMapWith :: Int -> Stream m Int
127sourceFoldMapWith :: Int -> Stream m Int
124−sourceFoldMapWith n = SP.concatMapFoldableWith S.serial S.yield [n..n+value]
128+sourceFoldMapWith n = concatMapFoldableWith S.serial S.yield [n..n+value]
125
129
126{-# INLINE sourceFoldMapWithM #-}
130{-# INLINE sourceFoldMapWithM #-}
127sourceFoldMapWithM :: Monad m => Int -> Stream m Int
131sourceFoldMapWithM :: Monad m => Int -> Stream m Int
132+sourceFoldMapWithM n =
128−sourceFoldMapWithM n = SP.concatMapFoldableWith S.serial (S.yieldM . return) [n..n+value]
133+ concatMapFoldableWith S.serial (S.yieldM . return) [n..n+value]
129
134
130-------------------------------------------------------------------------------
135-------------------------------------------------------------------------------
131-- Elimination
136-- Elimination
src/Streamly/Internal/Data/Array/Storable/Foreign.hs+5−27
@@ -65,8 +65,8 @@ module Streamly.Internal.Data.Array.Storable.Foreign
65 -- * Elimination
65 -- * Elimination
66
66
67 , A.toList
67 , A.toList
68− , toStream
68+ , A.toStream
69− , toStreamRev
69+ , A.toStreamRev
70 , read
70 , read
71 , ReadUState (..)
71 , ReadUState (..)
72 , unsafeRead
72 , unsafeRead
@@ -160,7 +160,6 @@ import GHC.IO (IO(..))
160import Streamly.Internal.Data.Array.Storable.Foreign.Types (Array(..), length)
160import Streamly.Internal.Data.Array.Storable.Foreign.Types (Array(..), length)
161import Streamly.Internal.Data.Fold.Types (Fold(..))
161import Streamly.Internal.Data.Fold.Types (Fold(..))
162import Streamly.Internal.Data.Stream.Serial (SerialT)
162import Streamly.Internal.Data.Stream.Serial (SerialT)
163−import Streamly.Internal.Data.Stream.StreamK.Type (IsStream)
164import Streamly.Internal.Data.Tuple.Strict (Tuple3'(..))
163import Streamly.Internal.Data.Tuple.Strict (Tuple3'(..))
165import Streamly.Internal.Data.Unfold.Types (Unfold(..))
164import Streamly.Internal.Data.Unfold.Types (Unfold(..))
166
165
@@ -170,7 +169,6 @@ import qualified Streamly.Internal.Data.Fold as FL
170import qualified Streamly.Internal.Data.Stream.Prelude as P
169import qualified Streamly.Internal.Data.Stream.Prelude as P
171import qualified Streamly.Internal.Data.Stream.Serial as Serial
170import qualified Streamly.Internal.Data.Stream.Serial as Serial
172import qualified Streamly.Internal.Data.Stream.StreamD as D
171import qualified Streamly.Internal.Data.Stream.StreamD as D
173−import qualified Streamly.Internal.Data.Stream.StreamK as K
174import qualified Streamly.Memory.Ring as RB
172import qualified Streamly.Memory.Ring as RB
175
173
176-------------------------------------------------------------------------------
174-------------------------------------------------------------------------------
@@ -206,26 +204,6 @@ fromStream = P.foldOnce A.write
206-- Elimination
204-- Elimination
207-------------------------------------------------------------------------------
205-------------------------------------------------------------------------------
208
206
209−-- | Convert an 'Array' into a stream.
210−--
211−-- /Internal/
212−{-# INLINE_EARLY toStream #-}
213−toStream :: (Monad m, K.IsStream t, Storable a) => Array a -> t m a
214−toStream = D.fromStreamD . A.toStreamD
215−-- XXX add fallback to StreamK rule
216−-- {-# RULES "Streamly.Array.read fallback to StreamK" [1]
217−-- forall a. S.readK (read a) = K.fromArray a #-}
218−
219−-- | Convert an 'Array' into a stream in reverse order.
220−--
221−-- /Internal/
222−{-# INLINE_EARLY toStreamRev #-}
223−toStreamRev :: (Monad m, IsStream t, Storable a) => Array a -> t m a
224−toStreamRev = D.fromStreamD . A.toStreamDRev
225−-- XXX add fallback to StreamK rule
226−-- {-# RULES "Streamly.Array.readRev fallback to StreamK" [1]
227−-- forall a. S.toStreamK (readRev a) = K.revFromArray a #-}
228−
229data ReadUState a = ReadUState
207data ReadUState a = ReadUState
230 {-# UNPACK #-} !(ForeignPtr a) -- foreign ptr with end of array pointer
208 {-# UNPACK #-} !(ForeignPtr a) -- foreign ptr with end of array pointer
231 {-# UNPACK #-} !(Ptr a) -- current pointer
209 {-# UNPACK #-} !(Ptr a) -- current pointer
@@ -530,7 +508,7 @@ streamTransform :: forall m a b. (MonadIO m, Storable a, Storable b)
530 => (SerialT m a -> SerialT m b) -> Array a -> m (Array b)
508 => (SerialT m a -> SerialT m b) -> Array a -> m (Array b)
531streamTransform f arr =
509streamTransform f arr =
532 P.foldOnce (A.toArrayMinChunk (alignment (undefined :: a)) (length arr))
510 P.foldOnce (A.toArrayMinChunk (alignment (undefined :: a)) (length arr))
533− $ f (toStream arr)
511+ $ f (A.toStream arr)
534
512
535-------------------------------------------------------------------------------
513-------------------------------------------------------------------------------
536-- Casts
514-- Casts
@@ -603,11 +581,11 @@ asCString arr act = do
603-- /Internal/
581-- /Internal/
604{-# INLINE fold #-}
582{-# INLINE fold #-}
605fold :: forall m a b. (MonadIO m, Storable a) => Fold m a b -> Array a -> m b
583fold :: forall m a b. (MonadIO m, Storable a) => Fold m a b -> Array a -> m b
606−fold f arr = P.foldOnce f (toStream arr :: Serial.SerialT m a)
584+fold f arr = P.foldOnce f (A.toStream arr :: Serial.SerialT m a)
607
585
608-- | Fold an array using a stream fold operation.
586-- | Fold an array using a stream fold operation.
609--
587--
610-- /Internal/
588-- /Internal/
611{-# INLINE streamFold #-}
589{-# INLINE streamFold #-}
612streamFold :: (MonadIO m, Storable a) => (SerialT m a -> m b) -> Array a -> m b
590streamFold :: (MonadIO m, Storable a) => (SerialT m a -> m b) -> Array a -> m b
613−streamFold f arr = f (toStream arr)
591+streamFold f arr = f (A.toStream arr)
src/Streamly/Internal/Data/Array/Storable/Foreign/Types.hs+23
@@ -56,6 +56,8 @@ module Streamly.Internal.Data.Array.Storable.Foreign.Types
56 , toStreamDRev
56 , toStreamDRev
57 , toStreamK
57 , toStreamK
58 , toStreamKRev
58 , toStreamKRev
59+ , toStream
60+ , toStreamRev
59 , toList
61 , toList
60
62
61 , unlines
63 , unlines
@@ -461,6 +463,27 @@ toStreamDRev arr = MA.toStreamDRev (unsafeThaw arr)
461toStreamKRev :: forall t m a. (K.IsStream t, Storable a) => Array a -> t m a
463toStreamKRev :: forall t m a. (K.IsStream t, Storable a) => Array a -> t m a
462toStreamKRev arr = MA.toStreamKRev (unsafeThaw arr)
464toStreamKRev arr = MA.toStreamKRev (unsafeThaw arr)
463
465
466+-- | Convert an 'Array' into a stream.
467+--
468+-- /Internal/
469+{-# INLINE_EARLY toStream #-}
470+toStream :: (Monad m, K.IsStream t, Storable a) => Array a -> t m a
471+toStream = D.fromStreamD . toStreamD
472+-- XXX add fallback to StreamK rule
473+-- {-# RULES "Streamly.Array.read fallback to StreamK" [1]
474+-- forall a. S.readK (read a) = K.fromArray a #-}
475+
476+-- | Convert an 'Array' into a stream in reverse order.
477+--
478+-- /Internal/
479+{-# INLINE_EARLY toStreamRev #-}
480+toStreamRev :: (Monad m, K.IsStream t, Storable a) => Array a -> t m a
481+toStreamRev = D.fromStreamD . toStreamDRev
482+
483+-- XXX add fallback to StreamK rule
484+-- {-# RULES "Streamly.Array.readRev fallback to StreamK" [1]
485+-- forall a. S.toStreamK (readRev a) = K.revFromArray a #-}
486+
464{-# INLINE_NORMAL foldl' #-}
487{-# INLINE_NORMAL foldl' #-}
465foldl' :: forall a b. Storable a => (b -> a -> b) -> b -> Array a -> b
488foldl' :: forall a b. Storable a => (b -> a -> b) -> b -> Array a -> b
466foldl' f z arr = MA.foldl' f z (unsafeThaw arr)
489foldl' f z arr = MA.foldl' f z (unsafeThaw arr)
src/Streamly/Internal/Data/List.hs+7−7
@@ -75,7 +75,7 @@ import GHC.Exts (IsList(..), IsString(..))
75import Streamly.Internal.Data.Stream.Serial (SerialT)
75import Streamly.Internal.Data.Stream.Serial (SerialT)
76import Streamly.Internal.Data.Stream.Zip (ZipSerialM)
76import Streamly.Internal.Data.Stream.Zip (ZipSerialM)
77
77
78−import qualified Streamly.Internal.Data.Stream.Prelude as P
78+import qualified Streamly.Internal.Data.Stream.IsStream as Stream
79import qualified Streamly.Internal.Data.Stream.StreamK as K
79import qualified Streamly.Internal.Data.Stream.StreamK as K
80
80
81-- We implement list as a newtype instead of a type synonym to make type
81-- We implement list as a newtype instead of a type synonym to make type
@@ -103,15 +103,15 @@ newtype List a = List { toSerial :: SerialT Identity a }
103
103
104instance (a ~ Char) => IsString (List a) where
104instance (a ~ Char) => IsString (List a) where
105 {-# INLINE fromString #-}
105 {-# INLINE fromString #-}
106− fromString = List . P.fromList
106+ fromString = List . Stream.fromList
107
107
108-- GHC versions 8.0 and below cannot derive IsList
108-- GHC versions 8.0 and below cannot derive IsList
109instance IsList (List a) where
109instance IsList (List a) where
110 type (Item (List a)) = a
110 type (Item (List a)) = a
111 {-# INLINE fromList #-}
111 {-# INLINE fromList #-}
112− fromList = List . P.fromList
112+ fromList = List . Stream.fromList
113 {-# INLINE toList #-}
113 {-# INLINE toList #-}
114− toList = runIdentity . P.toList . toSerial
114+ toList = runIdentity . Stream.toList . toSerial
115
115
116------------------------------------------------------------------------------
116------------------------------------------------------------------------------
117-- Patterns
117-- Patterns
@@ -165,15 +165,15 @@ newtype ZipList a = ZipList { toZipSerial :: ZipSerialM Identity a }
165
165
166instance (a ~ Char) => IsString (ZipList a) where
166instance (a ~ Char) => IsString (ZipList a) where
167 {-# INLINE fromString #-}
167 {-# INLINE fromString #-}
168− fromString = ZipList . P.fromList
168+ fromString = ZipList . Stream.fromList
169
169
170-- GHC versions 8.0 and below cannot derive IsList
170-- GHC versions 8.0 and below cannot derive IsList
171instance IsList (ZipList a) where
171instance IsList (ZipList a) where
172 type (Item (ZipList a)) = a
172 type (Item (ZipList a)) = a
173 {-# INLINE fromList #-}
173 {-# INLINE fromList #-}
174− fromList = ZipList . P.fromList
174+ fromList = ZipList . Stream.fromList
175 {-# INLINE toList #-}
175 {-# INLINE toList #-}
176− toList = runIdentity . P.toList . toZipSerial
176+ toList = runIdentity . Stream.toList . K.adapt . toZipSerial
177
177
178-- | Convert a 'ZipList' to a regular 'List'
178-- | Convert a 'ZipList' to a regular 'List'
179--
179--
src/Streamly/Internal/Data/Stream/IsStream.hs+1−2
@@ -102,7 +102,7 @@ module Streamly.Internal.Data.Stream.IsStream
102 , K.mfix
102 , K.mfix
103
103
104 -- ** From Containers
104 -- ** From Containers
105− , P.fromList
105+ , fromList
106 , fromListM
106 , fromListM
107 , K.fromFoldable
107 , K.fromFoldable
108 , fromFoldableM
108 , fromFoldableM
@@ -592,7 +592,6 @@ module Streamly.Internal.Data.Stream.IsStream
592where
592where
593
593
594import qualified Streamly.Internal.Data.Stream.Parallel as Par
594import qualified Streamly.Internal.Data.Stream.Parallel as Par
595−import qualified Streamly.Internal.Data.Stream.Prelude as P
596import qualified Streamly.Internal.Data.Stream.StreamD as D
595import qualified Streamly.Internal.Data.Stream.StreamD as D
597import qualified Streamly.Internal.Data.Stream.StreamK as K
596import qualified Streamly.Internal.Data.Stream.StreamK as K
598import qualified Streamly.Internal.Data.Stream.Serial as Serial
597import qualified Streamly.Internal.Data.Stream.Serial as Serial
src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs+1−1
@@ -162,7 +162,7 @@ import Streamly.Internal.Data.Stream.StreamD (fromStreamD, toStreamD)
162import Streamly.Internal.Data.Stream.StreamK (IsStream)
162import Streamly.Internal.Data.Stream.StreamK (IsStream)
163import Streamly.Internal.Data.Stream.Serial (SerialT)
163import Streamly.Internal.Data.Stream.Serial (SerialT)
164
164
165−import qualified Streamly.Internal.Data.Array.Storable.Foreign as A
165+import qualified Streamly.Internal.Data.Array.Storable.Foreign.Types as A
166import qualified Streamly.Internal.Data.Fold as FL
166import qualified Streamly.Internal.Data.Fold as FL
167import qualified Streamly.Internal.Data.Stream.Prelude as P
167import qualified Streamly.Internal.Data.Stream.Prelude as P
168import qualified Streamly.Internal.Data.Stream.StreamD as D
168import qualified Streamly.Internal.Data.Stream.StreamD as D
src/Streamly/Internal/Data/Stream/IsStream/Nesting.hs+1−1
@@ -255,7 +255,7 @@ import Streamly.Internal.Data.Tuple.Strict (Tuple'(..))
255
255
256import qualified Data.Heap as H
256import qualified Data.Heap as H
257import qualified Data.Map.Strict as Map
257import qualified Data.Map.Strict as Map
258−import qualified Streamly.Internal.Data.Array.Storable.Foreign as A
258+import qualified Streamly.Internal.Data.Array.Storable.Foreign.Types as A
259import qualified Streamly.Internal.Data.Fold as FL
259import qualified Streamly.Internal.Data.Fold as FL
260import qualified Streamly.Internal.Data.Parser.ParserK.Types as PRK
260import qualified Streamly.Internal.Data.Parser.ParserK.Types as PRK
261import qualified Streamly.Internal.Data.Parser.ParserD as PRD
261import qualified Streamly.Internal.Data.Parser.ParserD as PRD
src/Streamly/Internal/Memory/ArrayStream.hs+2−3
@@ -50,7 +50,6 @@ import qualified Streamly.Internal.Data.Array.Storable.Foreign.Types as A
50import qualified Streamly.Internal.Data.Array.Storable.Foreign.Mut.Types as MA
50import qualified Streamly.Internal.Data.Array.Storable.Foreign.Mut.Types as MA
51import qualified Streamly.Internal.Data.Stream.IsStream as S
51import qualified Streamly.Internal.Data.Stream.IsStream as S
52import qualified Streamly.Internal.Data.Stream.StreamD as D
52import qualified Streamly.Internal.Data.Stream.StreamD as D
53−import qualified Streamly.Internal.Data.Stream.Prelude as P
54
53
55-- XXX efficiently compare two streams of arrays. Two streams can have chunks
54-- XXX efficiently compare two streams of arrays. Two streams can have chunks
56-- of different sizes, we can handle that in the stream comparison abstraction.
55-- of different sizes, we can handle that in the stream comparison abstraction.
@@ -174,7 +173,7 @@ spliceArraysLenUnsafe len buffered = do
174_spliceArrays :: (MonadIO m, Storable a)
173_spliceArrays :: (MonadIO m, Storable a)
175 => SerialT m (Array a) -> m (Array a)
174 => SerialT m (Array a) -> m (Array a)
176_spliceArrays s = do
175_spliceArrays s = do
177− buffered <- P.foldr S.cons S.nil s
176+ buffered <- S.foldr S.cons S.nil s
178 len <- S.sum (S.map length buffered)
177 len <- S.sum (S.map length buffered)
179 arr <- liftIO $ MA.newArray len
178 arr <- liftIO $ MA.newArray len
180 end <- S.foldlM' writeArr (return $ MA.aEnd arr) s
179 end <- S.foldlM' writeArr (return $ MA.aEnd arr) s
@@ -192,7 +191,7 @@ _spliceArrays s = do
192_spliceArraysBuffered :: (MonadIO m, Storable a)
191_spliceArraysBuffered :: (MonadIO m, Storable a)
193 => SerialT m (Array a) -> m (Array a)
192 => SerialT m (Array a) -> m (Array a)
194_spliceArraysBuffered s = do
193_spliceArraysBuffered s = do
195− buffered <- P.foldr S.cons S.nil s
194+ buffered <- S.foldr S.cons S.nil s
196 len <- S.sum (S.map length buffered)
195 len <- S.sum (S.map length buffered)
197 A.unsafeFreeze <$> spliceArraysLenUnsafe len (S.map A.unsafeThaw s)
196 A.unsafeFreeze <$> spliceArraysLenUnsafe len (S.map A.unsafeThaw s)
198
197