on master help sign in
Remove deepseq and mtl dependencies from streamly-core
449d48dHarendra Kumar
benchmark/Streamly/Benchmark/Data/Array.hs+6
@@ -1,4 +1,5 @@
1{-# OPTIONS_GHC -Wno-deprecations #-}
1{-# OPTIONS_GHC -Wno-deprecations #-}
2+{-# OPTIONS_GHC -Wno-orphans #-}
2
3
3{-# LANGUAGE CPP #-}
4{-# LANGUAGE CPP #-}
4
5
@@ -11,10 +12,15 @@ import qualified GHC.Exts as GHC
11
12
12-- import qualified Streamly.Data.Array as A
13-- import qualified Streamly.Data.Array as A
13import qualified Streamly.Internal.Data.Array as A
14import qualified Streamly.Internal.Data.Array as A
15+
14type Stream = A.Array
16type Stream = A.Array
15
17
16#include "Streamly/Benchmark/Data/Array/Common.hs"
18#include "Streamly/Benchmark/Data/Array/Common.hs"
17
19
20+instance NFData (A.Array a) where
21+ {-# INLINE rnf #-}
22+ rnf _ = ()
23+
18-------------------------------------------------------------------------------
24-------------------------------------------------------------------------------
19-- Benchmark helpers
25-- Benchmark helpers
20-------------------------------------------------------------------------------
26-------------------------------------------------------------------------------
benchmark/Streamly/Benchmark/Data/Array/Generic.hs+6
@@ -1,4 +1,5 @@
1{-# OPTIONS_GHC -Wno-deprecations #-}
1{-# OPTIONS_GHC -Wno-deprecations #-}
2+{-# OPTIONS_GHC -Wno-orphans #-}
2
3
3{-# LANGUAGE CPP #-}
4{-# LANGUAGE CPP #-}
4
5
@@ -8,10 +9,15 @@ import Control.DeepSeq (deepseq)
8
9
9import qualified Streamly.Internal.Data.Array.Generic as IA
10import qualified Streamly.Internal.Data.Array.Generic as IA
10import qualified Streamly.Internal.Data.Array.Generic as A
11import qualified Streamly.Internal.Data.Array.Generic as A
12+
11type Stream = A.Array
13type Stream = A.Array
12
14
13#include "Streamly/Benchmark/Data/Array/Common.hs"
15#include "Streamly/Benchmark/Data/Array/Common.hs"
14
16
17+instance NFData a => NFData (A.Array a) where
18+ {-# INLINE rnf #-}
19+ rnf = A.foldl' (\_ x -> rnf x) ()
20+
15-------------------------------------------------------------------------------
21-------------------------------------------------------------------------------
16-- Benchmark helpers
22-- Benchmark helpers
17-------------------------------------------------------------------------------
23-------------------------------------------------------------------------------
benchmark/Streamly/Benchmark/Data/Array/Mut.hs+5
@@ -1,4 +1,5 @@
1{-# OPTIONS_GHC -Wno-deprecations #-}
1{-# OPTIONS_GHC -Wno-deprecations #-}
2+{-# OPTIONS_GHC -Wno-orphans #-}
2
3
3-- |
4-- |
4-- Module : Streamly.Benchmark.Data.Array.Unboxed.Mut
5-- Module : Streamly.Benchmark.Data.Array.Unboxed.Mut
@@ -53,6 +54,10 @@ import Streamly.Benchmark.Common hiding (benchPureSrc)
53
54
54type Stream = MArray.Array
55type Stream = MArray.Array
55
56
57+instance NFData (MArray.Array a) where
58+ {-# INLINE rnf #-}
59+ rnf _ = ()
60+
56-------------------------------------------------------------------------------
61-------------------------------------------------------------------------------
57-- Benchmark helpers
62-- Benchmark helpers
58-------------------------------------------------------------------------------
63-------------------------------------------------------------------------------
benchmark/Streamly/Benchmark/Data/Fold.hs+12−1
@@ -6,16 +6,18 @@
6-- Maintainer : streamly@composewell.com
6-- Maintainer : streamly@composewell.com
7
7
8{-# LANGUAGE FlexibleContexts #-}
8{-# LANGUAGE FlexibleContexts #-}
9+{-# LANGUAGE FlexibleInstances #-}
9{-# LANGUAGE RankNTypes #-}
10{-# LANGUAGE RankNTypes #-}
10{-# LANGUAGE ScopedTypeVariables #-}
11{-# LANGUAGE ScopedTypeVariables #-}
11{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
12{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
13+{-# OPTIONS_GHC -Wno-orphans #-}
12
14
13module Main (main) where
15module Main (main) where
14
16
15import Control.DeepSeq (NFData(..))
17import Control.DeepSeq (NFData(..))
16import Control.Monad (when)
18import Control.Monad (when)
17import Control.Monad.IO.Class (MonadIO(..))
19import Control.Monad.IO.Class (MonadIO(..))
18−import Data.Functor.Identity (Identity)
20+import Data.Functor.Identity (Identity(..))
19import Data.Map.Strict (Map)
21import Data.Map.Strict (Map)
20import Data.Hashable (Hashable)
22import Data.Hashable (Hashable)
21import Data.HashMap.Strict (HashMap)
23import Data.HashMap.Strict (HashMap)
@@ -27,6 +29,7 @@ import Streamly.Internal.Data.Stream (Stream)
27import Streamly.Internal.Data.Fold (Fold(..))
29import Streamly.Internal.Data.Fold (Fold(..))
28import Streamly.Internal.Data.IsMap.HashMap ()
30import Streamly.Internal.Data.IsMap.HashMap ()
29
31
32+import qualified Streamly.Internal.Data.Array.Mut.Type as MArray
30import qualified Streamly.Internal.Data.Fold as FL
33import qualified Streamly.Internal.Data.Fold as FL
31import qualified Streamly.Internal.Data.Fold.Extra as FL
34import qualified Streamly.Internal.Data.Fold.Extra as FL
32import qualified Streamly.Internal.Data.Unfold as Unfold
35import qualified Streamly.Internal.Data.Unfold as Unfold
@@ -288,6 +291,14 @@ unfoldMany val =
288moduleName :: String
291moduleName :: String
289moduleName = "Data.Fold"
292moduleName = "Data.Fold"
290
293
294+instance NFData (MArray.Array a) where
295+ {-# INLINE rnf #-}
296+ rnf _ = ()
297+
298+instance NFData a => NFData (Stream Identity a) where
299+ {-# INLINE rnf #-}
300+ rnf xs = runIdentity $ Stream.fold (FL.foldl' (\_ x -> rnf x) ()) xs
301+
291o_1_space_serial_elimination :: Int -> [Benchmark]
302o_1_space_serial_elimination :: Int -> [Benchmark]
292o_1_space_serial_elimination value =
303o_1_space_serial_elimination value =
293 [ bgroup "elimination"
304 [ bgroup "elimination"
benchmark/Streamly/Benchmark/Data/Stream/Eliminate.hs+6
@@ -6,9 +6,11 @@
6
6
7{-# LANGUAGE CPP #-}
7{-# LANGUAGE CPP #-}
8{-# LANGUAGE FlexibleContexts #-}
8{-# LANGUAGE FlexibleContexts #-}
9+{-# LANGUAGE FlexibleInstances #-}
9{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE RankNTypes #-}
11{-# LANGUAGE RankNTypes #-}
11
12
13+{-# OPTIONS_GHC -Wno-orphans #-}
12#ifdef USE_PRELUDE
14#ifdef USE_PRELUDE
13{-# OPTIONS_GHC -Wno-deprecations #-}
15{-# OPTIONS_GHC -Wno-deprecations #-}
14#endif
16#endif
@@ -252,6 +254,10 @@ o_n_space_elimination_foldable value =
252-- Stream folds
254-- Stream folds
253-------------------------------------------------------------------------------
255-------------------------------------------------------------------------------
254
256
257+instance NFData a => NFData (Stream Identity a) where
258+ {-# INLINE rnf #-}
259+ rnf xs = runIdentity $ S.fold (Fold.foldl' (\_ x -> rnf x) ()) xs
260+
255{-# INLINE benchPureSink #-}
261{-# INLINE benchPureSink #-}
256benchPureSink :: NFData b
262benchPureSink :: NFData b
257 => Int -> String -> (Stream Identity Int -> b) -> Benchmark
263 => Int -> String -> (Stream Identity Int -> b) -> Benchmark
benchmark/Streamly/Benchmark/Data/Stream/Generate.hs+9−1
@@ -6,19 +6,23 @@
6
6
7{-# LANGUAGE CPP #-}
7{-# LANGUAGE CPP #-}
8{-# LANGUAGE FlexibleContexts #-}
8{-# LANGUAGE FlexibleContexts #-}
9+{-# LANGUAGE FlexibleInstances #-}
9{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE RankNTypes #-}
11{-# LANGUAGE RankNTypes #-}
11
12
13+{-# OPTIONS_GHC -Wno-orphans #-}
12#ifdef USE_PRELUDE
14#ifdef USE_PRELUDE
13{-# OPTIONS_GHC -Wno-deprecations #-}
15{-# OPTIONS_GHC -Wno-deprecations #-}
14#endif
16#endif
15
17
16module Stream.Generate (benchmarks) where
18module Stream.Generate (benchmarks) where
17
19
20+import Control.DeepSeq (NFData(..))
18−import Data.Functor.Identity (Identity)
21+import Data.Functor.Identity (Identity(..))
19
22
20import qualified GHC.Exts as GHC
23import qualified GHC.Exts as GHC
21import qualified Stream.Common as Common
24import qualified Stream.Common as Common
25+import qualified Streamly.Internal.Data.Fold as Fold
22#ifdef USE_PRELUDE
26#ifdef USE_PRELUDE
23import Streamly.Benchmark.Prelude (sourceFromFoldableM, absTimes)
27import Streamly.Benchmark.Prelude (sourceFromFoldableM, absTimes)
24import qualified Streamly.Prelude as S
28import qualified Streamly.Prelude as S
@@ -224,6 +228,10 @@ o_1_space_generation value =
224 ]
228 ]
225 ]
229 ]
226
230
231+instance NFData a => NFData (Stream Identity a) where
232+ {-# INLINE rnf #-}
233+ rnf xs = runIdentity $ Stream.fold (Fold.foldl' (\_ x -> rnf x) ()) xs
234+
227o_n_heap_generation :: Int -> [Benchmark]
235o_n_heap_generation :: Int -> [Benchmark]
228o_n_heap_generation value =
236o_n_heap_generation value =
229 [ bgroup "buffered"
237 [ bgroup "buffered"
benchmark/Streamly/Benchmark/Data/Stream/Lift.hs+6−7
@@ -17,7 +17,7 @@ module Stream.Lift (benchmarks) where
17
17
18import Control.DeepSeq (NFData(..))
18import Control.DeepSeq (NFData(..))
19import Control.Monad.Trans.Class (lift)
19import Control.Monad.Trans.Class (lift)
20−import Control.Monad.State.Strict (StateT, get, put, MonadState)
20+import Control.Monad.State.Strict (StateT, get, put)
21import Data.Functor.Identity (Identity)
21import Data.Functor.Identity (Identity)
22import Stream.Common
22import Stream.Common
23 (benchIO, sourceUnfoldr, sourceUnfoldrM, benchIOSrc, drain)
23 (benchIO, sourceUnfoldr, sourceUnfoldrM, benchIOSrc, drain)
@@ -107,15 +107,14 @@ iterateStateT n = do
107
107
108{-# INLINE iterateState #-}
108{-# INLINE iterateState #-}
109{-# SPECIALIZE iterateState :: Int -> Stream (StateT Int IO) Int #-}
109{-# SPECIALIZE iterateState :: Int -> Stream (StateT Int IO) Int #-}
110−iterateState ::
110+iterateState :: Monad m =>
111− MonadState Int m
112− => Int
111+ Int
113− -> Stream m Int
112+ -> Stream (StateT Int m) Int
114iterateState n = do
113iterateState n = do
115− x <- get
114+ x <- Stream.fromEffect get
116 if x > n
115 if x > n
117 then do
116 then do
118− put (x - 1)
117+ Stream.fromEffect $ put (x - 1)
119 iterateState n
118 iterateState n
120 else return x
119 else return x
121
120
benchmark/Streamly/Benchmark/Data/Stream/Transform.hs+8−1
@@ -6,9 +6,11 @@
6
6
7{-# LANGUAGE CPP #-}
7{-# LANGUAGE CPP #-}
8{-# LANGUAGE FlexibleContexts #-}
8{-# LANGUAGE FlexibleContexts #-}
9+{-# LANGUAGE FlexibleInstances #-}
9{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE RankNTypes #-}
11{-# LANGUAGE RankNTypes #-}
11
12
13+{-# OPTIONS_GHC -Wno-orphans #-}
12#ifdef USE_PRELUDE
14#ifdef USE_PRELUDE
13{-# OPTIONS_GHC -Wno-deprecations #-}
15{-# OPTIONS_GHC -Wno-deprecations #-}
14#endif
16#endif
@@ -26,7 +28,7 @@ module Stream.Transform (benchmarks) where
26
28
27import Control.DeepSeq (NFData(..))
29import Control.DeepSeq (NFData(..))
28import Control.Monad.IO.Class (MonadIO(..))
30import Control.Monad.IO.Class (MonadIO(..))
29−import Data.Functor.Identity (Identity)
31+import Data.Functor.Identity (Identity(..))
30
32
31import System.Random (randomRIO)
33import System.Random (randomRIO)
32
34
@@ -34,6 +36,7 @@ import qualified Streamly.Internal.Data.Fold as FL
34
36
35import qualified Prelude
37import qualified Prelude
36import qualified Stream.Common as Common
38import qualified Stream.Common as Common
39+import qualified Streamly.Internal.Data.Fold as Fold
37import qualified Streamly.Internal.Data.Unfold as Unfold
40import qualified Streamly.Internal.Data.Unfold as Unfold
38#ifdef USE_PRELUDE
41#ifdef USE_PRELUDE
39import qualified Streamly.Internal.Data.Stream.IsStream as Stream
42import qualified Streamly.Internal.Data.Stream.IsStream as Stream
@@ -84,6 +87,10 @@ benchPureSinkIO
84benchPureSinkIO value name f =
87benchPureSinkIO value name f =
85 bench name $ nfIO $ randomRIO (1, 1) >>= f . sourceUnfoldr value
88 bench name $ nfIO $ randomRIO (1, 1) >>= f . sourceUnfoldr value
86
89
90+instance NFData a => NFData (Stream Identity a) where
91+ {-# INLINE rnf #-}
92+ rnf xs = runIdentity $ Stream.fold (Fold.foldl' (\_ x -> rnf x) ()) xs
93+
87o_n_space_traversable :: Int -> [Benchmark]
94o_n_space_traversable :: Int -> [Benchmark]
88o_n_space_traversable value =
95o_n_space_traversable value =
89 -- Buffering operations using heap proportional to number of elements.
96 -- Buffering operations using heap proportional to number of elements.
benchmark/Streamly/Benchmark/Unicode/Char.hs+9−3
@@ -1,4 +1,4 @@
1−{-# OPTIONS_GHC -Wno-deprecations #-}
1+{-# OPTIONS_GHC -Wno-deprecations -Wno-orphans #-}
2
2
3--
3--
4-- Module : Streamly.Unicode.Char
4-- Module : Streamly.Unicode.Char
@@ -12,7 +12,7 @@
12-- Imports
12-- Imports
13--------------------------------------------------------------------------------
13--------------------------------------------------------------------------------
14
14
15−import Control.DeepSeq (NFData)
15+import Control.DeepSeq (NFData(..))
16import Streamly.Internal.Data.Array (Array)
16import Streamly.Internal.Data.Array (Array)
17import System.FilePath (dropExtensions, takeFileName)
17import System.FilePath (dropExtensions, takeFileName)
18import System.FilePath.Posix ((</>))
18import System.FilePath.Posix ((</>))
@@ -43,7 +43,13 @@ dataDir = "benchmark/Streamly/Benchmark/Unicode/data"
43dataSetSize :: Int
43dataSetSize :: Int
44dataSetSize = 1000000
44dataSetSize = 1000000
45
45
46+-- Unboxed arrays are fully evaluated.
47+instance NFData (Array a) where
48+ {-# INLINE rnf #-}
49+ rnf _ = ()
50+
51+makeBench ::
46−makeBench :: (NFData a) => (String, a -> IO ()) -> (String, IO a) -> Benchmark
52+ (String, Array Char -> IO ()) -> (String, IO (Array Char)) -> Benchmark
47makeBench (implName, func) (dataName, setup) =
53makeBench (implName, func) (dataName, setup) =
48 env setup (bench (implName ++ "/" ++ dataName) . nfIO . func)
54 env setup (bench (implName ++ "/" ++ dataName) . nfIO . func)
49
55
benchmark/Streamly/Benchmark/Unicode/Utf8.hs+2−2
@@ -49,7 +49,7 @@ main = runWithCLIOpts defaultStreamSize allBenchmarks
49 allBenchmarks value =
49 allBenchmarks value =
50 [ bgroup
50 [ bgroup
51 moduleName
51 moduleName
52− [ bench "pack" $ nf pack value
52+ [ bench "pack" $ whnf pack value
53− , bench "pack + unpack" $ nf packUnpack value
53+ , bench "pack + unpack" $ whnf packUnpack value
54 ]
54 ]
55 ]
55 ]
core/src/Streamly/Internal/Data/Array/Generic.hs−5
@@ -50,7 +50,6 @@ module Streamly.Internal.Data.Array.Generic
50 )
50 )
51where
51where
52
52
53−import Control.DeepSeq (NFData(..))
54import Control.Monad (when, replicateM)
53import Control.Monad (when, replicateM)
55import Control.Monad.IO.Class (liftIO, MonadIO)
54import Control.Monad.IO.Class (liftIO, MonadIO)
56import GHC.Base (MutableArray#, RealWorld)
55import GHC.Base (MutableArray#, RealWorld)
@@ -226,10 +225,6 @@ foldl' f z arr = unsafePerformIO $ D.foldl' f z $ readStreamD arr
226foldr :: (a -> b -> b) -> b -> Array a -> b
225foldr :: (a -> b -> b) -> b -> Array a -> b
227foldr f z arr = unsafePerformIO $ D.foldr f z $ readStreamD arr
226foldr f z arr = unsafePerformIO $ D.foldr f z $ readStreamD arr
228
227
229−instance NFData a => NFData (Array a) where
230− {-# INLINE rnf #-}
231− rnf = foldl' (\_ x -> rnf x) ()
232−
233{-# INLINE fold #-}
228{-# INLINE fold #-}
234fold :: MonadIO m => Fold m a b -> Array a -> m b
229fold :: MonadIO m => Fold m a b -> Array a -> m b
235fold f arr = D.fold f (readStreamD arr)
230fold f arr = D.fold f (readStreamD arr)
core/src/Streamly/Internal/Data/Array/Mut/Type.hs−11
@@ -214,7 +214,6 @@ where
214#include "ArrayMacros.h"
214#include "ArrayMacros.h"
215#include "MachDeps.h"
215#include "MachDeps.h"
216
216
217−import Control.DeepSeq (NFData(..), NFData1(..))
218import Control.Monad (when, void)
217import Control.Monad (when, void)
219import Control.Monad.IO.Class (MonadIO(..))
218import Control.Monad.IO.Class (MonadIO(..))
220import Data.Bits (shiftR, (.|.), (.&.))
219import Data.Bits (shiftR, (.|.), (.&.))
@@ -2278,16 +2277,6 @@ cmp arr1 arr2 =
2278-- NFData
2277-- NFData
2279-------------------------------------------------------------------------------
2278-------------------------------------------------------------------------------
2280
2279
2281−-- This is an Unbox array, we cannot have unevaluated data in it so this is
2282−-- just a no op.
2283−instance NFData (Array a) where
2284− {-# INLINE rnf #-}
2285− rnf Array {} = ()
2286−
2287−instance NFData1 Array where
2288− {-# INLINE liftRnf #-}
2289− liftRnf _ Array{} = ()
2290−
2291-- | Strip elements which match with predicate from both ends.
2280-- | Strip elements which match with predicate from both ends.
2292--
2281--
2293-- /Pre-release/
2282-- /Pre-release/
core/src/Streamly/Internal/Data/Array/Type.hs−10
@@ -78,7 +78,6 @@ where
78#include "inline.hs"
78#include "inline.hs"
79
79
80import Control.Exception (assert)
80import Control.Exception (assert)
81−import Control.DeepSeq (NFData(..), NFData1(..))
82import Control.Monad (replicateM)
81import Control.Monad (replicateM)
83import Control.Monad.IO.Class (MonadIO(..))
82import Control.Monad.IO.Class (MonadIO(..))
84import Data.Functor.Identity (Identity(..))
83import Data.Functor.Identity (Identity(..))
@@ -515,15 +514,6 @@ instance (Unbox a, Eq a) => Eq (Array a) where
515 arr1 == arr2 =
514 arr1 == arr2 =
516 (==) EQ $ unsafeInlineIO $! unsafeThaw arr1 `MA.cmp` unsafeThaw arr2
515 (==) EQ $ unsafeInlineIO $! unsafeThaw arr1 `MA.cmp` unsafeThaw arr2
517
516
518−-- Since this is an Unbox array we cannot have unevaluated data in it so
519−-- this is just a no op.
520−instance NFData (Array a) where
521− {-# INLINE rnf #-}
522− rnf Array {} = ()
523−
524−instance NFData1 Array where
525− liftRnf _ Array{} = ()
526−
527instance (Unbox a, Ord a) => Ord (Array a) where
517instance (Unbox a, Ord a) => Ord (Array a) where
528 {-# INLINE compare #-}
518 {-# INLINE compare #-}
529 compare arr1 arr2 = runIdentity $
519 compare arr1 arr2 = runIdentity $
core/src/Streamly/Internal/Data/List.hs+2−4
@@ -62,8 +62,6 @@ module Streamly.Internal.Data.List
62where
62where
63
63
64import Control.Arrow (second)
64import Control.Arrow (second)
65−import Control.DeepSeq (NFData(..))
66−import Control.DeepSeq (NFData1(..))
67import Data.Functor.Identity (Identity, runIdentity)
65import Data.Functor.Identity (Identity, runIdentity)
68import GHC.Exts (IsList(..), IsString(..))
66import GHC.Exts (IsList(..), IsString(..))
69import Streamly.Internal.Data.Stream.Type (Stream)
67import Streamly.Internal.Data.Stream.Type (Stream)
@@ -89,7 +87,7 @@ import qualified Streamly.Internal.Data.Stream.Type as Stream
89-- /Pre-release/
87-- /Pre-release/
90newtype List a = List { toStream :: Stream Identity a }
88newtype List a = List { toStream :: Stream Identity a }
91 deriving
89 deriving
92− ( Show, Read, Eq, Ord, NFData , NFData1
90+ ( Show, Read, Eq, Ord
93 , Semigroup, Monoid, Functor, Foldable
91 , Semigroup, Monoid, Functor, Foldable
94 , Applicative, Traversable, Monad, IsList)
92 , Applicative, Traversable, Monad, IsList)
95
93
@@ -144,7 +142,7 @@ pattern Cons x xs <-
144-- @since 0.6.0
142-- @since 0.6.0
145newtype ZipList a = ZipList { toZipStream :: ZipStream Identity a }
143newtype ZipList a = ZipList { toZipStream :: ZipStream Identity a }
146 deriving
144 deriving
147− ( Show, Read, Eq, Ord, NFData , NFData1
145+ ( Show, Read, Eq, Ord
148 , Semigroup, Monoid, Functor, Foldable
146 , Semigroup, Monoid, Functor, Foldable
149 , Applicative, Traversable, IsList
147 , Applicative, Traversable, IsList
150 )
148 )
core/src/Streamly/Internal/Data/Parser/ParserD/Type.hs−19
@@ -211,8 +211,6 @@ import Control.Applicative (Alternative(..), liftA2)
211import Control.Exception (Exception(..))
211import Control.Exception (Exception(..))
212import Control.Monad (MonadPlus(..), (>=>))
212import Control.Monad (MonadPlus(..), (>=>))
213import Control.Monad.IO.Class (MonadIO, liftIO)
213import Control.Monad.IO.Class (MonadIO, liftIO)
214−import Control.Monad.Reader.Class (MonadReader, ask, local)
215−import Control.Monad.State.Class (MonadState, get, put)
216import Data.Bifunctor (Bifunctor(..))
214import Data.Bifunctor (Bifunctor(..))
217import Fusion.Plugin.Types (Fuse(..))
215import Fusion.Plugin.Types (Fuse(..))
218import Streamly.Internal.Data.Fold.Type (Fold(..), toList)
216import Streamly.Internal.Data.Fold.Type (Fold(..), toList)
@@ -1481,23 +1479,6 @@ instance Monad m => MonadPlus (Parser a m) where
1481 {-# INLINE mplus #-}
1479 {-# INLINE mplus #-}
1482 mplus = alt
1480 mplus = alt
1483
1481
1484−instance (Monad m, MonadReader r m) => MonadReader r (Parser a m) where
1485− {-# INLINE ask #-}
1486− ask = fromEffect ask
1487−
1488− {-# INLINE local #-}
1489− local f (Parser step init' extract) =
1490− Parser ((local f .) . step)
1491− (local f init')
1492− (local f . extract)
1493−
1494−instance (Monad m, MonadState s m) => MonadState s (Parser a m) where
1495− {-# INLINE get #-}
1496− get = fromEffect get
1497−
1498− {-# INLINE put #-}
1499− put = fromEffect . put
1500−
1501instance (Monad m, MonadIO m) => MonadIO (Parser a m) where
1482instance (Monad m, MonadIO m) => MonadIO (Parser a m) where
1502 {-# INLINE liftIO #-}
1483 {-# INLINE liftIO #-}
1503 liftIO = fromEffect . liftIO
1484 liftIO = fromEffect . liftIO
core/src/Streamly/Internal/Data/Parser/ParserK/Type.hs+8−20
@@ -32,10 +32,8 @@ where
32
32
33import Control.Applicative (Alternative(..), liftA2)
33import Control.Applicative (Alternative(..), liftA2)
34import Control.Monad (MonadPlus(..), ap)
34import Control.Monad (MonadPlus(..), ap)
35−import Control.Monad.Catch (MonadCatch, MonadThrow(..))
36import Control.Monad.IO.Class (MonadIO, liftIO)
35import Control.Monad.IO.Class (MonadIO, liftIO)
37−import Control.Monad.Reader.Class (MonadReader, ask, local)
38−import Control.Monad.State.Class (MonadState, get, put)
36+-- import Control.Monad.Trans.Class (MonadTrans(lift))
39import qualified Control.Monad.Fail as Fail
37import qualified Control.Monad.Fail as Fail
40
38
41-- | The intermediate result of running a parser step. The parser driver may
39-- | The intermediate result of running a parser step. The parser driver may
@@ -248,23 +246,7 @@ instance Monad m => Fail.MonadFail (Parser a m) where
248 {-# INLINE fail #-}
246 {-# INLINE fail #-}
249 fail = die
247 fail = die
250
248
251−instance (MonadThrow m, MonadReader r m, MonadCatch m) =>
252− MonadReader r (Parser a m) where
253−
254− {-# INLINE ask #-}
255− ask = fromEffect ask
256−
257− {-# INLINE local #-}
258− local f p = MkParser $ \n st k -> local f $ runParser p n st k
259−
260−instance (MonadThrow m, MonadState s m) => MonadState s (Parser a m) where
261− {-# INLINE get #-}
262− get = fromEffect get
263−
264− {-# INLINE put #-}
265− put = fromEffect . put
266−
267−instance (MonadThrow m, MonadIO m) => MonadIO (Parser a m) where
249+instance MonadIO m => MonadIO (Parser a m) where
268 {-# INLINE liftIO #-}
250 {-# INLINE liftIO #-}
269 liftIO = fromEffect . liftIO
251 liftIO = fromEffect . liftIO
270
252
@@ -324,3 +306,9 @@ instance Monad m => MonadPlus (Parser a m) where
324
306
325 {-# INLINE mplus #-}
307 {-# INLINE mplus #-}
326 mplus = (<|>)
308 mplus = (<|>)
309+
310+{-
311+instance MonadTrans (Parser a) where
312+ {-# INLINE lift #-}
313+ lift = fromEffect
314+-}
core/src/Streamly/Internal/Data/Stream/StreamK.hs−1
@@ -171,7 +171,6 @@ module Streamly.Internal.Data.Stream.StreamK
171
171
172 -- * Utilities
172 -- * Utilities
173 , consM
173 , consM
174− , withLocal
175 , mfix
174 , mfix
176 )
175 )
177where
176where
core/src/Streamly/Internal/Data/Stream/StreamK/Type.hs+2−16
@@ -99,20 +99,18 @@ module Streamly.Internal.Data.Stream.StreamK.Type
99 , interleaveMin
99 , interleaveMin
100
100
101 -- * Reader
101 -- * Reader
102− , withLocal
103 , evalStateT
102 , evalStateT
104 , liftInner
103 , liftInner
105 )
104 )
106where
105where
107
106
108import Control.Monad (ap, (>=>))
107import Control.Monad (ap, (>=>))
109−import Control.Monad.Reader.Class (MonadReader(..))
110−import Control.Monad.State.Strict (StateT)
111import Control.Monad.Trans.Class (MonadTrans(lift))
108import Control.Monad.Trans.Class (MonadTrans(lift))
109+import Control.Monad.Trans.State.Strict (StateT)
112import Data.Function (fix)
110import Data.Function (fix)
113import Streamly.Internal.Data.SVar.Type (State, adaptState, defState)
111import Streamly.Internal.Data.SVar.Type (State, adaptState, defState)
114
112
115−import qualified Control.Monad.State.Strict as State
113+import qualified Control.Monad.Trans.State.Strict as State
116import qualified Prelude
114import qualified Prelude
117
115
118import Prelude hiding
116import Prelude hiding
@@ -1187,18 +1185,6 @@ interleaveMin m1 m2 = mkStream $ \st yld _ stp -> do
1187 yieldk a r = yld a (interleaveMin m2 r)
1185 yieldk a r = yld a (interleaveMin m2 r)
1188 foldStream st yieldk single stop m1
1186 foldStream st yieldk single stop m1
1189
1187
1190−------------------------------------------------------------------------------
1191−-- MonadReader
1192−------------------------------------------------------------------------------
1193−
1194−{-# INLINABLE withLocal #-}
1195−withLocal :: MonadReader r m => (r -> r) -> Stream m a -> Stream m a
1196−withLocal f m =
1197− mkStream $ \st yld sng stp ->
1198− let single = local f . sng
1199− yieldk a r = local f $ yld a (withLocal f r)
1200− in foldStream st yieldk single (local f stp) m
1201−
1202-------------------------------------------------------------------------------
1188-------------------------------------------------------------------------------
1203-- Generation
1189-- Generation
1204-------------------------------------------------------------------------------
1190-------------------------------------------------------------------------------
core/src/Streamly/Internal/Data/Stream/Transform.hs+1
@@ -169,6 +169,7 @@ import Prelude hiding
169--
169--
170-- $setup
170-- $setup
171-- >>> :m
171-- >>> :m
172+-- >>> :set -package mtl
172-- >>> import Control.Concurrent (threadDelay)
173-- >>> import Control.Concurrent (threadDelay)
173-- >>> import Control.Monad.IO.Class (MonadIO (liftIO))
174-- >>> import Control.Monad.IO.Class (MonadIO (liftIO))
174-- >>> import Control.Monad.Trans (lift)
175-- >>> import Control.Monad.Trans (lift)
core/src/Streamly/Internal/Data/Stream/Type.hs−30
@@ -41,11 +41,8 @@ where
41#include "inline.hs"
41#include "inline.hs"
42
42
43import Control.Applicative (liftA2)
43import Control.Applicative (liftA2)
44−import Control.DeepSeq (NFData(..), NFData1(..))
45import Control.Monad.Catch (MonadThrow, throwM)
44import Control.Monad.Catch (MonadThrow, throwM)
46import Control.Monad.IO.Class (MonadIO(..))
45import Control.Monad.IO.Class (MonadIO(..))
47−import Control.Monad.Reader.Class (MonadReader(..))
48−import Control.Monad.State.Class (MonadState(..))
49import Control.Monad.Trans.Class (MonadTrans(lift))
46import Control.Monad.Trans.Class (MonadTrans(lift))
50import Data.Foldable (Foldable(foldl'), fold)
47import Data.Foldable (Foldable(foldl'), fold)
51import Data.Functor.Identity (Identity(..), runIdentity)
48import Data.Functor.Identity (Identity(..), runIdentity)
@@ -241,33 +238,6 @@ instance (MonadIO m) => MonadIO (Stream m) where
241instance (MonadThrow m) => MonadThrow (Stream m) where
238instance (MonadThrow m) => MonadThrow (Stream m) where
242 throwM = lift . throwM
239 throwM = lift . throwM
243
240
244−instance (MonadReader r m) => MonadReader r (Stream m) where
245− ask = lift ask
246−
247− local f (Stream m) = Stream $ K.withLocal f m
248−
249−instance (MonadState s m) => MonadState s (Stream m) where
250− {-# INLINE get #-}
251− get = lift get
252−
253− {-# INLINE put #-}
254− put x = lift (put x)
255−
256− {-# INLINE state #-}
257− state k = lift (state k)
258−
259−------------------------------------------------------------------------------
260−-- NFData
261−------------------------------------------------------------------------------
262−
263−instance NFData a => NFData (Stream Identity a) where
264− {-# INLINE rnf #-}
265− rnf (Stream xs) = runIdentity $ P.foldl' (\_ x -> rnf x) () xs
266−
267−instance NFData1 (Stream Identity) where
268− {-# INLINE liftRnf #-}
269− liftRnf f (Stream xs) = runIdentity $ P.foldl' (\_ x -> f x) () xs
270−
271------------------------------------------------------------------------------
241------------------------------------------------------------------------------
272-- Lists
242-- Lists
273------------------------------------------------------------------------------
243------------------------------------------------------------------------------
core/src/Streamly/Internal/Data/Stream/Zip.hs−3
@@ -24,7 +24,6 @@ module Streamly.Internal.Data.Stream.Zip
24 )
24 )
25where
25where
26
26
27−import Control.DeepSeq (NFData(..), NFData1(..))
28import Data.Functor.Identity (Identity(..))
27import Data.Functor.Identity (Identity(..))
29import GHC.Exts (IsList(..), IsString(..))
28import GHC.Exts (IsList(..), IsString(..))
30import Streamly.Internal.Data.Stream.Type (Stream)
29import Streamly.Internal.Data.Stream.Type (Stream)
@@ -62,8 +61,6 @@ import qualified Streamly.Internal.Data.Stream as Stream
62newtype ZipStream m a = ZipStream {getZipStream :: Stream m a}
61newtype ZipStream m a = ZipStream {getZipStream :: Stream m a}
63 deriving (Functor, Semigroup, Monoid)
62 deriving (Functor, Semigroup, Monoid)
64
63
65−deriving instance NFData a => NFData (ZipStream Identity a)
66−deriving instance NFData1 (ZipStream Identity)
67deriving instance IsList (ZipStream Identity a)
64deriving instance IsList (ZipStream Identity a)
68deriving instance (a ~ Char) => IsString (ZipStream Identity a)
65deriving instance (a ~ Char) => IsString (ZipStream Identity a)
69deriving instance Eq a => Eq (ZipStream Identity a)
66deriving instance Eq a => Eq (ZipStream Identity a)
core/streamly-core.cabal−3
@@ -237,7 +237,6 @@ library
237 , Streamly.Internal.Control.Exception
237 , Streamly.Internal.Control.Exception
238 , Streamly.Internal.Control.Monad
238 , Streamly.Internal.Control.Monad
239 , Streamly.Internal.Control.ForkIO
239 , Streamly.Internal.Control.ForkIO
240− , Streamly.Internal.Data.Cont
241 , Streamly.Internal.System.IO
240 , Streamly.Internal.System.IO
242
241
243 -- streamly-strict-data
242 -- streamly-strict-data
@@ -410,10 +409,8 @@ library
410 -- depending on doctest is a common example) can
409 -- depending on doctest is a common example) can
411 -- depend on streamly.
410 -- depend on streamly.
412 base >= 4.12 && < 4.18
411 base >= 4.12 && < 4.18
413− , deepseq >= 1.4.4 && < 1.5
414 , exceptions >= 0.8.0 && < 0.11
412 , exceptions >= 0.8.0 && < 0.11
415 , ghc-prim >= 0.5.3 && < 0.10
413 , ghc-prim >= 0.5.3 && < 0.10
416− , mtl >= 2.2.2 && < 2.4
417 , transformers >= 0.5.5 && < 0.7
414 , transformers >= 0.5.5 && < 0.7
418
415
419 -- streamly-unicode-core
416 -- streamly-unicode-core
hie.yaml+2
@@ -70,6 +70,8 @@ cradle:
70 component: "bench:Unicode.Char"
70 component: "bench:Unicode.Char"
71 - path: "./benchmark/Streamly/Benchmark/Unicode/Stream.hs"
71 - path: "./benchmark/Streamly/Benchmark/Unicode/Stream.hs"
72 component: "bench:Unicode.Stream"
72 component: "bench:Unicode.Stream"
73+ - path: "./benchmark/Streamly/Benchmark/Unicode/Utf8.hs"
74+ component: "bench:Unicode.Utf8"
73 - path: "./benchmark/lib/"
75 - path: "./benchmark/lib/"
74 component: "lib:streamly-benchmarks"
76 component: "lib:streamly-benchmarks"
75 - path: "./benchmark/Streamly/Benchmark/Data/Fold/Window.hs"
77 - path: "./benchmark/Streamly/Benchmark/Data/Fold/Window.hs"
src/Streamly/Data/Array/Foreign.hs+13
@@ -1,3 +1,4 @@
1+{-# OPTIONS_GHC -Wno-orphans #-}
1#include "inline.hs"
2#include "inline.hs"
2
3
3-- |
4-- |
@@ -93,6 +94,7 @@ module Streamly.Data.Array.Foreign
93 )
94 )
94where
95where
95
96
97+import Control.DeepSeq (NFData(..), NFData1(..))
96import Streamly.Internal.Data.Array as A
98import Streamly.Internal.Data.Array as A
97
99
98-- $setup
100-- $setup
@@ -104,3 +106,14 @@ import Streamly.Internal.Data.Array as A
104-- >>> import Streamly.Data.Array (Array)
106-- >>> import Streamly.Data.Array (Array)
105-- >>> import qualified Streamly.Internal.Data.Stream.IsStream as Stream
107-- >>> import qualified Streamly.Internal.Data.Stream.IsStream as Stream
106-- >>> import qualified Streamly.Data.Array as Array
108-- >>> import qualified Streamly.Data.Array as Array
109+
110+-- Orphan instances for backward compatibility
111+-- Since this is an Unbox array we cannot have unevaluated data in it so
112+-- this is just a no op.
113+
114+instance NFData (Array a) where
115+ {-# INLINE rnf #-}
116+ rnf _ = ()
117+
118+instance NFData1 Array where
119+ liftRnf _ _ = ()
core/src/Streamly/Internal/Data/Cont.hs → src/Streamly/Internal/Data/Cont.hsrenamed

The content is the same.

src/Streamly/Internal/Data/Stream/Ahead.hs+9−1
@@ -52,7 +52,7 @@ import Streamly.Internal.Data.Stream.StreamK.Type (Stream)
52
52
53import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
53import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
54 (foldStreamShared, cons, mkStream, foldStream, fromEffect
54 (foldStreamShared, cons, mkStream, foldStream, fromEffect
55− , nil, concatMapWith, fromPure, bindWith, withLocal)
55+ , nil, concatMapWith, fromPure, bindWith)
56import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
56import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
57 (mapM, fromStreamK, toStreamK)
57 (mapM, fromStreamK, toStreamK)
58import qualified Streamly.Internal.Data.Stream as Stream (toStreamK)
58import qualified Streamly.Internal.Data.Stream as Stream (toStreamK)
@@ -74,6 +74,14 @@ import Prelude hiding (map)
74-- return n -- IO Int
74-- return n -- IO Int
75-- :}
75-- :}
76
76
77+{-# INLINABLE withLocal #-}
78+withLocal :: MonadReader r m => (r -> r) -> Stream m a -> Stream m a
79+withLocal f m =
80+ K.mkStream $ \st yld sng stp ->
81+ let single = local f . sng
82+ yieldk a r = local f $ yld a (withLocal f r)
83+ in K.foldStream st yieldk single (local f stp) m
84+
77-------------------------------------------------------------------------------
85-------------------------------------------------------------------------------
78-- Ahead
86-- Ahead
79-------------------------------------------------------------------------------
87-------------------------------------------------------------------------------
src/Streamly/Internal/Data/Stream/Async.hs+9−1
@@ -63,7 +63,7 @@ import Streamly.Internal.Data.Stream.SVar.Generate (fromSVar, fromSVarD)
63
63
64import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
64import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
65 (foldStreamShared, mkStream, foldStream, fromEffect
65 (foldStreamShared, mkStream, foldStream, fromEffect
66− , nil, concatMapWith, fromPure, bindWith, withLocal)
66+ , nil, concatMapWith, fromPure, bindWith)
67import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
67import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
68 (Stream(..), Step(..), mapM, toStreamK, fromStreamK)
68 (Stream(..), Step(..), mapM, toStreamK, fromStreamK)
69import qualified Streamly.Internal.Data.Stream as Stream (toStreamK)
69import qualified Streamly.Internal.Data.Stream as Stream (toStreamK)
@@ -84,6 +84,14 @@ import Streamly.Internal.Data.SVar
84-- :}
84-- :}
85--
85--
86
86
87+{-# INLINABLE withLocal #-}
88+withLocal :: MonadReader r m => (r -> r) -> Stream m a -> Stream m a
89+withLocal f m =
90+ K.mkStream $ \st yld sng stp ->
91+ let single = local f . sng
92+ yieldk a r = local f $ yld a (withLocal f r)
93+ in K.foldStream st yieldk single (local f stp) m
94+
87-------------------------------------------------------------------------------
95-------------------------------------------------------------------------------
88-- Async
96-- Async
89-------------------------------------------------------------------------------
97-------------------------------------------------------------------------------
src/Streamly/Internal/Data/Stream/Instances.hs+1−1
@@ -33,7 +33,7 @@ instance (MonadError e m CONSTRAINT) => MonadError e (STREAM m) where { \
33 \
33 \
34instance (MonadReader r m CONSTRAINT) => MonadReader r (STREAM m) where { \
34instance (MonadReader r m CONSTRAINT) => MonadReader r (STREAM m) where { \
35 ask = lift ask; \
35 ask = lift ask; \
36− local f (STREAM m) = STREAM $ K.withLocal f m }; \
36+ local f (STREAM m) = STREAM $ withLocal f m }; \
37 \
37 \
38instance (MonadState s m CONSTRAINT) => MonadState s (STREAM m) where { \
38instance (MonadState s m CONSTRAINT) => MonadState s (STREAM m) where { \
39 {-# INLINE get #-}; \
39 {-# INLINE get #-}; \
src/Streamly/Internal/Data/Stream/IsStream.hs+9−1
@@ -1,4 +1,5 @@
1−{-# OPTIONS_GHC -Wno-deprecations #-}
1+{-# OPTIONS_GHC -Wno-deprecations -Wno-orphans #-}
2+{-# LANGUAGE StandaloneDeriving #-}
2
3
3-- |
4-- |
4-- Module : Streamly.Internal.Data.Stream.IsStream
5-- Module : Streamly.Internal.Data.Stream.IsStream
@@ -25,6 +26,10 @@ module Streamly.Internal.Data.Stream.IsStream {-# DEPRECATED "Please use \"Stre
25 )
26 )
26where
27where
27
28
29+import Control.DeepSeq (NFData(..), NFData1(..))
30+import Data.Functor.Identity (Identity(..))
31+import Streamly.Internal.Data.Stream.Zip (ZipStream(..))
32+
28import Streamly.Internal.Data.Stream.IsStream.Top
33import Streamly.Internal.Data.Stream.IsStream.Top
29import Streamly.Internal.Data.Stream.IsStream.Eliminate
34import Streamly.Internal.Data.Stream.IsStream.Eliminate
30import Streamly.Internal.Data.Stream.IsStream.Exception
35import Streamly.Internal.Data.Stream.IsStream.Exception
@@ -36,3 +41,6 @@ import Streamly.Internal.Data.Stream.IsStream.Transform
36import Streamly.Internal.Data.Stream.IsStream.Type
41import Streamly.Internal.Data.Stream.IsStream.Type
37 hiding (cmpBy, drain, eqBy, foldl', fold, toList, toStream
42 hiding (cmpBy, drain, eqBy, foldl', fold, toList, toStream
38 , fromEffect, fromPure, repeat)
43 , fromEffect, fromPure, repeat)
44+
45+deriving instance NFData a => NFData (ZipStream Identity a)
46+deriving instance NFData1 (ZipStream Identity)
src/Streamly/Internal/Data/Stream/Parallel.hs+9−1
@@ -71,7 +71,7 @@ import Streamly.Internal.Data.Stream.Type (Stream)
71import qualified Data.Set as Set
71import qualified Data.Set as Set
72import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
72import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
73 (Stream, foldStreamShared, mkStream, foldStream, fromEffect
73 (Stream, foldStreamShared, mkStream, foldStream, fromEffect
74− , nil, concatMapWith, fromPure, bindWith, withLocal)
74+ , nil, concatMapWith, fromPure, bindWith)
75import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
75import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
76 (Stream(..), mapM, toStreamK, fromStreamK)
76 (Stream(..), mapM, toStreamK, fromStreamK)
77import qualified Streamly.Internal.Data.Stream.SVar.Generate as SVar
77import qualified Streamly.Internal.Data.Stream.SVar.Generate as SVar
@@ -96,6 +96,14 @@ import Prelude hiding (map)
96-- return n -- IO Int
96-- return n -- IO Int
97-- :}
97-- :}
98
98
99+{-# INLINABLE withLocal #-}
100+withLocal :: MonadReader r m => (r -> r) -> K.Stream m a -> K.Stream m a
101+withLocal f m =
102+ K.mkStream $ \st yld sng stp ->
103+ let single = local f . sng
104+ yieldk a r = local f $ yld a (withLocal f r)
105+ in K.foldStream st yieldk single (local f stp) m
106+
99-------------------------------------------------------------------------------
107-------------------------------------------------------------------------------
100-- Parallel
108-- Parallel
101-------------------------------------------------------------------------------
109-------------------------------------------------------------------------------
src/Streamly/Internal/Data/Stream/Serial.hs+44−2
@@ -1,4 +1,5 @@
1{-# LANGUAGE UndecidableInstances #-}
1{-# LANGUAGE UndecidableInstances #-}
2+{-# OPTIONS_GHC -Wno-orphans #-}
2
3
3-- |
4-- |
4-- Module : Streamly.Internal.Data.Stream.Serial
5-- Module : Streamly.Internal.Data.Stream.Serial
@@ -65,13 +66,15 @@ import Streamly.Internal.BaseCompat ((#.))
65import Streamly.Internal.Data.Maybe.Strict (Maybe'(..), toMaybe)
66import Streamly.Internal.Data.Maybe.Strict (Maybe'(..), toMaybe)
66import Streamly.Data.Stream (Stream)
67import Streamly.Data.Stream (Stream)
67
68
69+import qualified Streamly.Data.Fold as Fold
68import qualified Streamly.Data.Stream as Stream
70import qualified Streamly.Data.Stream as Stream
71+import qualified Streamly.Internal.Data.Stream as Stream (toStreamK, fromStreamK)
69import qualified Streamly.Internal.Data.Stream.Common as P
72import qualified Streamly.Internal.Data.Stream.Common as P
70import qualified Streamly.Internal.Data.Stream.StreamD as D
73import qualified Streamly.Internal.Data.Stream.StreamD as D
71 (fromStreamK, toStreamK, mapM)
74 (fromStreamK, toStreamK, mapM)
72import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
75import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
73− (Stream, cons, consM, nil, concatMapWith, fromPure, bindWith
76+ (Stream, mkStream, foldStream, cons, consM, nil, concatMapWith, fromPure
74− , withLocal, interleave, interleaveFst, interleaveMin)
77+ , bindWith, interleave, interleaveFst, interleaveMin)
75
78
76import Prelude hiding (map, mapM, repeat, filter)
79import Prelude hiding (map, mapM, repeat, filter)
77
80
@@ -83,6 +86,45 @@ import Prelude hiding (map, mapM, repeat, filter)
83-- >>> import qualified Streamly.Data.Stream as Stream
86-- >>> import qualified Streamly.Data.Stream as Stream
84-- >>> import qualified Streamly.Prelude as IsStream
87-- >>> import qualified Streamly.Prelude as IsStream
85
88
89+{-# INLINABLE withLocal #-}
90+withLocal :: MonadReader r m => (r -> r) -> K.Stream m a -> K.Stream m a
91+withLocal f m =
92+ K.mkStream $ \st yld sng stp ->
93+ let single = local f . sng
94+ yieldk a r = local f $ yld a (withLocal f r)
95+ in K.foldStream st yieldk single (local f stp) m
96+
97+------------------------------------------------------------------------------
98+-- mtl orphan instances
99+------------------------------------------------------------------------------
100+
101+instance (MonadReader r m) => MonadReader r (Stream m) where
102+ ask = lift ask
103+
104+ local f m = Stream.fromStreamK $ withLocal f (Stream.toStreamK m)
105+
106+instance (MonadState s m) => MonadState s (Stream m) where
107+ {-# INLINE get #-}
108+ get = lift get
109+
110+ {-# INLINE put #-}
111+ put x = lift (put x)
112+
113+ {-# INLINE state #-}
114+ state k = lift (state k)
115+
116+------------------------------------------------------------------------------
117+-- NFData - orphan instances
118+------------------------------------------------------------------------------
119+
120+instance NFData a => NFData (Stream Identity a) where
121+ {-# INLINE rnf #-}
122+ rnf xs = runIdentity $ Stream.fold (Fold.foldl' (\_ x -> rnf x) ()) xs
123+
124+instance NFData1 (Stream Identity) where
125+ {-# INLINE liftRnf #-}
126+ liftRnf f xs = runIdentity $ Stream.fold (Fold.foldl' (\_ x -> f x) ()) xs
127+
86------------------------------------------------------------------------------
128------------------------------------------------------------------------------
87-- SerialT
129-- SerialT
88------------------------------------------------------------------------------
130------------------------------------------------------------------------------
src/Streamly/Internal/Unicode/Utf8.hs+1−4
@@ -27,7 +27,6 @@ where
27-- Imports
27-- Imports
28--------------------------------------------------------------------------------
28--------------------------------------------------------------------------------
29
29
30−import Control.DeepSeq (NFData)
31import Data.Word (Word8)
30import Data.Word (Word8)
32import Streamly.Data.Array (Array)
31import Streamly.Data.Array (Array)
33import System.IO.Unsafe (unsafePerformIO)
32import System.IO.Unsafe (unsafePerformIO)
@@ -45,9 +44,7 @@ import qualified Streamly.Internal.Unicode.Stream as Unicode
45--------------------------------------------------------------------------------
44--------------------------------------------------------------------------------
46
45
47-- | A space efficient, packed, unboxed Unicode container.
46-- | A space efficient, packed, unboxed Unicode container.
48−newtype Utf8 =
49− Utf8 (Array Word8)
47+newtype Utf8 = Utf8 (Array Word8)
50− deriving (NFData)
51
48
52--------------------------------------------------------------------------------
49--------------------------------------------------------------------------------
53-- Functions
50-- Functions
streamly.cabal+1
@@ -342,6 +342,7 @@ library
342
342
343 Streamly.Internal.Data.IsMap
343 Streamly.Internal.Data.IsMap
344 , Streamly.Internal.Data.IsMap.HashMap
344 , Streamly.Internal.Data.IsMap.HashMap
345+ , Streamly.Internal.Data.Cont
345
346
346 -- streamly-concurrent
347 -- streamly-concurrent
347 , Streamly.Internal.Control.Concurrent
348 , Streamly.Internal.Control.Concurrent