on master help sign in
Merge pull request #1696 from composewell/Rename_Storable_constraint_Unboxed
d2aaef0Harendra Kumar
benchmark/Streamly/Benchmark/Data/Array/Stream/Foreign.hs+3−3
@@ -48,7 +48,7 @@ import Streamly.Benchmark.Common
48import Streamly.Benchmark.Common.Handle
48import Streamly.Benchmark.Common.Handle
49
49
50#ifdef INSPECTION
50#ifdef INSPECTION
51−import Streamly.Internal.Data.Unboxed (Storable)
51+import Streamly.Internal.Data.Unboxed (Unboxed)
52import Streamly.Internal.Data.Stream.StreamD.Type (Step(..))
52import Streamly.Internal.Data.Stream.StreamD.Type (Step(..))
53import Test.Inspection
53import Test.Inspection
54#endif
54#endif
@@ -185,7 +185,7 @@ copyChunksSplitInterposeSuffix inh outh =
185 $ Handle.getChunks inh
185 $ Handle.getChunks inh
186
186
187#ifdef INSPECTION
187#ifdef INSPECTION
188−inspect $ hasNoTypeClassesExcept 'copyChunksSplitInterposeSuffix [''Storable]
188+inspect $ hasNoTypeClassesExcept 'copyChunksSplitInterposeSuffix [''Unboxed]
189inspect $ 'copyChunksSplitInterposeSuffix `hasNoType` ''Step
189inspect $ 'copyChunksSplitInterposeSuffix `hasNoType` ''Step
190#endif
190#endif
191
191
@@ -200,7 +200,7 @@ copyChunksSplitInterpose inh outh =
200 $ Handle.getChunks inh
200 $ Handle.getChunks inh
201
201
202#ifdef INSPECTION
202#ifdef INSPECTION
203−inspect $ hasNoTypeClassesExcept 'copyChunksSplitInterpose [''Storable]
203+inspect $ hasNoTypeClassesExcept 'copyChunksSplitInterpose [''Unboxed]
204inspect $ 'copyChunksSplitInterpose `hasNoType` ''Step
204inspect $ 'copyChunksSplitInterpose `hasNoType` ''Step
205#endif
205#endif
206
206
benchmark/Streamly/Benchmark/Unicode/Stream.hs+2−2
@@ -35,7 +35,7 @@ import Streamly.Benchmark.Common
35import Streamly.Benchmark.Common.Handle
35import Streamly.Benchmark.Common.Handle
36
36
37#ifdef INSPECTION
37#ifdef INSPECTION
38−import Streamly.Internal.Data.Unboxed (Storable)
38+import Streamly.Internal.Data.Unboxed (Unboxed)
39import Streamly.Internal.Data.Stream.StreamD.Type (Step(..))
39import Streamly.Internal.Data.Stream.StreamD.Type (Step(..))
40import qualified Streamly.Internal.Data.Fold.Type as Fold
40import qualified Streamly.Internal.Data.Fold.Type as Fold
41import qualified Streamly.Internal.Data.Tuple.Strict as Strict
41import qualified Streamly.Internal.Data.Tuple.Strict as Strict
@@ -105,7 +105,7 @@ linesUnlinesArrayCharCopy inh outh =
105 $ Stream.unfold Handle.read inh
105 $ Stream.unfold Handle.read inh
106
106
107#ifdef INSPECTION
107#ifdef INSPECTION
108−inspect $ hasNoTypeClassesExcept 'linesUnlinesArrayCharCopy [''Storable]
108+inspect $ hasNoTypeClassesExcept 'linesUnlinesArrayCharCopy [''Unboxed]
109-- inspect $ 'linesUnlinesArrayCharCopy `hasNoType` ''Step
109-- inspect $ 'linesUnlinesArrayCharCopy `hasNoType` ''Step
110#endif
110#endif
111
111
core/src/Streamly/Internal/Data/Array/Stream/Fold/Foreign.hs+5−5
@@ -60,7 +60,7 @@ import Control.Applicative (liftA2)
60import Control.Exception (assert)
60import Control.Exception (assert)
61import Control.Monad.Catch (MonadThrow)
61import Control.Monad.Catch (MonadThrow)
62import Control.Monad.IO.Class (MonadIO(..))
62import Control.Monad.IO.Class (MonadIO(..))
63−import Streamly.Internal.Data.Unboxed (Storable, peekWith, sizeOf)
63+import Streamly.Internal.Data.Unboxed (peekWith, sizeOf, Unboxed)
64import GHC.Types (SPEC(..))
64import GHC.Types (SPEC(..))
65import Streamly.Internal.Data.Array.Unboxed.Mut.Type (touch)
65import Streamly.Internal.Data.Array.Unboxed.Mut.Type (touch)
66import Streamly.Internal.Data.Array.Unboxed.Type (Array(..))
66import Streamly.Internal.Data.Array.Unboxed.Type (Array(..))
@@ -97,7 +97,7 @@ newtype ArrayFold m a b = ArrayFold (ParserD.Parser m (Array a) b)
97--
97--
98-- /Pre-release/
98-- /Pre-release/
99{-# INLINE fromFold #-}
99{-# INLINE fromFold #-}
100−fromFold :: forall m a b. (MonadIO m, Storable a) =>
100+fromFold :: forall m a b. (MonadIO m, Unboxed a) =>
101 Fold.Fold m a b -> ArrayFold m a b
101 Fold.Fold m a b -> ArrayFold m a b
102fromFold (Fold.Fold fstep finitial fextract) =
102fromFold (Fold.Fold fstep finitial fextract) =
103 ArrayFold (ParserD.Parser step initial fextract)
103 ArrayFold (ParserD.Parser step initial fextract)
@@ -135,7 +135,7 @@ fromFold (Fold.Fold fstep finitial fextract) =
135--
135--
136-- /Pre-release/
136-- /Pre-release/
137{-# INLINE fromParserD #-}
137{-# INLINE fromParserD #-}
138−fromParserD :: forall m a b. (MonadIO m, Storable a) =>
138+fromParserD :: forall m a b. (MonadIO m, Unboxed a) =>
139 ParserD.Parser m a b -> ArrayFold m a b
139 ParserD.Parser m a b -> ArrayFold m a b
140fromParserD (ParserD.Parser step1 initial1 extract1) =
140fromParserD (ParserD.Parser step1 initial1 extract1) =
141 ArrayFold (ParserD.Parser step initial1 extract1)
141 ArrayFold (ParserD.Parser step initial1 extract1)
@@ -177,7 +177,7 @@ fromParserD (ParserD.Parser step1 initial1 extract1) =
177--
177--
178-- /Pre-release/
178-- /Pre-release/
179{-# INLINE fromParser #-}
179{-# INLINE fromParser #-}
180−fromParser :: forall m a b. (MonadThrow m, MonadIO m, Storable a) =>
180+fromParser :: forall m a b. (MonadThrow m, MonadIO m, Unboxed a) =>
181 Parser.Parser m a b -> ArrayFold m a b
181 Parser.Parser m a b -> ArrayFold m a b
182fromParser = fromParserD . ParserD.fromParserK
182fromParser = fromParserD . ParserD.fromParserK
183
183
@@ -301,7 +301,7 @@ instance MonadThrow m => Monad (ArrayFold m a) where
301
301
302-- | Take @n@ array elements (@a@) from a stream of arrays (@Array a@).
302-- | Take @n@ array elements (@a@) from a stream of arrays (@Array a@).
303{-# INLINE take #-}
303{-# INLINE take #-}
304−take :: forall m a b. (Monad m, Storable a) =>
304+take :: forall m a b. (Monad m, Unboxed a) =>
305 Int -> ArrayFold m a b -> ArrayFold m a b
305 Int -> ArrayFold m a b -> ArrayFold m a b
306take n (ArrayFold (ParserD.Parser step1 initial1 extract1)) =
306take n (ArrayFold (ParserD.Parser step1 initial1 extract1)) =
307 ArrayFold $ ParserD.Parser step initial extract
307 ArrayFold $ ParserD.Parser step initial extract
core/src/Streamly/Internal/Data/Array/Stream/Mut/Foreign.hs+10−10
@@ -31,7 +31,7 @@ import Control.Monad.IO.Class (MonadIO(..))
31import Control.Monad (when)
31import Control.Monad (when)
32import Control.Monad.Catch (MonadThrow)
32import Control.Monad.Catch (MonadThrow)
33import Data.Bifunctor (first)
33import Data.Bifunctor (first)
34−import Streamly.Internal.Data.Unboxed (Storable, sizeOf)
34+import Streamly.Internal.Data.Unboxed (Unboxed, sizeOf)
35import Streamly.Internal.Data.Array.Unboxed.Mut.Type (Array(..))
35import Streamly.Internal.Data.Array.Unboxed.Mut.Type (Array(..))
36import Streamly.Internal.Data.Fold.Type (Fold(..))
36import Streamly.Internal.Data.Fold.Type (Fold(..))
37import Streamly.Internal.Data.Stream.Type (Stream)
37import Streamly.Internal.Data.Stream.Type (Stream)
@@ -52,7 +52,7 @@ import qualified Streamly.Internal.Data.Stream.Type as Stream
52--
52--
53-- /Pre-release/
53-- /Pre-release/
54{-# INLINE arraysOf #-}
54{-# INLINE arraysOf #-}
55−arraysOf :: (MonadIO m, Storable a)
55+arraysOf :: (MonadIO m, Unboxed a)
56 => Int -> Stream m a -> Stream m (Array a)
56 => Int -> Stream m a -> Stream m (Array a)
57arraysOf n = Stream.fromStreamD . MArray.arraysOf n . Stream.toStreamD
57arraysOf n = Stream.fromStreamD . MArray.arraysOf n . Stream.toStreamD
58
58
@@ -81,7 +81,7 @@ data SpliceState s arr
81--
81--
82-- @since 0.7.0
82-- @since 0.7.0
83{-# INLINE_NORMAL packArraysChunksOf #-}
83{-# INLINE_NORMAL packArraysChunksOf #-}
84−packArraysChunksOf :: (MonadIO m, Storable a)
84+packArraysChunksOf :: (MonadIO m, Unboxed a)
85 => Int -> D.Stream m (Array a) -> D.Stream m (Array a)
85 => Int -> D.Stream m (Array a) -> D.Stream m (Array a)
86packArraysChunksOf n (D.Stream step state) =
86packArraysChunksOf n (D.Stream step state) =
87 D.Stream step' (SpliceInitial state)
87 D.Stream step' (SpliceInitial state)
@@ -129,7 +129,7 @@ packArraysChunksOf n (D.Stream step state) =
129-- lpackArraysChunksOf = Fold.many compactLEFold
129-- lpackArraysChunksOf = Fold.many compactLEFold
130--
130--
131{-# INLINE_NORMAL lpackArraysChunksOf #-}
131{-# INLINE_NORMAL lpackArraysChunksOf #-}
132−lpackArraysChunksOf :: (MonadIO m, Storable a)
132+lpackArraysChunksOf :: (MonadIO m, Unboxed a)
133 => Int -> Fold m (Array a) () -> Fold m (Array a) ()
133 => Int -> Fold m (Array a) () -> Fold m (Array a) ()
134lpackArraysChunksOf n (Fold step1 initial1 extract1) =
134lpackArraysChunksOf n (Fold step1 initial1 extract1) =
135 Fold step initial extract
135 Fold step initial extract
@@ -191,7 +191,7 @@ lpackArraysChunksOf n (Fold step1 initial1 extract1) =
191--
191--
192-- /Internal/
192-- /Internal/
193{-# INLINE compact #-}
193{-# INLINE compact #-}
194−compact :: (MonadIO m, Storable a)
194+compact :: (MonadIO m, Unboxed a)
195 => Int -> Stream m (Array a) -> Stream m (Array a)
195 => Int -> Stream m (Array a) -> Stream m (Array a)
196compact n = Stream.fromStreamD . packArraysChunksOf n . Stream.toStreamD
196compact n = Stream.fromStreamD . packArraysChunksOf n . Stream.toStreamD
197
197
@@ -204,7 +204,7 @@ compact n = Stream.fromStreamD . packArraysChunksOf n . Stream.toStreamD
204-- /Internal/
204-- /Internal/
205{-# INLINE_NORMAL compactLEParserD #-}
205{-# INLINE_NORMAL compactLEParserD #-}
206compactLEParserD ::
206compactLEParserD ::
207− forall m a. (MonadThrow m, MonadIO m, Storable a)
207+ forall m a. (MonadThrow m, MonadIO m, Unboxed a)
208 => Int -> ParserD.Parser m (Array a) (Array a)
208 => Int -> ParserD.Parser m (Array a) (Array a)
209compactLEParserD n = ParserD.Parser step initial extract
209compactLEParserD n = ParserD.Parser step initial extract
210
210
@@ -254,7 +254,7 @@ compactLEParserD n = ParserD.Parser step initial extract
254-- /Internal/
254-- /Internal/
255{-# INLINE_NORMAL compactGEFold #-}
255{-# INLINE_NORMAL compactGEFold #-}
256compactGEFold ::
256compactGEFold ::
257− forall m a. (MonadIO m, Storable a)
257+ forall m a. (MonadIO m, Unboxed a)
258 => Int -> FL.Fold m (Array a) (Array a)
258 => Int -> FL.Fold m (Array a) (Array a)
259compactGEFold n = Fold step initial extract
259compactGEFold n = Fold step initial extract
260
260
@@ -298,7 +298,7 @@ compactGEFold n = Fold step initial extract
298-- maximum specified size in bytes.
298-- maximum specified size in bytes.
299--
299--
300-- /Internal/
300-- /Internal/
301−compactLE :: (MonadThrow m, MonadIO m, Storable a) =>
301+compactLE :: (MonadThrow m, MonadIO m, Unboxed a) =>
302 Int -> Stream m (Array a) -> Stream m (Array a)
302 Int -> Stream m (Array a) -> Stream m (Array a)
303compactLE n =
303compactLE n =
304 Stream.fromStreamD . D.parseMany (compactLEParserD n) . Stream.toStreamD
304 Stream.fromStreamD . D.parseMany (compactLEParserD n) . Stream.toStreamD
@@ -308,7 +308,7 @@ compactLE n =
308--
308--
309-- /Unimplemented/
309-- /Unimplemented/
310{-# INLINE compactEQ #-}
310{-# INLINE compactEQ #-}
311−compactEQ :: -- (MonadIO m, Storable a) =>
311+compactEQ :: -- (MonadIO m, Unboxed a) =>
312 Int -> Stream m (Array a) -> Stream m (Array a)
312 Int -> Stream m (Array a) -> Stream m (Array a)
313compactEQ _n _xs = undefined
313compactEQ _n _xs = undefined
314 -- IsStream.fromStreamD $ D.foldMany (compactEQFold n) (IsStream.toStreamD xs)
314 -- IsStream.fromStreamD $ D.foldMany (compactEQFold n) (IsStream.toStreamD xs)
@@ -319,7 +319,7 @@ compactEQ _n _xs = undefined
319-- /Internal/
319-- /Internal/
320{-# INLINE compactGE #-}
320{-# INLINE compactGE #-}
321compactGE ::
321compactGE ::
322− (MonadIO m, Storable a)
322+ (MonadIO m, Unboxed a)
323 => Int -> Stream m (Array a) -> Stream m (Array a)
323 => Int -> Stream m (Array a) -> Stream m (Array a)
324compactGE n =
324compactGE n =
325 Stream.fromStreamD . D.foldMany (compactGEFold n) . Stream.toStreamD
325 Stream.fromStreamD . D.foldMany (compactGEFold n) . Stream.toStreamD
core/src/Streamly/Internal/Data/Array/Unboxed.hs+21−22
@@ -116,10 +116,8 @@ import Data.Functor.Identity (Identity)
116import Data.Word (Word8)
116import Data.Word (Word8)
117import Foreign.C.String (CString)
117import Foreign.C.String (CString)
118import Foreign.Ptr (castPtr)
118import Foreign.Ptr (castPtr)
119−import qualified Foreign.Storable as Storable (Storable)
120import Streamly.Internal.Data.Unboxed
119import Streamly.Internal.Data.Unboxed
121− ( Storable
122− , Unboxed
120+ ( Unboxed
123 , castContents
121 , castContents
124 , peekWith
122 , peekWith
125 , sizeOf
123 , sizeOf
@@ -136,6 +134,7 @@ import Streamly.Internal.Data.Tuple.Strict (Tuple3Fused'(..))
136import Streamly.Internal.Data.Unfold.Type (Unfold(..))
134import Streamly.Internal.Data.Unfold.Type (Unfold(..))
137import Streamly.Internal.System.IO (unsafeInlineIO)
135import Streamly.Internal.System.IO (unsafeInlineIO)
138
136
137+import qualified Foreign.Storable as Storable
139import qualified Streamly.Internal.Data.Array.Unboxed.Mut.Type as MA
138import qualified Streamly.Internal.Data.Array.Unboxed.Mut.Type as MA
140import qualified Streamly.Internal.Data.Array.Unboxed.Mut as MA
139import qualified Streamly.Internal.Data.Array.Unboxed.Mut as MA
141import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
140import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
@@ -158,7 +157,7 @@ import qualified Streamly.Internal.Data.Unfold as Unfold
158--
157--
159-- /Pre-release/
158-- /Pre-release/
160{-# INLINE fromStreamN #-}
159{-# INLINE fromStreamN #-}
161−fromStreamN :: (MonadIO m, Storable a) => Int -> Stream m a -> m (Array a)
160+fromStreamN :: (MonadIO m, Unboxed a) => Int -> Stream m a -> m (Array a)
162fromStreamN n m = do
161fromStreamN n m = do
163 when (n < 0) $ error "writeN: negative write count specified"
162 when (n < 0) $ error "writeN: negative write count specified"
164 A.fromStreamDN n $ Stream.toStreamD m
163 A.fromStreamDN n $ Stream.toStreamD m
@@ -173,7 +172,7 @@ fromStreamN n m = do
173--
172--
174-- /Pre-release/
173-- /Pre-release/
175{-# INLINE fromStream #-}
174{-# INLINE fromStream #-}
176−fromStream :: (MonadIO m, Storable a) => Stream m a -> m (Array a)
175+fromStream :: (MonadIO m, Unboxed a) => Stream m a -> m (Array a)
177fromStream m = P.fold A.write $ Stream.toStreamK m
176fromStream m = P.fold A.write $ Stream.toStreamK m
178-- write m = A.fromStreamD $ D.fromStreamK m
177-- write m = A.fromStreamD $ D.fromStreamK m
179
178
@@ -182,7 +181,7 @@ fromStream m = P.fold A.write $ Stream.toStreamK m
182-------------------------------------------------------------------------------
181-------------------------------------------------------------------------------
183
182
184{-# INLINE_NORMAL producer #-}
183{-# INLINE_NORMAL producer #-}
185−producer :: forall m a. (Monad m, Storable a) => Producer m (Array a) a
184+producer :: forall m a. (Monad m, Unboxed a) => Producer m (Array a) a
186producer =
185producer =
187 Producer.translate A.unsafeThaw A.unsafeFreeze
186 Producer.translate A.unsafeThaw A.unsafeFreeze
188 $ MA.producerWith (return . unsafeInlineIO)
187 $ MA.producerWith (return . unsafeInlineIO)
@@ -193,7 +192,7 @@ producer =
193--
192--
194-- @since 0.8.0
193-- @since 0.8.0
195{-# INLINE_NORMAL read #-}
194{-# INLINE_NORMAL read #-}
196−read :: forall m a. (Monad m, Storable a) => Unfold m (Array a) a
195+read :: forall m a. (Monad m, Unboxed a) => Unfold m (Array a) a
197read = Producer.simplify producer
196read = Producer.simplify producer
198
197
199-- | Unfold an array into a stream, does not check the end of the array, the
198-- | Unfold an array into a stream, does not check the end of the array, the
@@ -208,7 +207,7 @@ read = Producer.simplify producer
208-- /Pre-release/
207-- /Pre-release/
209--
208--
210{-# INLINE_NORMAL unsafeRead #-}
209{-# INLINE_NORMAL unsafeRead #-}
211−unsafeRead :: forall m a. (Monad m, Storable a) => Unfold m (Array a) a
210+unsafeRead :: forall m a. (Monad m, Unboxed a) => Unfold m (Array a) a
212unsafeRead = Unfold step inject
211unsafeRead = Unfold step inject
213 where
212 where
214
213
@@ -243,7 +242,7 @@ null arr = A.byteLength arr == 0
243--
242--
244-- /Pre-release/
243-- /Pre-release/
245{-# INLINE getIndexRev #-}
244{-# INLINE getIndexRev #-}
246−getIndexRev :: forall a. Storable a => Int -> Array a -> Maybe a
245+getIndexRev :: forall a. Unboxed a => Int -> Array a -> Maybe a
247getIndexRev i arr =
246getIndexRev i arr =
248 unsafeInlineIO
247 unsafeInlineIO
249 $ do
248 $ do
@@ -259,7 +258,7 @@ getIndexRev i arr =
259--
258--
260-- /Pre-release/
259-- /Pre-release/
261{-# INLINE last #-}
260{-# INLINE last #-}
262−last :: Storable a => Array a -> Maybe a
261+last :: Unboxed a => Array a -> Maybe a
263last = getIndexRev 0
262last = getIndexRev 0
264
263
265-------------------------------------------------------------------------------
264-------------------------------------------------------------------------------
@@ -352,7 +351,7 @@ find = Unfold.fold Fold.null . Stream.unfold (findIndicesOf p)
352-- /Pre-release/
351-- /Pre-release/
353{-# INLINE getSliceUnsafe #-}
352{-# INLINE getSliceUnsafe #-}
354getSliceUnsafe ::
353getSliceUnsafe ::
355− forall a. Storable a
354+ forall a. Unboxed a
356 => Int -- ^ starting index
355 => Int -- ^ starting index
357 -> Int -- ^ length of the slice
356 -> Int -- ^ length of the slice
358 -> Array a
357 -> Array a
@@ -368,7 +367,7 @@ getSliceUnsafe index len (Array contents start e) =
368--
367--
369-- /Pre-release/
368-- /Pre-release/
370{-# INLINE splitOn #-}
369{-# INLINE splitOn #-}
371−splitOn :: (Monad m, Storable a) =>
370+splitOn :: (Monad m, Unboxed a) =>
372 (a -> Bool) -> Array a -> Stream m (Array a)
371 (a -> Bool) -> Array a -> Stream m (Array a)
373splitOn predicate arr =
372splitOn predicate arr =
374 Stream.fromStreamD
373 Stream.fromStreamD
@@ -376,7 +375,7 @@ splitOn predicate arr =
376 $ D.sliceOnSuffix predicate (A.toStreamD arr)
375 $ D.sliceOnSuffix predicate (A.toStreamD arr)
377
376
378{-# INLINE genSlicesFromLen #-}
377{-# INLINE genSlicesFromLen #-}
379−genSlicesFromLen :: forall m a. (Monad m, Storable a)
378+genSlicesFromLen :: forall m a. (Monad m, Unboxed a)
380 => Int -- ^ from index
379 => Int -- ^ from index
381 -> Int -- ^ length of the slice
380 -> Int -- ^ length of the slice
382 -> Unfold m (Array a) (Int, Int)
381 -> Unfold m (Array a) (Int, Int)
@@ -389,7 +388,7 @@ genSlicesFromLen from len =
389--
388--
390-- /Pre-release//
389-- /Pre-release//
391{-# INLINE getSlicesFromLen #-}
390{-# INLINE getSlicesFromLen #-}
392−getSlicesFromLen :: forall m a. (Monad m, Storable a)
391+getSlicesFromLen :: forall m a. (Monad m, Unboxed a)
393 => Int -- ^ from index
392 => Int -- ^ from index
394 -> Int -- ^ length of the slice
393 -> Int -- ^ length of the slice
395 -> Unfold m (Array a) (Array a)
394 -> Unfold m (Array a) (Array a)
@@ -408,7 +407,7 @@ getSlicesFromLen from len =
408--
407--
409-- @since 0.8.0
408-- @since 0.8.0
410{-# INLINE getIndex #-}
409{-# INLINE getIndex #-}
411−getIndex :: forall a. Storable a => Int -> Array a -> Maybe a
410+getIndex :: forall a. Unboxed a => Int -> Array a -> Maybe a
412getIndex i arr =
411getIndex i arr =
413 unsafeInlineIO
412 unsafeInlineIO
414 $ do
413 $ do
@@ -435,7 +434,7 @@ getIndex i arr =
435--
434--
436-- /Pre-release/
435-- /Pre-release/
437{-# INLINE getIndices #-}
436{-# INLINE getIndices #-}
438−getIndices :: (Monad m, Storable a) => Stream m Int -> Unfold m (Array a) a
437+getIndices :: (Monad m, Unboxed a) => Stream m Int -> Unfold m (Array a) a
439getIndices m =
438getIndices m =
440 let unf = MA.getIndicesD (return . unsafeInlineIO) $ D.fromStreamK $ Stream.toStreamK m
439 let unf = MA.getIndicesD (return . unsafeInlineIO) $ D.fromStreamK $ Stream.toStreamK m
441 in Unfold.lmap A.unsafeThaw unf
440 in Unfold.lmap A.unsafeThaw unf
@@ -472,7 +471,7 @@ getIndicesFromThenTo = undefined
472--
471--
473-- @since 0.7.0
472-- @since 0.7.0
474{-# INLINE runPipe #-}
473{-# INLINE runPipe #-}
475−runPipe :: (MonadIO m, Storable a, Storable b)
474+runPipe :: (MonadIO m, Unboxed a, Unboxed b)
476 => Pipe m a b -> Array a -> m (Array b)
475 => Pipe m a b -> Array a -> m (Array b)
477runPipe f arr = P.runPipe (toArrayMinChunk (length arr)) $ f (A.read arr)
476runPipe f arr = P.runPipe (toArrayMinChunk (length arr)) $ f (A.read arr)
478-}
477-}
@@ -485,7 +484,7 @@ runPipe f arr = P.runPipe (toArrayMinChunk (length arr)) $ f (A.read arr)
485--
484--
486-- /Pre-release/
485-- /Pre-release/
487{-# INLINE streamTransform #-}
486{-# INLINE streamTransform #-}
488−streamTransform :: forall m a b. (MonadIO m, Storable a, Storable b)
487+streamTransform :: forall m a b. (MonadIO m, Unboxed a, Unboxed b)
489 => (Stream m a -> Stream m b) -> Array a -> m (Array b)
488 => (Stream m a -> Stream m b) -> Array a -> m (Array b)
490streamTransform f arr =
489streamTransform f arr =
491 P.fold (A.writeWith (length arr)) $ Stream.toStreamK $ f (A.toStream arr)
490 P.fold (A.writeWith (length arr)) $ Stream.toStreamK $ f (A.toStream arr)
@@ -503,7 +502,7 @@ streamTransform f arr =
503--
502--
504castUnsafe ::
503castUnsafe ::
505#ifdef DEVBUILD
504#ifdef DEVBUILD
506− Storable b =>
505+ Unboxed b =>
507#endif
506#endif
508 Array a -> Array b
507 Array a -> Array b
509castUnsafe (Array contents start end) =
508castUnsafe (Array contents start end) =
@@ -522,7 +521,7 @@ asBytes = castUnsafe
522--
521--
523-- @since 0.8.0
522-- @since 0.8.0
524--
523--
525−cast :: forall a b. (Storable b) => Array a -> Maybe (Array b)
524+cast :: forall a b. (Unboxed b) => Array a -> Maybe (Array b)
526cast arr =
525cast arr =
527 let len = A.byteLength arr
526 let len = A.byteLength arr
528 r = len `mod` SIZE_OF(b)
527 r = len `mod` SIZE_OF(b)
@@ -552,12 +551,12 @@ asCStringUnsafe arr act = do
552--
551--
553-- /Pre-release/
552-- /Pre-release/
554{-# INLINE fold #-}
553{-# INLINE fold #-}
555−fold :: forall m a b. (Monad m, Storable a) => Fold m a b -> Array a -> m b
554+fold :: forall m a b. (Monad m, Unboxed a) => Fold m a b -> Array a -> m b
556fold f arr = P.fold f (Stream.toStreamK (A.toStream arr))
555fold f arr = P.fold f (Stream.toStreamK (A.toStream arr))
557
556
558-- | Fold an array using a stream fold operation.
557-- | Fold an array using a stream fold operation.
559--
558--
560-- /Pre-release/
559-- /Pre-release/
561{-# INLINE streamFold #-}
560{-# INLINE streamFold #-}
562−streamFold :: (Monad m, Storable a) => (Stream m a -> m b) -> Array a -> m b
561+streamFold :: (Monad m, Unboxed a) => (Stream m a -> m b) -> Array a -> m b
563streamFold f arr = f (A.toStream arr)
562streamFold f arr = f (A.toStream arr)
core/src/Streamly/Internal/Data/Array/Unboxed/Mut.hs+6−6
@@ -8,7 +8,7 @@
8-- Stability : experimental
8-- Stability : experimental
9-- Portability : GHC
9-- Portability : GHC
10--
10--
11−-- Unboxed pinned mutable array type for 'Storable' types with an option to use
11+-- Unboxed pinned mutable array type for 'Unboxed' types with an option to use
12-- foreign (non-GHC) memory allocators. Fulfils the following goals:
12-- foreign (non-GHC) memory allocators. Fulfils the following goals:
13--
13--
14-- * Random access (array)
14-- * Random access (array)
@@ -33,7 +33,7 @@ module Streamly.Internal.Data.Array.Unboxed.Mut
33where
33where
34
34
35import Control.Monad.IO.Class (MonadIO(..))
35import Control.Monad.IO.Class (MonadIO(..))
36−import Streamly.Internal.Data.Unboxed (Storable)
36+import Streamly.Internal.Data.Unboxed (Unboxed)
37import Streamly.Internal.Data.Stream (Stream)
37import Streamly.Internal.Data.Stream (Stream)
38import Streamly.Internal.Data.Unfold.Type (Unfold(..))
38import Streamly.Internal.Data.Unfold.Type (Unfold(..))
39
39
@@ -50,7 +50,7 @@ import Streamly.Internal.Data.Array.Unboxed.Mut.Type
50--
50--
51-- /Pre-release/
51-- /Pre-release/
52{-# INLINE splitOn #-}
52{-# INLINE splitOn #-}
53−splitOn :: (MonadIO m, Storable a) =>
53+splitOn :: (MonadIO m, Unboxed a) =>
54 (a -> Bool) -> Array a -> Stream m (Array a)
54 (a -> Bool) -> Array a -> Stream m (Array a)
55splitOn predicate arr =
55splitOn predicate arr =
56 Stream.fromStreamD
56 Stream.fromStreamD
@@ -63,7 +63,7 @@ splitOn predicate arr =
63--
63--
64-- /Pre-release/
64-- /Pre-release/
65{-# INLINE genSlicesFromLen #-}
65{-# INLINE genSlicesFromLen #-}
66−genSlicesFromLen :: forall m a. (Monad m, Storable a)
66+genSlicesFromLen :: forall m a. (Monad m, Unboxed a)
67 => Int -- ^ from index
67 => Int -- ^ from index
68 -> Int -- ^ length of the slice
68 -> Int -- ^ length of the slice
69 -> Unfold m (Array a) (Int, Int)
69 -> Unfold m (Array a) (Int, Int)
@@ -80,7 +80,7 @@ genSlicesFromLen from len =
80--
80--
81-- /Pre-release/
81-- /Pre-release/
82{-# INLINE getSlicesFromLen #-}
82{-# INLINE getSlicesFromLen #-}
83−getSlicesFromLen :: forall m a. (Monad m, Storable a)
83+getSlicesFromLen :: forall m a. (Monad m, Unboxed a)
84 => Int -- ^ from index
84 => Int -- ^ from index
85 -> Int -- ^ length of the slice
85 -> Int -- ^ length of the slice
86 -> Unfold m (Array a) (Array a)
86 -> Unfold m (Array a) (Array a)
@@ -98,6 +98,6 @@ getSlicesFromLen from len =
98--
98--
99-- /Pre-release/
99-- /Pre-release/
100{-# INLINE fromStream #-}
100{-# INLINE fromStream #-}
101−fromStream :: (MonadIO m, Storable a) => Stream m a -> m (Array a)
101+fromStream :: (MonadIO m, Unboxed a) => Stream m a -> m (Array a)
102fromStream = fromStreamD . Stream.toStreamD
102fromStream = fromStreamD . Stream.toStreamD
103-- fromStream (Stream m) = P.fold write m
103-- fromStream (Stream m) = P.fold write m
core/src/Streamly/Internal/Data/Array/Unboxed/Mut/Type.hs+106−106
@@ -228,7 +228,7 @@ import Foreign.Ptr (plusPtr, minusPtr, nullPtr)
228import Streamly.Internal.Control.Exception (assertM)
228import Streamly.Internal.Control.Exception (assertM)
229import Streamly.Internal.Data.Unboxed
229import Streamly.Internal.Data.Unboxed
230 ( ArrayContents(..)
230 ( ArrayContents(..)
231− , Storable
231+ , Unboxed
232 , alignment
232 , alignment
233 , castContents
233 , castContents
234 , getMutableByteArray#
234 , getMutableByteArray#
@@ -289,11 +289,11 @@ foreign import ccall unsafe "string.h memchr" c_memchr
289foreign import ccall unsafe "string.h memcmp" c_memcmp
289foreign import ccall unsafe "string.h memcmp" c_memcmp
290 :: Ptr Word8 -> Ptr Word8 -> CSize -> IO CInt
290 :: Ptr Word8 -> Ptr Word8 -> CSize -> IO CInt
291
291
292−-- | Given a 'Storable' type (unused first arg) and a number of bytes, return
292+-- | Given an 'Unboxed' type (unused first arg) and a number of bytes, return
293-- how many elements of that type will completely fit in those bytes.
293-- how many elements of that type will completely fit in those bytes.
294--
294--
295{-# INLINE bytesToElemCount #-}
295{-# INLINE bytesToElemCount #-}
296−bytesToElemCount :: forall a. Storable a => a -> Int -> Int
296+bytesToElemCount :: forall a. Unboxed a => a -> Int -> Int
297bytesToElemCount _ n = n `div` SIZE_OF(a)
297bytesToElemCount _ n = n `div` SIZE_OF(a)
298
298
299-- XXX we are converting Int to CSize
299-- XXX we are converting Int to CSize
@@ -314,7 +314,7 @@ memcmp p1 p2 len = do
314
314
315-- $arrayNotes
315-- $arrayNotes
316--
316--
317−-- We can use a 'Storable' constraint in the Array type and the constraint can
317+-- We can use an 'Unboxed' constraint in the Array type and the constraint can
318-- be automatically provided to a function that pattern matches on the Array
318-- be automatically provided to a function that pattern matches on the Array
319-- type. However, it has huge performance cost, so we do not use it.
319-- type. However, it has huge performance cost, so we do not use it.
320-- Investigate a GHC improvement possiblity.
320-- Investigate a GHC improvement possiblity.
@@ -340,7 +340,7 @@ memcmp p1 p2 len = do
340--
340--
341data Array a =
341data Array a =
342#ifdef DEVBUILD
342#ifdef DEVBUILD
343− Storable a =>
343+ Unboxed a =>
344#endif
344#endif
345 -- The array is a range into arrContents. arrContents may be a superset of
345 -- The array is a range into arrContents. arrContents may be a superset of
346 -- the slice represented by the array. All offsets are in bytes.
346 -- the slice represented by the array. All offsets are in bytes.
@@ -394,7 +394,7 @@ unpin arr@(Array{..}) = do
394--
394--
395-- /Pre-release/
395-- /Pre-release/
396{-# INLINE newArrayWith #-}
396{-# INLINE newArrayWith #-}
397−newArrayWith :: forall m a. (MonadIO m, Storable a)
397+newArrayWith :: forall m a. (MonadIO m, Unboxed a)
398 => (Int -> Int -> m (ArrayContents a)) -> Int -> Int -> m (Array a)
398 => (Int -> Int -> m (ArrayContents a)) -> Int -> Int -> m (Array a)
399newArrayWith alloc alignSize count = do
399newArrayWith alloc alignSize count = do
400 let size = max (count * SIZE_OF(a)) 0
400 let size = max (count * SIZE_OF(a)) 0
@@ -425,17 +425,17 @@ nilArrayContents =
425
425
426nil ::
426nil ::
427#ifdef DEVBUILD
427#ifdef DEVBUILD
428− Storable a =>
428+ Unboxed a =>
429#endif
429#endif
430 Array a
430 Array a
431nil = Array nilArrayContents 0 0 0
431nil = Array nilArrayContents 0 0 0
432
432
433-- | Like 'newArrayWith' but using an allocator that aligns the memory to the
433-- | Like 'newArrayWith' but using an allocator that aligns the memory to the
434−-- alignment dictated by the 'Storable' instance of the type.
434+-- alignment dictated by the 'Unboxed' instance of the type.
435--
435--
436-- /Internal/
436-- /Internal/
437{-# INLINE newArrayAligned #-}
437{-# INLINE newArrayAligned #-}
438−newArrayAligned :: (MonadIO m, Storable a) => Int -> Int -> m (Array a)
438+newArrayAligned :: (MonadIO m, Unboxed a) => Int -> Int -> m (Array a)
439newArrayAligned = newArrayWith (\s a -> liftIO $ newAlignedArrayContents s a)
439newArrayAligned = newArrayWith (\s a -> liftIO $ newAlignedArrayContents s a)
440
440
441-- XXX Intead of newArray, make newPinnedArray and newUnpinnedArray. Make it
441-- XXX Intead of newArray, make newPinnedArray and newUnpinnedArray. Make it
@@ -443,21 +443,21 @@ newArrayAligned = newArrayWith (\s a -> liftIO $ newAlignedArrayContents s a)
443-- XXX can unaligned allocation be more efficient when alignment is not needed?
443-- XXX can unaligned allocation be more efficient when alignment is not needed?
444--
444--
445-- | Allocates an empty array that can hold 'count' items. The memory of the
445-- | Allocates an empty array that can hold 'count' items. The memory of the
446−-- array is uninitialized and the allocation is aligned as per the 'Storable'
446+-- array is uninitialized and the allocation is aligned as per the 'Unboxed'
447-- instance of the type.
447-- instance of the type.
448--
448--
449-- /Pre-release/
449-- /Pre-release/
450{-# INLINE newArray #-}
450{-# INLINE newArray #-}
451−newArray :: forall m a. (MonadIO m, Storable a) => Int -> m (Array a)
451+newArray :: forall m a. (MonadIO m, Unboxed a) => Int -> m (Array a)
452newArray = newArrayAligned (alignment (undefined :: a))
452newArray = newArrayAligned (alignment (undefined :: a))
453
453
454-- | Allocates a pinned empty array that can hold 'count' items. The memory of
454-- | Allocates a pinned empty array that can hold 'count' items. The memory of
455-- the array is uninitialized and the allocation is aligned as per the
455-- the array is uninitialized and the allocation is aligned as per the
456−-- 'Storable' instance of the type.
456+-- 'Unboxed' instance of the type.
457--
457--
458-- /Pre-release/
458-- /Pre-release/
459{-# INLINE newPinnedArrayBytes #-}
459{-# INLINE newPinnedArrayBytes #-}
460−newPinnedArrayBytes :: forall m a. (MonadIO m, Storable a) => Int -> m (Array a)
460+newPinnedArrayBytes :: forall m a. (MonadIO m, Unboxed a) => Int -> m (Array a)
461newPinnedArrayBytes bytes = do
461newPinnedArrayBytes bytes = do
462 contents <-
462 contents <-
463 liftIO $ newAlignedArrayContents bytes (alignment (undefined :: a))
463 liftIO $ newAlignedArrayContents bytes (alignment (undefined :: a))
@@ -474,7 +474,7 @@ newPinnedArrayBytes bytes = do
474-- /Internal/
474-- /Internal/
475{-# INLINE withNewArrayUnsafe #-}
475{-# INLINE withNewArrayUnsafe #-}
476withNewArrayUnsafe ::
476withNewArrayUnsafe ::
477− (MonadIO m, Storable a) => Int -> (Ptr a -> m ()) -> m (Array a)
477+ (MonadIO m, Unboxed a) => Int -> (Ptr a -> m ()) -> m (Array a)
478withNewArrayUnsafe count f = do
478withNewArrayUnsafe count f = do
479 arr <- newArray count
479 arr <- newArray count
480 asPtrUnsafe arr
480 asPtrUnsafe arr
@@ -489,7 +489,7 @@ withNewArrayUnsafe count f = do
489--
489--
490-- /Pre-release/
490-- /Pre-release/
491{-# INLINE putIndexUnsafe #-}
491{-# INLINE putIndexUnsafe #-}
492−putIndexUnsafe :: forall m a. (MonadIO m, Storable a)
492+putIndexUnsafe :: forall m a. (MonadIO m, Unboxed a)
493 => Int -> a -> Array a -> m ()
493 => Int -> a -> Array a -> m ()
494putIndexUnsafe i x (Array {..}) = do
494putIndexUnsafe i x (Array {..}) = do
495 let index = INDEX_OF(arrStart, i, a)
495 let index = INDEX_OF(arrStart, i, a)
@@ -509,7 +509,7 @@ invalidIndex label i =
509--
509--
510-- /Pre-release/
510-- /Pre-release/
511{-# INLINE putIndex #-}
511{-# INLINE putIndex #-}
512−putIndex :: forall m a. (MonadIO m, Storable a) => Int -> a -> Array a -> m ()
512+putIndex :: forall m a. (MonadIO m, Unboxed a) => Int -> a -> Array a -> m ()
513putIndex i x Array{..} = do
513putIndex i x Array{..} = do
514 let index = INDEX_OF(arrStart,i,a)
514 let index = INDEX_OF(arrStart,i,a)
515 if i >= 0 && INDEX_VALID(index,aEnd,a)
515 if i >= 0 && INDEX_VALID(index,aEnd,a)
@@ -521,7 +521,7 @@ putIndex i x Array{..} = do
521--
521--
522-- /Pre-release/
522-- /Pre-release/
523{-# INLINE putIndices #-}
523{-# INLINE putIndices #-}
524−putIndices :: forall m a. (MonadIO m, Storable a)
524+putIndices :: forall m a. (MonadIO m, Unboxed a)
525 => Array a -> Fold m (Int, a) ()
525 => Array a -> Fold m (Int, a) ()
526putIndices arr = FL.foldlM' step (return ())
526putIndices arr = FL.foldlM' step (return ())
527
527
@@ -532,7 +532,7 @@ putIndices arr = FL.foldlM' step (return ())
532-- | Modify a given index of an array using a modifier function.
532-- | Modify a given index of an array using a modifier function.
533--
533--
534-- /Pre-release/
534-- /Pre-release/
535−modifyIndexUnsafe :: forall m a b. (MonadIO m, Storable a) =>
535+modifyIndexUnsafe :: forall m a b. (MonadIO m, Unboxed a) =>
536 Int -> (a -> (a, b)) -> Array a -> m b
536 Int -> (a -> (a, b)) -> Array a -> m b
537modifyIndexUnsafe i f (Array{..}) = liftIO $ do
537modifyIndexUnsafe i f (Array{..}) = liftIO $ do
538 let index = INDEX_OF(arrStart,i,a)
538 let index = INDEX_OF(arrStart,i,a)
@@ -545,7 +545,7 @@ modifyIndexUnsafe i f (Array{..}) = liftIO $ do
545-- | Modify a given index of an array using a modifier function.
545-- | Modify a given index of an array using a modifier function.
546--
546--
547-- /Pre-release/
547-- /Pre-release/
548−modifyIndex :: forall m a b. (MonadIO m, Storable a) =>
548+modifyIndex :: forall m a b. (MonadIO m, Unboxed a) =>
549 Int -> (a -> (a, b)) -> Array a -> m b
549 Int -> (a -> (a, b)) -> Array a -> m b
550modifyIndex i f Array{..} = do
550modifyIndex i f Array{..} = do
551 let index = INDEX_OF(arrStart,i,a)
551 let index = INDEX_OF(arrStart,i,a)
@@ -562,7 +562,7 @@ modifyIndex i f Array{..} = do
562--
562--
563-- /Pre-release/
563-- /Pre-release/
564{-# INLINE modifyIndices #-}
564{-# INLINE modifyIndices #-}
565−modifyIndices :: forall m a . (MonadIO m, Storable a)
565+modifyIndices :: forall m a . (MonadIO m, Unboxed a)
566 => (Int -> a -> a) -> Array a -> Fold m Int ()
566 => (Int -> a -> a) -> Array a -> Fold m Int ()
567modifyIndices f arr = FL.foldlM' step initial
567modifyIndices f arr = FL.foldlM' step initial
568
568
@@ -577,7 +577,7 @@ modifyIndices f arr = FL.foldlM' step initial
577-- | Modify each element of an array using the supplied modifier function.
577-- | Modify each element of an array using the supplied modifier function.
578--
578--
579-- /Pre-release/
579-- /Pre-release/
580−modify :: forall m a. (MonadIO m, Storable a)
580+modify :: forall m a. (MonadIO m, Unboxed a)
581 => (a -> a) -> Array a -> m ()
581 => (a -> a) -> Array a -> m ()
582modify f Array{..} = liftIO $
582modify f Array{..} = liftIO $
583 go arrStart
583 go arrStart
@@ -591,7 +591,7 @@ modify f Array{..} = liftIO $
591 go (INDEX_NEXT(i,a))
591 go (INDEX_NEXT(i,a))
592
592
593{-# INLINE swapArrayByteIndices #-}
593{-# INLINE swapArrayByteIndices #-}
594−swapArrayByteIndices :: Storable a => ArrayContents a -> Int -> Int -> IO ()
594+swapArrayByteIndices :: Unboxed a => ArrayContents a -> Int -> Int -> IO ()
595swapArrayByteIndices arrContents i1 i2 = do
595swapArrayByteIndices arrContents i1 i2 = do
596 r1 <- peekWith arrContents i1
596 r1 <- peekWith arrContents i1
597 r2 <- peekWith arrContents i2
597 r2 <- peekWith arrContents i2
@@ -604,7 +604,7 @@ swapArrayByteIndices arrContents i1 i2 = do
604--
604--
605-- /Pre-release/
605-- /Pre-release/
606{-# INLINE unsafeSwapIndices #-}
606{-# INLINE unsafeSwapIndices #-}
607−unsafeSwapIndices :: forall m a. (MonadIO m, Storable a)
607+unsafeSwapIndices :: forall m a. (MonadIO m, Unboxed a)
608 => Int -> Int -> Array a -> m ()
608 => Int -> Int -> Array a -> m ()
609unsafeSwapIndices i1 i2 Array{..} = liftIO $ do
609unsafeSwapIndices i1 i2 Array{..} = liftIO $ do
610 let t1 = INDEX_OF(arrStart,i1,a)
610 let t1 = INDEX_OF(arrStart,i1,a)
@@ -614,7 +614,7 @@ unsafeSwapIndices i1 i2 Array{..} = liftIO $ do
614-- | Swap the elements at two indices.
614-- | Swap the elements at two indices.
615--
615--
616-- /Pre-release/
616-- /Pre-release/
617−swapIndices :: forall m a. (MonadIO m, Storable a)
617+swapIndices :: forall m a. (MonadIO m, Unboxed a)
618 => Int -> Int -> Array a -> m ()
618 => Int -> Int -> Array a -> m ()
619swapIndices i1 i2 Array{..} = liftIO $ do
619swapIndices i1 i2 Array{..} = liftIO $ do
620 let t1 = INDEX_OF(arrStart,i1,a)
620 let t1 = INDEX_OF(arrStart,i1,a)
@@ -685,15 +685,15 @@ roundUpToPower2 n =
685-- case it returns one element's size.
685-- case it returns one element's size.
686--
686--
687{-# INLINE allocBytesToBytes #-}
687{-# INLINE allocBytesToBytes #-}
688−allocBytesToBytes :: forall a. Storable a => a -> Int -> Int
688+allocBytesToBytes :: forall a. Unboxed a => a -> Int -> Int
689allocBytesToBytes _ n = max (arrayPayloadSize n) (SIZE_OF(a))
689allocBytesToBytes _ n = max (arrayPayloadSize n) (SIZE_OF(a))
690
690
691−-- | Given a 'Storable' type (unused first arg) and real allocation size
691+-- | Given an 'Unboxed' type (unused first arg) and real allocation size
692-- (including overhead), return how many elements of that type will completely
692-- (including overhead), return how many elements of that type will completely
693-- fit in it, returns at least 1.
693-- fit in it, returns at least 1.
694--
694--
695{-# INLINE allocBytesToElemCount #-}
695{-# INLINE allocBytesToElemCount #-}
696−allocBytesToElemCount :: Storable a => a -> Int -> Int
696+allocBytesToElemCount :: Unboxed a => a -> Int -> Int
697allocBytesToElemCount x bytes =
697allocBytesToElemCount x bytes =
698 let n = bytesToElemCount x (allocBytesToBytes x bytes)
698 let n = bytesToElemCount x (allocBytesToBytes x bytes)
699 in assert (n >= 1) n
699 in assert (n >= 1) n
@@ -715,8 +715,8 @@ roundDownTo elemSize size = size - (size `mod` elemSize)
715-- XXX See if resizing can be implemented by reading the old array as a stream
715-- XXX See if resizing can be implemented by reading the old array as a stream
716-- and then using writeN to the new array.
716-- and then using writeN to the new array.
717--
717--
718−-- NOTE: we are passing elemSize explicitly to avoid a Storable constraint.
718+-- NOTE: we are passing elemSize explicitly to avoid an Unboxed constraint.
719−-- Since this is not inlined Storable consrraint leads to dictionary passing
719+-- Since this is not inlined Unboxed consrraint leads to dictionary passing
720-- which complicates some inspection tests.
720-- which complicates some inspection tests.
721--
721--
722{-# NOINLINE reallocAligned #-}
722{-# NOINLINE reallocAligned #-}
@@ -758,14 +758,14 @@ reallocAligned elemSize alignSize newCapacityInBytes Array{..} = do
758-- 'largeObjectThreshold' then it is rounded up to the block size (4K).
758-- 'largeObjectThreshold' then it is rounded up to the block size (4K).
759--
759--
760{-# INLINABLE realloc #-}
760{-# INLINABLE realloc #-}
761−realloc :: forall m a. (MonadIO m, Storable a) => Int -> Array a -> m (Array a)
761+realloc :: forall m a. (MonadIO m, Unboxed a) => Int -> Array a -> m (Array a)
762realloc bytes arr =
762realloc bytes arr =
763 liftIO $ reallocAligned (SIZE_OF(a)) (alignment (undefined :: a)) bytes arr
763 liftIO $ reallocAligned (SIZE_OF(a)) (alignment (undefined :: a)) bytes arr
764
764
765-- | @reallocWith label capSizer minIncrBytes array@. The label is used
765-- | @reallocWith label capSizer minIncrBytes array@. The label is used
766-- in error messages and the capSizer is used to determine the capacity of the
766-- in error messages and the capSizer is used to determine the capacity of the
767-- new array in bytes given the current byte length of the array.
767-- new array in bytes given the current byte length of the array.
768−reallocWith :: forall m a. (MonadIO m , Storable a) =>
768+reallocWith :: forall m a. (MonadIO m , Unboxed a) =>
769 String
769 String
770 -> (Int -> Int)
770 -> (Int -> Int)
771 -> Int
771 -> Int
@@ -799,7 +799,7 @@ reallocWith label capSizer minIncrBytes arr = do
799--
799--
800-- /Pre-release/
800-- /Pre-release/
801{-# INLINE resize #-}
801{-# INLINE resize #-}
802−resize :: forall m a. (MonadIO m, Storable a) =>
802+resize :: forall m a. (MonadIO m, Unboxed a) =>
803 Int -> Array a -> m (Array a)
803 Int -> Array a -> m (Array a)
804resize nElems arr@Array{..} = do
804resize nElems arr@Array{..} = do
805 let req = SIZE_OF(a) * nElems
805 let req = SIZE_OF(a) * nElems
@@ -813,7 +813,7 @@ resize nElems arr@Array{..} = do
813--
813--
814-- /Pre-release/
814-- /Pre-release/
815{-# INLINE resizeExp #-}
815{-# INLINE resizeExp #-}
816−resizeExp :: forall m a. (MonadIO m, Storable a) =>
816+resizeExp :: forall m a. (MonadIO m, Unboxed a) =>
817 Int -> Array a -> m (Array a)
817 Int -> Array a -> m (Array a)
818resizeExp nElems arr@Array{..} = do
818resizeExp nElems arr@Array{..} = do
819 let req = roundUpLargeArray (SIZE_OF(a) * nElems)
819 let req = roundUpLargeArray (SIZE_OF(a) * nElems)
@@ -835,7 +835,7 @@ resizeExp nElems arr@Array{..} = do
835--
835--
836-- /Pre-release/
836-- /Pre-release/
837{-# INLINE rightSize #-}
837{-# INLINE rightSize #-}
838−rightSize :: forall m a. (MonadIO m, Storable a) => Array a -> m (Array a)
838+rightSize :: forall m a. (MonadIO m, Unboxed a) => Array a -> m (Array a)
839rightSize arr@Array{..} = do
839rightSize arr@Array{..} = do
840 assert (aEnd <= aBound) (return ())
840 assert (aEnd <= aBound) (return ())
841 let start = arrStart
841 let start = arrStart
@@ -867,7 +867,7 @@ rightSize arr@Array{..} = do
867--
867--
868-- /Internal/
868-- /Internal/
869{-# INLINE snocNewEnd #-}
869{-# INLINE snocNewEnd #-}
870−snocNewEnd :: (MonadIO m, Storable a) => Int -> Array a -> a -> m (Array a)
870+snocNewEnd :: (MonadIO m, Unboxed a) => Int -> Array a -> a -> m (Array a)
871snocNewEnd newEnd arr@Array{..} x = liftIO $ do
871snocNewEnd newEnd arr@Array{..} x = liftIO $ do
872 assert (newEnd <= aBound) (return ())
872 assert (newEnd <= aBound) (return ())
873 pokeWith arrContents aEnd x
873 pokeWith arrContents aEnd x
@@ -879,7 +879,7 @@ snocNewEnd newEnd arr@Array{..} x = liftIO $ do
879--
879--
880-- /Internal/
880-- /Internal/
881{-# INLINE snocUnsafe #-}
881{-# INLINE snocUnsafe #-}
882−snocUnsafe :: forall m a. (MonadIO m, Storable a) =>
882+snocUnsafe :: forall m a. (MonadIO m, Unboxed a) =>
883 Array a -> a -> m (Array a)
883 Array a -> a -> m (Array a)
884snocUnsafe arr@Array{..} = snocNewEnd (INDEX_NEXT(aEnd,a)) arr
884snocUnsafe arr@Array{..} = snocNewEnd (INDEX_NEXT(aEnd,a)) arr
885
885
@@ -888,7 +888,7 @@ snocUnsafe arr@Array{..} = snocNewEnd (INDEX_NEXT(aEnd,a)) arr
888--
888--
889-- /Internal/
889-- /Internal/
890{-# INLINE snocMay #-}
890{-# INLINE snocMay #-}
891−snocMay :: forall m a. (MonadIO m, Storable a) =>
891+snocMay :: forall m a. (MonadIO m, Unboxed a) =>
892 Array a -> a -> m (Maybe (Array a))
892 Array a -> a -> m (Maybe (Array a))
893snocMay arr@Array{..} x = liftIO $ do
893snocMay arr@Array{..} x = liftIO $ do
894 let newEnd = INDEX_NEXT(aEnd,a)
894 let newEnd = INDEX_NEXT(aEnd,a)
@@ -898,7 +898,7 @@ snocMay arr@Array{..} x = liftIO $ do
898
898
899-- NOINLINE to move it out of the way and not pollute the instruction cache.
899-- NOINLINE to move it out of the way and not pollute the instruction cache.
900{-# NOINLINE snocWithRealloc #-}
900{-# NOINLINE snocWithRealloc #-}
901−snocWithRealloc :: forall m a. (MonadIO m, Storable a) =>
901+snocWithRealloc :: forall m a. (MonadIO m, Unboxed a) =>
902 (Int -> Int)
902 (Int -> Int)
903 -> Array a
903 -> Array a
904 -> a
904 -> a
@@ -921,7 +921,7 @@ snocWithRealloc sizer arr x = do
921--
921--
922-- /Pre-release/
922-- /Pre-release/
923{-# INLINE snocWith #-}
923{-# INLINE snocWith #-}
924−snocWith :: forall m a. (MonadIO m, Storable a) =>
924+snocWith :: forall m a. (MonadIO m, Unboxed a) =>
925 (Int -> Int)
925 (Int -> Int)
926 -> Array a
926 -> Array a
927 -> a
927 -> a
@@ -943,7 +943,7 @@ snocWith allocSize arr x = liftIO $ do
943--
943--
944-- /Pre-release/
944-- /Pre-release/
945{-# INLINE snocLinear #-}
945{-# INLINE snocLinear #-}
946−snocLinear :: forall m a. (MonadIO m, Storable a) => Array a -> a -> m (Array a)
946+snocLinear :: forall m a. (MonadIO m, Unboxed a) => Array a -> a -> m (Array a)
947snocLinear = snocWith (+ allocBytesToBytes (undefined :: a) arrayChunkBytes)
947snocLinear = snocWith (+ allocBytesToBytes (undefined :: a) arrayChunkBytes)
948
948
949-- | The array is mutated to append an additional element to it. If there is no
949-- | The array is mutated to append an additional element to it. If there is no
@@ -961,7 +961,7 @@ snocLinear = snocWith (+ allocBytesToBytes (undefined :: a) arrayChunkBytes)
961--
961--
962-- /Pre-release/
962-- /Pre-release/
963{-# INLINE snoc #-}
963{-# INLINE snoc #-}
964−snoc :: forall m a. (MonadIO m, Storable a) => Array a -> a -> m (Array a)
964+snoc :: forall m a. (MonadIO m, Unboxed a) => Array a -> a -> m (Array a)
965snoc = snocWith f
965snoc = snocWith f
966
966
967 where
967 where
@@ -981,7 +981,7 @@ snoc = snocWith f
981--
981--
982-- Unsafe because it does not check the bounds of the array.
982-- Unsafe because it does not check the bounds of the array.
983{-# INLINE_NORMAL getIndexUnsafe #-}
983{-# INLINE_NORMAL getIndexUnsafe #-}
984−getIndexUnsafe :: forall m a. (MonadIO m, Storable a) => Int -> Array a -> m a
984+getIndexUnsafe :: forall m a. (MonadIO m, Unboxed a) => Int -> Array a -> m a
985getIndexUnsafe i (Array {..}) = do
985getIndexUnsafe i (Array {..}) = do
986 let index = INDEX_OF(arrStart,i,a)
986 let index = INDEX_OF(arrStart,i,a)
987 assert (i >= 0 && INDEX_VALID(index,aEnd,a)) (return ())
987 assert (i >= 0 && INDEX_VALID(index,aEnd,a)) (return ())
@@ -990,7 +990,7 @@ getIndexUnsafe i (Array {..}) = do
990-- | /O(1)/ Lookup the element at the given index. Index starts from 0.
990-- | /O(1)/ Lookup the element at the given index. Index starts from 0.
991--
991--
992{-# INLINE getIndex #-}
992{-# INLINE getIndex #-}
993−getIndex :: forall m a. (MonadIO m, Storable a) => Int -> Array a -> m a
993+getIndex :: forall m a. (MonadIO m, Unboxed a) => Int -> Array a -> m a
994getIndex i Array{..} = do
994getIndex i Array{..} = do
995 let index = INDEX_OF(arrStart,i,a)
995 let index = INDEX_OF(arrStart,i,a)
996 if i >= 0 && INDEX_VALID(index,aEnd,a)
996 if i >= 0 && INDEX_VALID(index,aEnd,a)
@@ -1003,7 +1003,7 @@ getIndex i Array{..} = do
1003-- Slightly faster than computing the forward index and using getIndex.
1003-- Slightly faster than computing the forward index and using getIndex.
1004--
1004--
1005{-# INLINE getIndexRev #-}
1005{-# INLINE getIndexRev #-}
1006−getIndexRev :: forall m a. (MonadIO m, Storable a) => Int -> Array a -> m a
1006+getIndexRev :: forall m a. (MonadIO m, Unboxed a) => Int -> Array a -> m a
1007getIndexRev i Array{..} = do
1007getIndexRev i Array{..} = do
1008 let index = RINDEX_OF(aEnd,i,a)
1008 let index = RINDEX_OF(aEnd,i,a)
1009 if i >= 0 && index >= arrStart
1009 if i >= 0 && index >= arrStart
@@ -1019,7 +1019,7 @@ data GetIndicesState contents start end st =
1019--
1019--
1020-- /Pre-release/
1020-- /Pre-release/
1021{-# INLINE getIndicesD #-}
1021{-# INLINE getIndicesD #-}
1022−getIndicesD :: (Monad m, Storable a) =>
1022+getIndicesD :: (Monad m, Unboxed a) =>
1023 (forall b. IO b -> m b) -> D.Stream m Int -> Unfold m (Array a) a
1023 (forall b. IO b -> m b) -> D.Stream m Int -> Unfold m (Array a) a
1024getIndicesD liftio (D.Stream stepi sti) = Unfold step inject
1024getIndicesD liftio (D.Stream stepi sti) = Unfold step inject
1025
1025
@@ -1039,7 +1039,7 @@ getIndicesD liftio (D.Stream stepi sti) = Unfold step inject
1039 D.Stop -> return D.Stop
1039 D.Stop -> return D.Stop
1040
1040
1041{-# INLINE getIndices #-}
1041{-# INLINE getIndices #-}
1042−getIndices :: (MonadIO m, Storable a) => Stream m Int -> Unfold m (Array a) a
1042+getIndices :: (MonadIO m, Unboxed a) => Stream m Int -> Unfold m (Array a) a
1043getIndices = getIndicesD liftIO . Stream.toStreamD
1043getIndices = getIndicesD liftIO . Stream.toStreamD
1044
1044
1045-------------------------------------------------------------------------------
1045-------------------------------------------------------------------------------
@@ -1056,7 +1056,7 @@ getIndices = getIndicesD liftIO . Stream.toStreamD
1056--
1056--
1057-- /Pre-release/
1057-- /Pre-release/
1058{-# INLINE getSliceUnsafe #-}
1058{-# INLINE getSliceUnsafe #-}
1059−getSliceUnsafe :: forall a. Storable a
1059+getSliceUnsafe :: forall a. Unboxed a
1060 => Int -- ^ from index
1060 => Int -- ^ from index
1061 -> Int -- ^ length of the slice
1061 -> Int -- ^ length of the slice
1062 -> Array a
1062 -> Array a
@@ -1075,7 +1075,7 @@ getSliceUnsafe index len (Array contents start e _) =
1075--
1075--
1076-- /Pre-release/
1076-- /Pre-release/
1077{-# INLINE getSlice #-}
1077{-# INLINE getSlice #-}
1078−getSlice :: forall a. Storable a =>
1078+getSlice :: forall a. Unboxed a =>
1079 Int -- ^ from index
1079 Int -- ^ from index
1080 -> Int -- ^ length of the slice
1080 -> Int -- ^ length of the slice
1081 -> Array a
1081 -> Array a
@@ -1104,7 +1104,7 @@ getSlice index len (Array contents start e _) =
1104--
1104--
1105-- /Pre-release/
1105-- /Pre-release/
1106{-# INLINE reverse #-}
1106{-# INLINE reverse #-}
1107−reverse :: forall m a. (MonadIO m, Storable a) => Array a -> m ()
1107+reverse :: forall m a. (MonadIO m, Unboxed a) => Array a -> m ()
1108reverse Array{..} = liftIO $ do
1108reverse Array{..} = liftIO $ do
1109 let l = arrStart
1109 let l = arrStart
1110 h = INDEX_PREV(aEnd,a)
1110 h = INDEX_PREV(aEnd,a)
@@ -1131,7 +1131,7 @@ permute = undefined
1131--
1131--
1132-- /Pre-release/
1132-- /Pre-release/
1133{-# INLINE partitionBy #-}
1133{-# INLINE partitionBy #-}
1134−partitionBy :: forall m a. (MonadIO m, Storable a)
1134+partitionBy :: forall m a. (MonadIO m, Unboxed a)
1135 => (a -> Bool) -> Array a -> m (Array a, Array a)
1135 => (a -> Bool) -> Array a -> m (Array a, Array a)
1136partitionBy f arr@Array{..} = liftIO $ do
1136partitionBy f arr@Array{..} = liftIO $ do
1137 if arrStart >= aEnd
1137 if arrStart >= aEnd
@@ -1255,7 +1255,7 @@ byteLength Array{..} =
1255--
1255--
1256-- @since 0.7.0
1256-- @since 0.7.0
1257{-# INLINE length #-}
1257{-# INLINE length #-}
1258−length :: forall a. Storable a => Array a -> Int
1258+length :: forall a. Unboxed a => Array a -> Int
1259length arr =
1259length arr =
1260 let elemSize = SIZE_OF(a)
1260 let elemSize = SIZE_OF(a)
1261 blen = byteLength arr
1261 blen = byteLength arr
@@ -1299,7 +1299,7 @@ data GroupState s contents start end bound
1299--
1299--
1300-- /Pre-release/
1300-- /Pre-release/
1301{-# INLINE_NORMAL arraysOf #-}
1301{-# INLINE_NORMAL arraysOf #-}
1302−arraysOf :: forall m a. (MonadIO m, Storable a)
1302+arraysOf :: forall m a. (MonadIO m, Unboxed a)
1303 => Int -> D.Stream m a -> D.Stream m (Array a)
1303 => Int -> D.Stream m a -> D.Stream m (Array a)
1304-- XXX the idiomatic implementation leads to large regression in the D.reverse'
1304-- XXX the idiomatic implementation leads to large regression in the D.reverse'
1305-- benchmark. It seems it has difficulty producing optimized code when
1305-- benchmark. It seems it has difficulty producing optimized code when
@@ -1346,7 +1346,7 @@ arraysOf n (D.Stream step state) =
1346-- XXX buffer to a list instead?
1346-- XXX buffer to a list instead?
1347-- | Buffer the stream into arrays in memory.
1347-- | Buffer the stream into arrays in memory.
1348{-# INLINE arrayStreamKFromStreamD #-}
1348{-# INLINE arrayStreamKFromStreamD #-}
1349−arrayStreamKFromStreamD :: forall m a. (MonadIO m, Storable a) =>
1349+arrayStreamKFromStreamD :: forall m a. (MonadIO m, Unboxed a) =>
1350 D.Stream m a -> m (K.Stream m (Array a))
1350 D.Stream m a -> m (K.Stream m (Array a))
1351arrayStreamKFromStreamD =
1351arrayStreamKFromStreamD =
1352 let n = allocBytesToElemCount (undefined :: a) defaultChunkSize
1352 let n = allocBytesToElemCount (undefined :: a) defaultChunkSize
@@ -1367,7 +1367,7 @@ data FlattenState s contents a =
1367-- We can try this if there are any fusion issues in the unfold.
1367-- We can try this if there are any fusion issues in the unfold.
1368--
1368--
1369{-# INLINE_NORMAL flattenArrays #-}
1369{-# INLINE_NORMAL flattenArrays #-}
1370−flattenArrays :: forall m a. (MonadIO m, Storable a)
1370+flattenArrays :: forall m a. (MonadIO m, Unboxed a)
1371 => D.Stream m (Array a) -> D.Stream m a
1371 => D.Stream m (Array a) -> D.Stream m a
1372flattenArrays (D.Stream step state) = D.Stream step' (OuterLoop state)
1372flattenArrays (D.Stream step state) = D.Stream step' (OuterLoop state)
1373
1373
@@ -1396,7 +1396,7 @@ flattenArrays (D.Stream step state) = D.Stream step' (OuterLoop state)
1396-- We can try this if there are any fusion issues in the unfold.
1396-- We can try this if there are any fusion issues in the unfold.
1397--
1397--
1398{-# INLINE_NORMAL flattenArraysRev #-}
1398{-# INLINE_NORMAL flattenArraysRev #-}
1399−flattenArraysRev :: forall m a. (MonadIO m, Storable a)
1399+flattenArraysRev :: forall m a. (MonadIO m, Unboxed a)
1400 => D.Stream m (Array a) -> D.Stream m a
1400 => D.Stream m (Array a) -> D.Stream m a
1401flattenArraysRev (D.Stream step state) = D.Stream step' (OuterLoop state)
1401flattenArraysRev (D.Stream step state) = D.Stream step' (OuterLoop state)
1402
1402
@@ -1436,7 +1436,7 @@ toArrayUnsafe (Array contents start end _) = ArrayUnsafe contents start end
1436
1436
1437fromArrayUnsafe ::
1437fromArrayUnsafe ::
1438#ifdef DEVBUILD
1438#ifdef DEVBUILD
1439− Storable a =>
1439+ Unboxed a =>
1440#endif
1440#endif
1441 ArrayUnsafe a -> Array a
1441 ArrayUnsafe a -> Array a
1442fromArrayUnsafe (ArrayUnsafe contents start end) =
1442fromArrayUnsafe (ArrayUnsafe contents start end) =
@@ -1444,7 +1444,7 @@ fromArrayUnsafe (ArrayUnsafe contents start end) =
1444
1444
1445{-# INLINE_NORMAL producerWith #-}
1445{-# INLINE_NORMAL producerWith #-}
1446producerWith ::
1446producerWith ::
1447− forall m a. (Monad m, Storable a)
1447+ forall m a. (Monad m, Unboxed a)
1448 => (forall b. IO b -> m b) -> Producer m (Array a) a
1448 => (forall b. IO b -> m b) -> Producer m (Array a) a
1449producerWith liftio = Producer step (return . toArrayUnsafe) extract
1449producerWith liftio = Producer step (return . toArrayUnsafe) extract
1450 where
1450 where
@@ -1465,19 +1465,19 @@ producerWith liftio = Producer step (return . toArrayUnsafe) extract
1465-- | Resumable unfold of an array.
1465-- | Resumable unfold of an array.
1466--
1466--
1467{-# INLINE_NORMAL producer #-}
1467{-# INLINE_NORMAL producer #-}
1468−producer :: forall m a. (MonadIO m, Storable a) => Producer m (Array a) a
1468+producer :: forall m a. (MonadIO m, Unboxed a) => Producer m (Array a) a
1469producer = producerWith liftIO
1469producer = producerWith liftIO
1470
1470
1471-- | Unfold an array into a stream.
1471-- | Unfold an array into a stream.
1472--
1472--
1473-- @since 0.7.0
1473-- @since 0.7.0
1474{-# INLINE_NORMAL read #-}
1474{-# INLINE_NORMAL read #-}
1475−read :: forall m a. (MonadIO m, Storable a) => Unfold m (Array a) a
1475+read :: forall m a. (MonadIO m, Unboxed a) => Unfold m (Array a) a
1476read = Producer.simplify producer
1476read = Producer.simplify producer
1477
1477
1478{-# INLINE_NORMAL readRevWith #-}
1478{-# INLINE_NORMAL readRevWith #-}
1479readRevWith ::
1479readRevWith ::
1480− forall m a. (Monad m, Storable a)
1480+ forall m a. (Monad m, Unboxed a)
1481 => (forall b. IO b -> m b) -> Unfold m (Array a) a
1481 => (forall b. IO b -> m b) -> Unfold m (Array a) a
1482readRevWith liftio = Unfold step inject
1482readRevWith liftio = Unfold step inject
1483 where
1483 where
@@ -1496,7 +1496,7 @@ readRevWith liftio = Unfold step inject
1496--
1496--
1497-- /Pre-release/
1497-- /Pre-release/
1498{-# INLINE_NORMAL readRev #-}
1498{-# INLINE_NORMAL readRev #-}
1499−readRev :: forall m a. (MonadIO m, Storable a) => Unfold m (Array a) a
1499+readRev :: forall m a. (MonadIO m, Unboxed a) => Unfold m (Array a) a
1500readRev = readRevWith liftIO
1500readRev = readRevWith liftIO
1501
1501
1502-------------------------------------------------------------------------------
1502-------------------------------------------------------------------------------
@@ -1507,7 +1507,7 @@ readRev = readRevWith liftIO
1507-- Use foldr/build fusion to fuse with list consumers
1507-- Use foldr/build fusion to fuse with list consumers
1508-- This can be useful when using the IsList instance
1508-- This can be useful when using the IsList instance
1509{-# INLINE_LATE toListFB #-}
1509{-# INLINE_LATE toListFB #-}
1510−toListFB :: forall a b. Storable a => (a -> b -> b) -> b -> Array a -> b
1510+toListFB :: forall a b. Unboxed a => (a -> b -> b) -> b -> Array a -> b
1511toListFB c n Array{..} = go arrStart
1511toListFB c n Array{..} = go arrStart
1512 where
1512 where
1513
1513
@@ -1532,7 +1532,7 @@ toListFB c n Array{..} = go arrStart
1532--
1532--
1533-- @since 0.7.0
1533-- @since 0.7.0
1534{-# INLINE toList #-}
1534{-# INLINE toList #-}
1535−toList :: forall m a. (MonadIO m, Storable a) => Array a -> m [a]
1535+toList :: forall m a. (MonadIO m, Unboxed a) => Array a -> m [a]
1536toList Array{..} = liftIO $ go arrStart
1536toList Array{..} = liftIO $ go arrStart
1537 where
1537 where
1538
1538
@@ -1543,7 +1543,7 @@ toList Array{..} = liftIO $ go arrStart
1543
1543
1544{-# INLINE_NORMAL toStreamDWith #-}
1544{-# INLINE_NORMAL toStreamDWith #-}
1545toStreamDWith ::
1545toStreamDWith ::
1546− forall m a. (Monad m, Storable a)
1546+ forall m a. (Monad m, Unboxed a)
1547 => (forall b. IO b -> m b) -> Array a -> D.Stream m a
1547 => (forall b. IO b -> m b) -> Array a -> D.Stream m a
1548toStreamDWith liftio Array{..} = D.Stream step arrStart
1548toStreamDWith liftio Array{..} = D.Stream step arrStart
1549
1549
@@ -1561,12 +1561,12 @@ toStreamDWith liftio Array{..} = D.Stream step arrStart
1561--
1561--
1562-- We can try this if the unfold has any performance issues.
1562-- We can try this if the unfold has any performance issues.
1563{-# INLINE_NORMAL toStreamD #-}
1563{-# INLINE_NORMAL toStreamD #-}
1564−toStreamD :: forall m a. (MonadIO m, Storable a) => Array a -> D.Stream m a
1564+toStreamD :: forall m a. (MonadIO m, Unboxed a) => Array a -> D.Stream m a
1565toStreamD = toStreamDWith liftIO
1565toStreamD = toStreamDWith liftIO
1566
1566
1567{-# INLINE toStreamKWith #-}
1567{-# INLINE toStreamKWith #-}
1568toStreamKWith ::
1568toStreamKWith ::
1569− forall m a. (Monad m, Storable a)
1569+ forall m a. (Monad m, Unboxed a)
1570 => (forall b. IO b -> m b) -> Array a -> K.Stream m a
1570 => (forall b. IO b -> m b) -> Array a -> K.Stream m a
1571toStreamKWith liftio Array{..} = go arrStart
1571toStreamKWith liftio Array{..} = go arrStart
1572
1572
@@ -1580,12 +1580,12 @@ toStreamKWith liftio Array{..} = go arrStart
1580 in liftio elemM `K.consM` go (INDEX_NEXT(p,a))
1580 in liftio elemM `K.consM` go (INDEX_NEXT(p,a))
1581
1581
1582{-# INLINE toStreamK #-}
1582{-# INLINE toStreamK #-}
1583−toStreamK :: forall m a. (MonadIO m, Storable a) => Array a -> K.Stream m a
1583+toStreamK :: forall m a. (MonadIO m, Unboxed a) => Array a -> K.Stream m a
1584toStreamK = toStreamKWith liftIO
1584toStreamK = toStreamKWith liftIO
1585
1585
1586{-# INLINE_NORMAL toStreamDRevWith #-}
1586{-# INLINE_NORMAL toStreamDRevWith #-}
1587toStreamDRevWith ::
1587toStreamDRevWith ::
1588− forall m a. (Monad m, Storable a)
1588+ forall m a. (Monad m, Unboxed a)
1589 => (forall b. IO b -> m b) -> Array a -> D.Stream m a
1589 => (forall b. IO b -> m b) -> Array a -> D.Stream m a
1590toStreamDRevWith liftio Array{..} =
1590toStreamDRevWith liftio Array{..} =
1591 let p = INDEX_PREV(aEnd,a)
1591 let p = INDEX_PREV(aEnd,a)
@@ -1605,12 +1605,12 @@ toStreamDRevWith liftio Array{..} =
1605--
1605--
1606-- We can try this if the unfold has any perf issues.
1606-- We can try this if the unfold has any perf issues.
1607{-# INLINE_NORMAL toStreamDRev #-}
1607{-# INLINE_NORMAL toStreamDRev #-}
1608−toStreamDRev :: forall m a. (MonadIO m, Storable a) => Array a -> D.Stream m a
1608+toStreamDRev :: forall m a. (MonadIO m, Unboxed a) => Array a -> D.Stream m a
1609toStreamDRev = toStreamDRevWith liftIO
1609toStreamDRev = toStreamDRevWith liftIO
1610
1610
1611{-# INLINE toStreamKRevWith #-}
1611{-# INLINE toStreamKRevWith #-}
1612toStreamKRevWith ::
1612toStreamKRevWith ::
1613− forall m a. (Monad m, Storable a)
1613+ forall m a. (Monad m, Unboxed a)
1614 => (forall b. IO b -> m b) -> Array a -> K.Stream m a
1614 => (forall b. IO b -> m b) -> Array a -> K.Stream m a
1615toStreamKRevWith liftio Array {..} =
1615toStreamKRevWith liftio Array {..} =
1616 let p = INDEX_PREV(aEnd,a)
1616 let p = INDEX_PREV(aEnd,a)
@@ -1626,7 +1626,7 @@ toStreamKRevWith liftio Array {..} =
1626 in liftio elemM `K.consM` go (INDEX_PREV(p,a))
1626 in liftio elemM `K.consM` go (INDEX_PREV(p,a))
1627
1627
1628{-# INLINE toStreamKRev #-}
1628{-# INLINE toStreamKRev #-}
1629−toStreamKRev :: forall m a. (MonadIO m, Storable a) => Array a -> K.Stream m a
1629+toStreamKRev :: forall m a. (MonadIO m, Unboxed a) => Array a -> K.Stream m a
1630toStreamKRev = toStreamKRevWith liftIO
1630toStreamKRev = toStreamKRevWith liftIO
1631
1631
1632-------------------------------------------------------------------------------
1632-------------------------------------------------------------------------------
@@ -1638,12 +1638,12 @@ toStreamKRev = toStreamKRevWith liftIO
1638--
1638--
1639-- | Strict left fold of an array.
1639-- | Strict left fold of an array.
1640{-# INLINE_NORMAL foldl' #-}
1640{-# INLINE_NORMAL foldl' #-}
1641−foldl' :: (MonadIO m, Storable a) => (b -> a -> b) -> b -> Array a -> m b
1641+foldl' :: (MonadIO m, Unboxed a) => (b -> a -> b) -> b -> Array a -> m b
1642foldl' f z arr = D.foldl' f z $ toStreamD arr
1642foldl' f z arr = D.foldl' f z $ toStreamD arr
1643
1643
1644-- | Right fold of an array.
1644-- | Right fold of an array.
1645{-# INLINE_NORMAL foldr #-}
1645{-# INLINE_NORMAL foldr #-}
1646−foldr :: (MonadIO m, Storable a) => (a -> b -> b) -> b -> Array a -> m b
1646+foldr :: (MonadIO m, Unboxed a) => (a -> b -> b) -> b -> Array a -> m b
1647foldr f z arr = D.foldr f z $ toStreamD arr
1647foldr f z arr = D.foldr f z $ toStreamD arr
1648
1648
1649-------------------------------------------------------------------------------
1649-------------------------------------------------------------------------------
@@ -1667,7 +1667,7 @@ foldr f z arr = D.foldr f z $ toStreamD arr
1667--
1667--
1668-- /Internal/
1668-- /Internal/
1669{-# INLINE_NORMAL appendNUnsafe #-}
1669{-# INLINE_NORMAL appendNUnsafe #-}
1670−appendNUnsafe :: forall m a. (MonadIO m, Storable a) =>
1670+appendNUnsafe :: forall m a. (MonadIO m, Unboxed a) =>
1671 m (Array a)
1671 m (Array a)
1672 -> Int
1672 -> Int
1673 -> Fold m a (Array a)
1673 -> Fold m a (Array a)
@@ -1700,7 +1700,7 @@ appendNUnsafe action n =
1700--
1700--
1701-- /Pre-release/
1701-- /Pre-release/
1702{-# INLINE_NORMAL appendN #-}
1702{-# INLINE_NORMAL appendN #-}
1703−appendN :: forall m a. (MonadIO m, Storable a) =>
1703+appendN :: forall m a. (MonadIO m, Unboxed a) =>
1704 m (Array a) -> Int -> Fold m a (Array a)
1704 m (Array a) -> Int -> Fold m a (Array a)
1705appendN initial n = FL.take n (appendNUnsafe initial n)
1705appendN initial n = FL.take n (appendNUnsafe initial n)
1706
1706
@@ -1715,7 +1715,7 @@ appendN initial n = FL.take n (appendNUnsafe initial n)
1715--
1715--
1716-- /Pre-release/
1716-- /Pre-release/
1717{-# INLINE appendWith #-}
1717{-# INLINE appendWith #-}
1718−appendWith :: forall m a. (MonadIO m, Storable a) =>
1718+appendWith :: forall m a. (MonadIO m, Unboxed a) =>
1719 (Int -> Int) -> m (Array a) -> Fold m a (Array a)
1719 (Int -> Int) -> m (Array a) -> Fold m a (Array a)
1720appendWith sizer = FL.foldlM' (snocWith sizer)
1720appendWith sizer = FL.foldlM' (snocWith sizer)
1721
1721
@@ -1729,7 +1729,7 @@ appendWith sizer = FL.foldlM' (snocWith sizer)
1729--
1729--
1730-- /Pre-release/
1730-- /Pre-release/
1731{-# INLINE append #-}
1731{-# INLINE append #-}
1732−append :: forall m a. (MonadIO m, Storable a) =>
1732+append :: forall m a. (MonadIO m, Unboxed a) =>
1733 m (Array a) -> Fold m a (Array a)
1733 m (Array a) -> Fold m a (Array a)
1734append = appendWith (* 2)
1734append = appendWith (* 2)
1735
1735
@@ -1743,7 +1743,7 @@ append = appendWith (* 2)
1743--
1743--
1744-- /Pre-release/
1744-- /Pre-release/
1745{-# INLINE_NORMAL writeNWithUnsafe #-}
1745{-# INLINE_NORMAL writeNWithUnsafe #-}
1746−writeNWithUnsafe :: forall m a. (MonadIO m, Storable a)
1746+writeNWithUnsafe :: forall m a. (MonadIO m, Unboxed a)
1747 => (Int -> m (Array a)) -> Int -> Fold m a (Array a)
1747 => (Int -> m (Array a)) -> Int -> Fold m a (Array a)
1748writeNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
1748writeNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
1749
1749
@@ -1766,7 +1766,7 @@ writeNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
1766--
1766--
1767-- @since 0.7.0
1767-- @since 0.7.0
1768{-# INLINE_NORMAL writeNUnsafe #-}
1768{-# INLINE_NORMAL writeNUnsafe #-}
1769−writeNUnsafe :: forall m a. (MonadIO m, Storable a)
1769+writeNUnsafe :: forall m a. (MonadIO m, Unboxed a)
1770 => Int -> Fold m a (Array a)
1770 => Int -> Fold m a (Array a)
1771writeNUnsafe = writeNWithUnsafe newArray
1771writeNUnsafe = writeNWithUnsafe newArray
1772
1772
@@ -1777,7 +1777,7 @@ writeNUnsafe = writeNWithUnsafe newArray
1777-- >>> writeNWith alloc n = Array.appendN (alloc n) n
1777-- >>> writeNWith alloc n = Array.appendN (alloc n) n
1778--
1778--
1779{-# INLINE_NORMAL writeNWith #-}
1779{-# INLINE_NORMAL writeNWith #-}
1780−writeNWith :: forall m a. (MonadIO m, Storable a)
1780+writeNWith :: forall m a. (MonadIO m, Unboxed a)
1781 => (Int -> m (Array a)) -> Int -> Fold m a (Array a)
1781 => (Int -> m (Array a)) -> Int -> Fold m a (Array a)
1782writeNWith alloc n = FL.take n (writeNWithUnsafe alloc n)
1782writeNWith alloc n = FL.take n (writeNWithUnsafe alloc n)
1783
1783
@@ -1790,14 +1790,14 @@ writeNWith alloc n = FL.take n (writeNWithUnsafe alloc n)
1790--
1790--
1791-- @since 0.7.0
1791-- @since 0.7.0
1792{-# INLINE_NORMAL writeN #-}
1792{-# INLINE_NORMAL writeN #-}
1793−writeN :: forall m a. (MonadIO m, Storable a) => Int -> Fold m a (Array a)
1793+writeN :: forall m a. (MonadIO m, Unboxed a) => Int -> Fold m a (Array a)
1794writeN = writeNWith newArray
1794writeN = writeNWith newArray
1795
1795
1796-- | Like writeNWithUnsafe but writes the array in reverse order.
1796-- | Like writeNWithUnsafe but writes the array in reverse order.
1797--
1797--
1798-- /Internal/
1798-- /Internal/
1799{-# INLINE_NORMAL writeRevNWithUnsafe #-}
1799{-# INLINE_NORMAL writeRevNWithUnsafe #-}
1800−writeRevNWithUnsafe :: forall m a. (MonadIO m, Storable a)
1800+writeRevNWithUnsafe :: forall m a. (MonadIO m, Unboxed a)
1801 => (Int -> m (Array a)) -> Int -> Fold m a (Array a)
1801 => (Int -> m (Array a)) -> Int -> Fold m a (Array a)
1802writeRevNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
1802writeRevNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
1803
1803
@@ -1818,7 +1818,7 @@ writeRevNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
1818--
1818--
1819-- /Internal/
1819-- /Internal/
1820{-# INLINE_NORMAL writeRevNWith #-}
1820{-# INLINE_NORMAL writeRevNWith #-}
1821−writeRevNWith :: forall m a. (MonadIO m, Storable a)
1821+writeRevNWith :: forall m a. (MonadIO m, Unboxed a)
1822 => (Int -> m (Array a)) -> Int -> Fold m a (Array a)
1822 => (Int -> m (Array a)) -> Int -> Fold m a (Array a)
1823writeRevNWith alloc n = FL.take n (writeRevNWithUnsafe alloc n)
1823writeRevNWith alloc n = FL.take n (writeRevNWithUnsafe alloc n)
1824
1824
@@ -1826,7 +1826,7 @@ writeRevNWith alloc n = FL.take n (writeRevNWithUnsafe alloc n)
1826--
1826--
1827-- /Pre-release/
1827-- /Pre-release/
1828{-# INLINE_NORMAL writeRevN #-}
1828{-# INLINE_NORMAL writeRevN #-}
1829−writeRevN :: forall m a. (MonadIO m, Storable a) => Int -> Fold m a (Array a)
1829+writeRevN :: forall m a. (MonadIO m, Unboxed a) => Int -> Fold m a (Array a)
1830writeRevN = writeRevNWith newArray
1830writeRevN = writeRevNWith newArray
1831
1831
1832-- | @writeNAligned align n@ folds a maximum of @n@ elements from the input
1832-- | @writeNAligned align n@ folds a maximum of @n@ elements from the input
@@ -1838,7 +1838,7 @@ writeRevN = writeRevNWith newArray
1838-- /Pre-release/
1838-- /Pre-release/
1839--
1839--
1840{-# INLINE_NORMAL writeNAligned #-}
1840{-# INLINE_NORMAL writeNAligned #-}
1841−writeNAligned :: forall m a. (MonadIO m, Storable a)
1841+writeNAligned :: forall m a. (MonadIO m, Unboxed a)
1842 => Int -> Int -> Fold m a (Array a)
1842 => Int -> Int -> Fold m a (Array a)
1843writeNAligned align = writeNWith (newArrayAligned align)
1843writeNAligned align = writeNWith (newArrayAligned align)
1844
1844
@@ -1856,7 +1856,7 @@ writeNAligned align = writeNWith (newArrayAligned align)
1856-- /Unimplemented/
1856-- /Unimplemented/
1857--
1857--
1858{-# INLINE_NORMAL writeChunks #-}
1858{-# INLINE_NORMAL writeChunks #-}
1859−writeChunks :: (MonadIO m, Storable a) =>
1859+writeChunks :: (MonadIO m, Unboxed a) =>
1860 Int -> Fold m a (K.Stream n (Array a))
1860 Int -> Fold m a (K.Stream n (Array a))
1861writeChunks n = FL.many (writeN n) FL.toStreamK
1861writeChunks n = FL.many (writeN n) FL.toStreamK
1862
1862
@@ -1889,7 +1889,7 @@ writeChunks n = FL.many (writeN n) FL.toStreamK
1889--
1889--
1890-- /Pre-release/
1890-- /Pre-release/
1891{-# INLINE_NORMAL writeWith #-}
1891{-# INLINE_NORMAL writeWith #-}
1892−writeWith :: forall m a. (MonadIO m, Storable a)
1892+writeWith :: forall m a. (MonadIO m, Unboxed a)
1893 => Int -> Fold m a (Array a)
1893 => Int -> Fold m a (Array a)
1894-- writeWith n = FL.rmapM rightSize $ appendWith (* 2) (newArray n)
1894-- writeWith n = FL.rmapM rightSize $ appendWith (* 2) (newArray n)
1895writeWith elemCount =
1895writeWith elemCount =
@@ -1928,7 +1928,7 @@ writeWith elemCount =
1928--
1928--
1929-- @since 0.7.0
1929-- @since 0.7.0
1930{-# INLINE write #-}
1930{-# INLINE write #-}
1931−write :: forall m a. (MonadIO m, Storable a) => Fold m a (Array a)
1931+write :: forall m a. (MonadIO m, Unboxed a) => Fold m a (Array a)
1932write = writeWith (allocBytesToElemCount (undefined :: a) arrayChunkBytes)
1932write = writeWith (allocBytesToElemCount (undefined :: a) arrayChunkBytes)
1933
1933
1934-------------------------------------------------------------------------------
1934-------------------------------------------------------------------------------
@@ -1940,7 +1940,7 @@ write = writeWith (allocBytesToElemCount (undefined :: a) arrayChunkBytes)
1940-- >>> fromStreamDN n = StreamD.fold (Array.writeN n)
1940-- >>> fromStreamDN n = StreamD.fold (Array.writeN n)
1941--
1941--
1942{-# INLINE_NORMAL fromStreamDN #-}
1942{-# INLINE_NORMAL fromStreamDN #-}
1943−fromStreamDN :: forall m a. (MonadIO m, Storable a)
1943+fromStreamDN :: forall m a. (MonadIO m, Unboxed a)
1944 => Int -> D.Stream m a -> m (Array a)
1944 => Int -> D.Stream m a -> m (Array a)
1945-- fromStreamDN n = D.fold (writeN n)
1945-- fromStreamDN n = D.fold (writeN n)
1946fromStreamDN limit str = do
1946fromStreamDN limit str = do
@@ -1960,14 +1960,14 @@ fromStreamDN limit str = do
1960--
1960--
1961-- @since 0.7.0
1961-- @since 0.7.0
1962{-# INLINABLE fromListN #-}
1962{-# INLINABLE fromListN #-}
1963−fromListN :: (MonadIO m, Storable a) => Int -> [a] -> m (Array a)
1963+fromListN :: (MonadIO m, Unboxed a) => Int -> [a] -> m (Array a)
1964fromListN n xs = fromStreamDN n $ D.fromList xs
1964fromListN n xs = fromStreamDN n $ D.fromList xs
1965
1965
1966-- | Like fromListN but writes the array in reverse order.
1966-- | Like fromListN but writes the array in reverse order.
1967--
1967--
1968-- /Pre-release/
1968-- /Pre-release/
1969{-# INLINE fromListRevN #-}
1969{-# INLINE fromListRevN #-}
1970−fromListRevN :: (MonadIO m, Storable a) => Int -> [a] -> m (Array a)
1970+fromListRevN :: (MonadIO m, Unboxed a) => Int -> [a] -> m (Array a)
1971fromListRevN n xs = D.fold (writeRevN n) $ D.fromList xs
1971fromListRevN n xs = D.fold (writeRevN n) $ D.fromList xs
1972
1972
1973-------------------------------------------------------------------------------
1973-------------------------------------------------------------------------------
@@ -1975,14 +1975,14 @@ fromListRevN n xs = D.fold (writeRevN n) $ D.fromList xs
1975-------------------------------------------------------------------------------
1975-------------------------------------------------------------------------------
1976
1976
1977{-# INLINE arrayStreamKLength #-}
1977{-# INLINE arrayStreamKLength #-}
1978−arrayStreamKLength :: (Monad m, Storable a) => K.Stream m (Array a) -> m Int
1978+arrayStreamKLength :: (Monad m, Unboxed a) => K.Stream m (Array a) -> m Int
1979arrayStreamKLength as = K.foldl' (+) 0 (K.map length as)
1979arrayStreamKLength as = K.foldl' (+) 0 (K.map length as)
1980
1980
1981-- | Convert an array stream to an array. Note that this requires peak memory
1981-- | Convert an array stream to an array. Note that this requires peak memory
1982-- that is double the size of the array stream.
1982-- that is double the size of the array stream.
1983--
1983--
1984{-# INLINE fromArrayStreamK #-}
1984{-# INLINE fromArrayStreamK #-}
1985−fromArrayStreamK :: (Storable a, MonadIO m) =>
1985+fromArrayStreamK :: (Unboxed a, MonadIO m) =>
1986 K.Stream m (Array a) -> m (Array a)
1986 K.Stream m (Array a) -> m (Array a)
1987fromArrayStreamK as = do
1987fromArrayStreamK as = do
1988 len <- arrayStreamKLength as
1988 len <- arrayStreamKLength as
@@ -2002,14 +2002,14 @@ fromArrayStreamK as = do
2002-- >>> fromStreamD = StreamD.fold Array.write
2002-- >>> fromStreamD = StreamD.fold Array.write
2003--
2003--
2004{-# INLINE fromStreamD #-}
2004{-# INLINE fromStreamD #-}
2005−fromStreamD :: (MonadIO m, Storable a) => D.Stream m a -> m (Array a)
2005+fromStreamD :: (MonadIO m, Unboxed a) => D.Stream m a -> m (Array a)
2006fromStreamD m = arrayStreamKFromStreamD m >>= fromArrayStreamK
2006fromStreamD m = arrayStreamKFromStreamD m >>= fromArrayStreamK
2007
2007
2008-- | Create an 'Array' from a list. The list must be of finite size.
2008-- | Create an 'Array' from a list. The list must be of finite size.
2009--
2009--
2010-- @since 0.7.0
2010-- @since 0.7.0
2011{-# INLINE fromList #-}
2011{-# INLINE fromList #-}
2012−fromList :: (MonadIO m, Storable a) => [a] -> m (Array a)
2012+fromList :: (MonadIO m, Unboxed a) => [a] -> m (Array a)
2013fromList xs = fromStreamD $ D.fromList xs
2013fromList xs = fromStreamD $ D.fromList xs
2014
2014
2015-- XXX We are materializing the whole list first for getting the length. Check
2015-- XXX We are materializing the whole list first for getting the length. Check
@@ -2017,7 +2017,7 @@ fromList xs = fromStreamD $ D.fromList xs
2017
2017
2018-- | Like 'fromList' but writes the contents of the list in reverse order.
2018-- | Like 'fromList' but writes the contents of the list in reverse order.
2019{-# INLINE fromListRev #-}
2019{-# INLINE fromListRev #-}
2020−fromListRev :: (MonadIO m, Storable a) => [a] -> m (Array a)
2020+fromListRev :: (MonadIO m, Unboxed a) => [a] -> m (Array a)
2021fromListRev xs = fromListRevN (Prelude.length xs) xs
2021fromListRev xs = fromListRevN (Prelude.length xs) xs
2022
2022
2023-------------------------------------------------------------------------------
2023-------------------------------------------------------------------------------
@@ -2042,7 +2042,7 @@ putSliceUnsafe src srcStartBytes dst dstStartBytes lenBytes = liftIO $ do
2042
2042
2043-- | Copy two arrays into a newly allocated array.
2043-- | Copy two arrays into a newly allocated array.
2044{-# INLINE spliceCopy #-}
2044{-# INLINE spliceCopy #-}
2045−spliceCopy :: forall m a. (MonadIO m, Storable a) =>
2045+spliceCopy :: forall m a. (MonadIO m, Unboxed a) =>
2046 Array a -> Array a -> m (Array a)
2046 Array a -> Array a -> m (Array a)
2047spliceCopy arr1 arr2 = liftIO $ do
2047spliceCopy arr1 arr2 = liftIO $ do
2048 let start1 = arrStart arr1
2048 let start1 = arrStart arr1
@@ -2084,7 +2084,7 @@ spliceUnsafe dst src =
2084--
2084--
2085-- /Pre-release/
2085-- /Pre-release/
2086{-# INLINE spliceWith #-}
2086{-# INLINE spliceWith #-}
2087−spliceWith :: forall m a. (MonadIO m, Storable a) =>
2087+spliceWith :: forall m a. (MonadIO m, Unboxed a) =>
2088 (Int -> Int -> Int) -> Array a -> Array a -> m (Array a)
2088 (Int -> Int -> Int) -> Array a -> Array a -> m (Array a)
2089spliceWith sizer dst@(Array _ start end bound) src = do
2089spliceWith sizer dst@(Array _ start end bound) src = do
2090{-
2090{-
@@ -2118,7 +2118,7 @@ spliceWith sizer dst@(Array _ start end bound) src = do
2118--
2118--
2119-- /Pre-release/
2119-- /Pre-release/
2120{-# INLINE splice #-}
2120{-# INLINE splice #-}
2121−splice :: (MonadIO m, Storable a) => Array a -> Array a -> m (Array a)
2121+splice :: (MonadIO m, Unboxed a) => Array a -> Array a -> m (Array a)
2122splice = spliceWith (+)
2122splice = spliceWith (+)
2123
2123
2124-- | Like 'append' but the growth of the array is exponential. Whenever a new
2124-- | Like 'append' but the growth of the array is exponential. Whenever a new
@@ -2132,7 +2132,7 @@ splice = spliceWith (+)
2132--
2132--
2133-- /Pre-release/
2133-- /Pre-release/
2134{-# INLINE spliceExp #-}
2134{-# INLINE spliceExp #-}
2135−spliceExp :: (MonadIO m, Storable a) => Array a -> Array a -> m (Array a)
2135+spliceExp :: (MonadIO m, Unboxed a) => Array a -> Array a -> m (Array a)
2136spliceExp = spliceWith (\l1 l2 -> max (l1 * 2) (l1 + l2))
2136spliceExp = spliceWith (\l1 l2 -> max (l1 * 2) (l1 + l2))
2137
2137
2138-------------------------------------------------------------------------------
2138-------------------------------------------------------------------------------
@@ -2171,7 +2171,7 @@ breakOn sep arr@Array{..} = asPtrUnsafe arr $ \p -> liftIO $ do
2171-- specified index @i@ is the first index of the second slice.
2171-- specified index @i@ is the first index of the second slice.
2172--
2172--
2173-- @since 0.7.0
2173-- @since 0.7.0
2174−splitAt :: forall a. Storable a => Int -> Array a -> (Array a, Array a)
2174+splitAt :: forall a. Unboxed a => Int -> Array a -> (Array a, Array a)
2175splitAt i arr@Array{..} =
2175splitAt i arr@Array{..} =
2176 let maxIndex = length arr - 1
2176 let maxIndex = length arr - 1
2177 in if i < 0
2177 in if i < 0
@@ -2208,7 +2208,7 @@ splitAt i arr@Array{..} =
2208--
2208--
2209castUnsafe ::
2209castUnsafe ::
2210#ifdef DEVBUILD
2210#ifdef DEVBUILD
2211− Storable b =>
2211+ Unboxed b =>
2212#endif
2212#endif
2213 Array a -> Array b
2213 Array a -> Array b
2214castUnsafe (Array contents start end bound) =
2214castUnsafe (Array contents start end bound) =
@@ -2227,7 +2227,7 @@ asBytes = castUnsafe
2227--
2227--
2228-- /Pre-release/
2228-- /Pre-release/
2229--
2229--
2230−cast :: forall a b. Storable b => Array a -> Maybe (Array b)
2230+cast :: forall a b. Unboxed b => Array a -> Maybe (Array b)
2231cast arr =
2231cast arr =
2232 let len = byteLength arr
2232 let len = byteLength arr
2233 r = len `mod` SIZE_OF(b)
2233 r = len `mod` SIZE_OF(b)
@@ -2316,7 +2316,7 @@ cmp arr1 arr2 =
2316-- NFData
2316-- NFData
2317-------------------------------------------------------------------------------
2317-------------------------------------------------------------------------------
2318
2318
2319−-- This is a Storable array, we cannot have unevaluated data in it so this is
2319+-- This is an Unboxed array, we cannot have unevaluated data in it so this is
2320-- just a no op.
2320-- just a no op.
2321instance NFData (Array a) where
2321instance NFData (Array a) where
2322 {-# INLINE rnf #-}
2322 {-# INLINE rnf #-}
@@ -2330,7 +2330,7 @@ instance NFData1 Array where
2330--
2330--
2331-- /Pre-release/
2331-- /Pre-release/
2332{-# INLINE strip #-}
2332{-# INLINE strip #-}
2333−strip :: forall a m. (Storable a, MonadIO m) =>
2333+strip :: forall a m. (Unboxed a, MonadIO m) =>
2334 (a -> Bool) -> Array a -> m (Array a)
2334 (a -> Bool) -> Array a -> m (Array a)
2335strip eq arr@Array{..} = liftIO $ do
2335strip eq arr@Array{..} = liftIO $ do
2336 st <- getStart arrStart
2336 st <- getStart arrStart
@@ -2374,7 +2374,7 @@ strip eq arr@Array{..} = liftIO $ do
2374--
2374--
2375-- /Pre-release/
2375-- /Pre-release/
2376{-# INLINE bubble #-}
2376{-# INLINE bubble #-}
2377−bubble :: (MonadIO m, Storable a) => (a -> a -> Ordering) -> Array a -> m ()
2377+bubble :: (MonadIO m, Unboxed a) => (a -> a -> Ordering) -> Array a -> m ()
2378bubble cmp0 arr =
2378bubble cmp0 arr =
2379 when (l > 1) $ do
2379 when (l > 1) $ do
2380 x <- getIndexUnsafe (l - 1) arr
2380 x <- getIndexUnsafe (l - 1) arr
core/src/Streamly/Internal/Data/Array/Unboxed/Type.hs+47−47
@@ -89,7 +89,7 @@ import GHC.Ptr (Ptr(..))
89import Streamly.Internal.Data.Array.Unboxed.Mut.Type (ArrayContents)
89import Streamly.Internal.Data.Array.Unboxed.Mut.Type (ArrayContents)
90import Streamly.Internal.Data.Fold.Type (Fold(..))
90import Streamly.Internal.Data.Fold.Type (Fold(..))
91import Streamly.Internal.Data.Stream.Type (Stream)
91import Streamly.Internal.Data.Stream.Type (Stream)
92−import Streamly.Internal.Data.Unboxed (Storable, peekWith, sizeOf)
92+import Streamly.Internal.Data.Unboxed (Unboxed, peekWith, sizeOf)
93import Streamly.Internal.Data.Unfold.Type (Unfold(..))
93import Streamly.Internal.Data.Unfold.Type (Unfold(..))
94import Text.Read (readPrec, readListPrec, readListPrecDefault)
94import Text.Read (readPrec, readListPrec, readListPrecDefault)
95
95
@@ -125,7 +125,7 @@ import qualified Data.Foldable as F
125
125
126-- $arrayNotes
126-- $arrayNotes
127--
127--
128−-- We can use a 'Storable' constraint in the Array type and the constraint can
128+-- We can use an 'Unboxed' constraint in the Array type and the constraint can
129-- be automatically provided to a function that pattern matches on the Array
129-- be automatically provided to a function that pattern matches on the Array
130-- type. However, it has huge performance cost, so we do not use it.
130-- type. However, it has huge performance cost, so we do not use it.
131-- Investigate a GHC improvement possiblity.
131-- Investigate a GHC improvement possiblity.
@@ -134,7 +134,7 @@ import qualified Data.Foldable as F
134--
134--
135data Array a =
135data Array a =
136#ifdef DEVBUILD
136#ifdef DEVBUILD
137− Storable a =>
137+ Unboxed a =>
138#endif
138#endif
139 -- All offsets are in terms of bytes from the start of arraycontents
139 -- All offsets are in terms of bytes from the start of arraycontents
140 Array
140 Array
@@ -182,7 +182,7 @@ unsafeFreeze (MA.Array ac as ae _) = Array ac as ae
182-- | Similar to 'unsafeFreeze' but uses 'MA.rightSize' on the mutable array
182-- | Similar to 'unsafeFreeze' but uses 'MA.rightSize' on the mutable array
183-- first.
183-- first.
184{-# INLINE unsafeFreezeWithShrink #-}
184{-# INLINE unsafeFreezeWithShrink #-}
185−unsafeFreezeWithShrink :: Storable a => MA.Array a -> Array a
185+unsafeFreezeWithShrink :: Unboxed a => MA.Array a -> Array a
186unsafeFreezeWithShrink arr = unsafePerformIO $ do
186unsafeFreezeWithShrink arr = unsafePerformIO $ do
187 MA.Array ac as ae _ <- MA.rightSize arr
187 MA.Array ac as ae _ <- MA.rightSize arr
188 return $ Array ac as ae
188 return $ Array ac as ae
@@ -217,7 +217,7 @@ unpin = fmap unsafeFreeze . MA.unpin . unsafeThaw
217
217
218-- Splice two immutable arrays creating a new array.
218-- Splice two immutable arrays creating a new array.
219{-# INLINE splice #-}
219{-# INLINE splice #-}
220−splice :: (MonadIO m, Storable a) => Array a -> Array a -> m (Array a)
220+splice :: (MonadIO m, Unboxed a) => Array a -> Array a -> m (Array a)
221splice arr1 arr2 =
221splice arr1 arr2 =
222 unsafeFreeze <$> MA.splice (unsafeThaw arr1) (unsafeThaw arr2)
222 unsafeFreeze <$> MA.splice (unsafeThaw arr1) (unsafeThaw arr2)
223
223
@@ -229,7 +229,7 @@ splice arr1 arr2 =
229--
229--
230-- @since 0.8.0
230-- @since 0.8.0
231{-# INLINABLE fromListN #-}
231{-# INLINABLE fromListN #-}
232−fromListN :: Storable a => Int -> [a] -> Array a
232+fromListN :: Unboxed a => Int -> [a] -> Array a
233fromListN n xs = unsafePerformIO $ unsafeFreeze <$> MA.fromListN n xs
233fromListN n xs = unsafePerformIO $ unsafeFreeze <$> MA.fromListN n xs
234
234
235-- | Create an 'Array' from the first N elements of a list in reverse order.
235-- | Create an 'Array' from the first N elements of a list in reverse order.
@@ -238,7 +238,7 @@ fromListN n xs = unsafePerformIO $ unsafeFreeze <$> MA.fromListN n xs
238--
238--
239-- /Pre-release/
239-- /Pre-release/
240{-# INLINABLE fromListRevN #-}
240{-# INLINABLE fromListRevN #-}
241−fromListRevN :: Storable a => Int -> [a] -> Array a
241+fromListRevN :: Unboxed a => Int -> [a] -> Array a
242fromListRevN n xs = unsafePerformIO $ unsafeFreeze <$> MA.fromListRevN n xs
242fromListRevN n xs = unsafePerformIO $ unsafeFreeze <$> MA.fromListRevN n xs
243
243
244-- | Create an 'Array' from a list. The list must be of finite size.
244-- | Create an 'Array' from a list. The list must be of finite size.
@@ -247,7 +247,7 @@ fromListRevN n xs = unsafePerformIO $ unsafeFreeze <$> MA.fromListRevN n xs
247--
247--
248-- @since 0.8.0
248-- @since 0.8.0
249{-# INLINE fromList #-}
249{-# INLINE fromList #-}
250−fromList :: Storable a => [a] -> Array a
250+fromList :: Unboxed a => [a] -> Array a
251fromList xs = unsafePerformIO $ unsafeFreeze <$> MA.fromList xs
251fromList xs = unsafePerformIO $ unsafeFreeze <$> MA.fromList xs
252
252
253-- | Create an 'Array' from a list in reverse order. The list must be of finite
253-- | Create an 'Array' from a list in reverse order. The list must be of finite
@@ -255,16 +255,16 @@ fromList xs = unsafePerformIO $ unsafeFreeze <$> MA.fromList xs
255--
255--
256-- /Pre-release/
256-- /Pre-release/
257{-# INLINABLE fromListRev #-}
257{-# INLINABLE fromListRev #-}
258−fromListRev :: Storable a => [a] -> Array a
258+fromListRev :: Unboxed a => [a] -> Array a
259fromListRev xs = unsafePerformIO $ unsafeFreeze <$> MA.fromListRev xs
259fromListRev xs = unsafePerformIO $ unsafeFreeze <$> MA.fromListRev xs
260
260
261{-# INLINE_NORMAL fromStreamDN #-}
261{-# INLINE_NORMAL fromStreamDN #-}
262−fromStreamDN :: forall m a. (MonadIO m, Storable a)
262+fromStreamDN :: forall m a. (MonadIO m, Unboxed a)
263 => Int -> D.Stream m a -> m (Array a)
263 => Int -> D.Stream m a -> m (Array a)
264fromStreamDN limit str = unsafeFreeze <$> MA.fromStreamDN limit str
264fromStreamDN limit str = unsafeFreeze <$> MA.fromStreamDN limit str
265
265
266{-# INLINE_NORMAL fromStreamD #-}
266{-# INLINE_NORMAL fromStreamD #-}
267−fromStreamD :: forall m a. (MonadIO m, Storable a)
267+fromStreamD :: forall m a. (MonadIO m, Unboxed a)
268 => D.Stream m a -> m (Array a)
268 => D.Stream m a -> m (Array a)
269fromStreamD str = unsafeFreeze <$> MA.fromStreamD str
269fromStreamD str = unsafeFreeze <$> MA.fromStreamD str
270
270
@@ -273,14 +273,14 @@ fromStreamD str = unsafeFreeze <$> MA.fromStreamD str
273-------------------------------------------------------------------------------
273-------------------------------------------------------------------------------
274
274
275{-# INLINE bufferChunks #-}
275{-# INLINE bufferChunks #-}
276−bufferChunks :: (MonadIO m, Storable a) =>
276+bufferChunks :: (MonadIO m, Unboxed a) =>
277 D.Stream m a -> m (K.Stream m (Array a))
277 D.Stream m a -> m (K.Stream m (Array a))
278bufferChunks m = D.foldr K.cons K.nil $ arraysOf defaultChunkSize m
278bufferChunks m = D.foldr K.cons K.nil $ arraysOf defaultChunkSize m
279
279
280-- | @arraysOf n stream@ groups the input stream into a stream of
280-- | @arraysOf n stream@ groups the input stream into a stream of
281-- arrays of size n.
281-- arrays of size n.
282{-# INLINE_NORMAL arraysOf #-}
282{-# INLINE_NORMAL arraysOf #-}
283−arraysOf :: forall m a. (MonadIO m, Storable a)
283+arraysOf :: forall m a. (MonadIO m, Unboxed a)
284 => Int -> D.Stream m a -> D.Stream m (Array a)
284 => Int -> D.Stream m a -> D.Stream m (Array a)
285arraysOf n str = D.map unsafeFreeze $ MA.arraysOf n str
285arraysOf n str = D.map unsafeFreeze $ MA.arraysOf n str
286
286
@@ -291,7 +291,7 @@ arraysOf n str = D.map unsafeFreeze $ MA.arraysOf n str
291-- We can try this if there are any fusion issues in the unfold.
291-- We can try this if there are any fusion issues in the unfold.
292--
292--
293{-# INLINE_NORMAL flattenArrays #-}
293{-# INLINE_NORMAL flattenArrays #-}
294−flattenArrays :: forall m a. (MonadIO m, Storable a)
294+flattenArrays :: forall m a. (MonadIO m, Unboxed a)
295 => D.Stream m (Array a) -> D.Stream m a
295 => D.Stream m (Array a) -> D.Stream m a
296flattenArrays = MA.flattenArrays . D.map unsafeThaw
296flattenArrays = MA.flattenArrays . D.map unsafeThaw
297
297
@@ -302,7 +302,7 @@ flattenArrays = MA.flattenArrays . D.map unsafeThaw
302-- We can try this if there are any fusion issues in the unfold.
302-- We can try this if there are any fusion issues in the unfold.
303--
303--
304{-# INLINE_NORMAL flattenArraysRev #-}
304{-# INLINE_NORMAL flattenArraysRev #-}
305−flattenArraysRev :: forall m a. (MonadIO m, Storable a)
305+flattenArraysRev :: forall m a. (MonadIO m, Unboxed a)
306 => D.Stream m (Array a) -> D.Stream m a
306 => D.Stream m (Array a) -> D.Stream m a
307flattenArraysRev = MA.flattenArraysRev . D.map unsafeThaw
307flattenArraysRev = MA.flattenArraysRev . D.map unsafeThaw
308
308
@@ -322,12 +322,12 @@ breakOn sep arr = do
322--
322--
323-- Unsafe because it does not check the bounds of the array.
323-- Unsafe because it does not check the bounds of the array.
324{-# INLINE_NORMAL unsafeIndexIO #-}
324{-# INLINE_NORMAL unsafeIndexIO #-}
325−unsafeIndexIO :: forall a. Storable a => Int -> Array a -> IO a
325+unsafeIndexIO :: forall a. Unboxed a => Int -> Array a -> IO a
326unsafeIndexIO i arr = MA.getIndexUnsafe i (unsafeThaw arr)
326unsafeIndexIO i arr = MA.getIndexUnsafe i (unsafeThaw arr)
327
327
328-- | Return element at the specified index without checking the bounds.
328-- | Return element at the specified index without checking the bounds.
329{-# INLINE_NORMAL unsafeIndex #-}
329{-# INLINE_NORMAL unsafeIndex #-}
330−unsafeIndex :: forall a. Storable a => Int -> Array a -> a
330+unsafeIndex :: forall a. Unboxed a => Int -> Array a -> a
331unsafeIndex i arr = let !r = unsafeInlineIO $ unsafeIndexIO i arr in r
331unsafeIndex i arr = let !r = unsafeInlineIO $ unsafeIndexIO i arr in r
332
332
333-- | /O(1)/ Get the byte length of the array.
333-- | /O(1)/ Get the byte length of the array.
@@ -344,31 +344,31 @@ byteLength = MA.byteLength . unsafeThaw
344--
344--
345-- @since 0.8.0
345-- @since 0.8.0
346{-# INLINE length #-}
346{-# INLINE length #-}
347−length :: Storable a => Array a -> Int
347+length :: Unboxed a => Array a -> Int
348length arr = MA.length (unsafeThaw arr)
348length arr = MA.length (unsafeThaw arr)
349
349
350-- | Unfold an array into a stream in reverse order.
350-- | Unfold an array into a stream in reverse order.
351--
351--
352-- @since 0.8.0
352-- @since 0.8.0
353{-# INLINE_NORMAL readRev #-}
353{-# INLINE_NORMAL readRev #-}
354−readRev :: forall m a. (Monad m, Storable a) => Unfold m (Array a) a
354+readRev :: forall m a. (Monad m, Unboxed a) => Unfold m (Array a) a
355readRev = Unfold.lmap unsafeThaw $ MA.readRevWith (return . unsafeInlineIO)
355readRev = Unfold.lmap unsafeThaw $ MA.readRevWith (return . unsafeInlineIO)
356
356
357{-# INLINE_NORMAL toStreamD #-}
357{-# INLINE_NORMAL toStreamD #-}
358−toStreamD :: forall m a. (Monad m, Storable a) => Array a -> D.Stream m a
358+toStreamD :: forall m a. (Monad m, Unboxed a) => Array a -> D.Stream m a
359toStreamD arr = MA.toStreamDWith (return . unsafeInlineIO) (unsafeThaw arr)
359toStreamD arr = MA.toStreamDWith (return . unsafeInlineIO) (unsafeThaw arr)
360
360
361{-# INLINE toStreamK #-}
361{-# INLINE toStreamK #-}
362−toStreamK :: forall m a. (Monad m, Storable a) => Array a -> K.Stream m a
362+toStreamK :: forall m a. (Monad m, Unboxed a) => Array a -> K.Stream m a
363toStreamK arr = MA.toStreamKWith (return . unsafeInlineIO) (unsafeThaw arr)
363toStreamK arr = MA.toStreamKWith (return . unsafeInlineIO) (unsafeThaw arr)
364
364
365{-# INLINE_NORMAL toStreamDRev #-}
365{-# INLINE_NORMAL toStreamDRev #-}
366−toStreamDRev :: forall m a. (Monad m, Storable a) => Array a -> D.Stream m a
366+toStreamDRev :: forall m a. (Monad m, Unboxed a) => Array a -> D.Stream m a
367toStreamDRev arr =
367toStreamDRev arr =
368 MA.toStreamDRevWith (return . unsafeInlineIO) (unsafeThaw arr)
368 MA.toStreamDRevWith (return . unsafeInlineIO) (unsafeThaw arr)
369
369
370{-# INLINE toStreamKRev #-}
370{-# INLINE toStreamKRev #-}
371−toStreamKRev :: forall m a. (Monad m, Storable a) => Array a -> K.Stream m a
371+toStreamKRev :: forall m a. (Monad m, Unboxed a) => Array a -> K.Stream m a
372toStreamKRev arr =
372toStreamKRev arr =
373 MA.toStreamKRevWith (return . unsafeInlineIO) (unsafeThaw arr)
373 MA.toStreamKRevWith (return . unsafeInlineIO) (unsafeThaw arr)
374
374
@@ -376,7 +376,7 @@ toStreamKRev arr =
376--
376--
377-- /Pre-release/
377-- /Pre-release/
378{-# INLINE_EARLY toStream #-}
378{-# INLINE_EARLY toStream #-}
379−toStream :: (Monad m, Storable a) => Array a -> Stream m a
379+toStream :: (Monad m, Unboxed a) => Array a -> Stream m a
380toStream = Stream.fromStreamD . toStreamD
380toStream = Stream.fromStreamD . toStreamD
381-- XXX add fallback to StreamK rule
381-- XXX add fallback to StreamK rule
382-- {-# RULES "Streamly.Array.read fallback to StreamK" [1]
382-- {-# RULES "Streamly.Array.read fallback to StreamK" [1]
@@ -386,7 +386,7 @@ toStream = Stream.fromStreamD . toStreamD
386--
386--
387-- /Pre-release/
387-- /Pre-release/
388{-# INLINE_EARLY toStreamRev #-}
388{-# INLINE_EARLY toStreamRev #-}
389−toStreamRev :: (Monad m, Storable a) => Array a -> Stream m a
389+toStreamRev :: (Monad m, Unboxed a) => Array a -> Stream m a
390toStreamRev = Stream.fromStreamD . toStreamDRev
390toStreamRev = Stream.fromStreamD . toStreamDRev
391
391
392-- XXX add fallback to StreamK rule
392-- XXX add fallback to StreamK rule
@@ -394,18 +394,18 @@ toStreamRev = Stream.fromStreamD . toStreamDRev
394-- forall a. S.toStreamK (readRev a) = K.revFromArray a #-}
394-- forall a. S.toStreamK (readRev a) = K.revFromArray a #-}
395
395
396{-# INLINE_NORMAL foldl' #-}
396{-# INLINE_NORMAL foldl' #-}
397−foldl' :: forall a b. Storable a => (b -> a -> b) -> b -> Array a -> b
397+foldl' :: forall a b. Unboxed a => (b -> a -> b) -> b -> Array a -> b
398foldl' f z arr = runIdentity $ D.foldl' f z $ toStreamD arr
398foldl' f z arr = runIdentity $ D.foldl' f z $ toStreamD arr
399
399
400{-# INLINE_NORMAL foldr #-}
400{-# INLINE_NORMAL foldr #-}
401−foldr :: Storable a => (a -> b -> b) -> b -> Array a -> b
401+foldr :: Unboxed a => (a -> b -> b) -> b -> Array a -> b
402foldr f z arr = runIdentity $ D.foldr f z $ toStreamD arr
402foldr f z arr = runIdentity $ D.foldr f z $ toStreamD arr
403
403
404-- | Create two slices of an array without copying the original array. The
404-- | Create two slices of an array without copying the original array. The
405-- specified index @i@ is the first index of the second slice.
405-- specified index @i@ is the first index of the second slice.
406--
406--
407-- @since 0.7.0
407-- @since 0.7.0
408−splitAt :: Storable a => Int -> Array a -> (Array a, Array a)
408+splitAt :: Unboxed a => Int -> Array a -> (Array a, Array a)
409splitAt i arr = (unsafeFreeze a, unsafeFreeze b)
409splitAt i arr = (unsafeFreeze a, unsafeFreeze b)
410 where
410 where
411 (a, b) = MA.splitAt i (unsafeThaw arr)
411 (a, b) = MA.splitAt i (unsafeThaw arr)
@@ -413,7 +413,7 @@ splitAt i arr = (unsafeFreeze a, unsafeFreeze b)
413-- Use foldr/build fusion to fuse with list consumers
413-- Use foldr/build fusion to fuse with list consumers
414-- This can be useful when using the IsList instance
414-- This can be useful when using the IsList instance
415{-# INLINE_LATE toListFB #-}
415{-# INLINE_LATE toListFB #-}
416−toListFB :: forall a b. Storable a => (a -> b -> b) -> b -> Array a -> b
416+toListFB :: forall a b. Unboxed a => (a -> b -> b) -> b -> Array a -> b
417toListFB c n Array{..} = go arrStart
417toListFB c n Array{..} = go arrStart
418 where
418 where
419
419
@@ -434,7 +434,7 @@ toListFB c n Array{..} = go arrStart
434--
434--
435-- @since 0.8.0
435-- @since 0.8.0
436{-# INLINE toList #-}
436{-# INLINE toList #-}
437−toList :: Storable a => Array a -> [a]
437+toList :: Unboxed a => Array a -> [a]
438toList s = build (\c n -> toListFB c n s)
438toList s = build (\c n -> toListFB c n s)
439
439
440-------------------------------------------------------------------------------
440-------------------------------------------------------------------------------
@@ -448,7 +448,7 @@ toList s = build (\c n -> toListFB c n s)
448--
448--
449-- @since 0.8.0
449-- @since 0.8.0
450{-# INLINE_NORMAL writeN #-}
450{-# INLINE_NORMAL writeN #-}
451−writeN :: forall m a. (MonadIO m, Storable a) => Int -> Fold m a (Array a)
451+writeN :: forall m a. (MonadIO m, Unboxed a) => Int -> Fold m a (Array a)
452writeN = fmap unsafeFreeze . MA.writeN
452writeN = fmap unsafeFreeze . MA.writeN
453
453
454-- | @writeNAligned alignment n@ folds a maximum of @n@ elements from the input
454-- | @writeNAligned alignment n@ folds a maximum of @n@ elements from the input
@@ -457,7 +457,7 @@ writeN = fmap unsafeFreeze . MA.writeN
457-- /Pre-release/
457-- /Pre-release/
458--
458--
459{-# INLINE_NORMAL writeNAligned #-}
459{-# INLINE_NORMAL writeNAligned #-}
460−writeNAligned :: forall m a. (MonadIO m, Storable a)
460+writeNAligned :: forall m a. (MonadIO m, Unboxed a)
461 => Int -> Int -> Fold m a (Array a)
461 => Int -> Int -> Fold m a (Array a)
462writeNAligned alignSize = fmap unsafeFreeze . MA.writeNAligned alignSize
462writeNAligned alignSize = fmap unsafeFreeze . MA.writeNAligned alignSize
463
463
@@ -469,12 +469,12 @@ writeNAligned alignSize = fmap unsafeFreeze . MA.writeNAligned alignSize
469--
469--
470-- @since 0.7.0
470-- @since 0.7.0
471{-# INLINE_NORMAL writeNUnsafe #-}
471{-# INLINE_NORMAL writeNUnsafe #-}
472−writeNUnsafe :: forall m a. (MonadIO m, Storable a)
472+writeNUnsafe :: forall m a. (MonadIO m, Unboxed a)
473 => Int -> Fold m a (Array a)
473 => Int -> Fold m a (Array a)
474writeNUnsafe n = unsafeFreeze <$> MA.writeNUnsafe n
474writeNUnsafe n = unsafeFreeze <$> MA.writeNUnsafe n
475
475
476{-# INLINE_NORMAL writeWith #-}
476{-# INLINE_NORMAL writeWith #-}
477−writeWith :: forall m a. (MonadIO m, Storable a)
477+writeWith :: forall m a. (MonadIO m, Unboxed a)
478 => Int -> Fold m a (Array a)
478 => Int -> Fold m a (Array a)
479-- writeWith n = FL.rmapM spliceArrays $ toArraysOf n
479-- writeWith n = FL.rmapM spliceArrays $ toArraysOf n
480writeWith elemCount = unsafeFreeze <$> MA.writeWith elemCount
480writeWith elemCount = unsafeFreeze <$> MA.writeWith elemCount
@@ -487,18 +487,18 @@ writeWith elemCount = unsafeFreeze <$> MA.writeWith elemCount
487--
487--
488-- @since 0.8.0
488-- @since 0.8.0
489{-# INLINE write #-}
489{-# INLINE write #-}
490−write :: forall m a. (MonadIO m, Storable a) => Fold m a (Array a)
490+write :: forall m a. (MonadIO m, Unboxed a) => Fold m a (Array a)
491write = fmap unsafeFreeze MA.write
491write = fmap unsafeFreeze MA.write
492
492
493-------------------------------------------------------------------------------
493-------------------------------------------------------------------------------
494-- Instances
494-- Instances
495-------------------------------------------------------------------------------
495-------------------------------------------------------------------------------
496
496
497−instance (Show a, Storable a) => Show (Array a) where
497+instance (Show a, Unboxed a) => Show (Array a) where
498 {-# INLINE showsPrec #-}
498 {-# INLINE showsPrec #-}
499 showsPrec _ = shows . toList
499 showsPrec _ = shows . toList
500
500
501−instance (Storable a, Read a, Show a) => Read (Array a) where
501+instance (Unboxed a, Read a, Show a) => Read (Array a) where
502 {-# INLINE readPrec #-}
502 {-# INLINE readPrec #-}
503 readPrec = fromList <$> readPrec
503 readPrec = fromList <$> readPrec
504 readListPrec = readListPrecDefault
504 readListPrec = readListPrecDefault
@@ -508,7 +508,7 @@ instance (a ~ Char) => IsString (Array a) where
508 fromString = fromList
508 fromString = fromList
509
509
510-- GHC versions 8.0 and below cannot derive IsList
510-- GHC versions 8.0 and below cannot derive IsList
511−instance Storable a => IsList (Array a) where
511+instance Unboxed a => IsList (Array a) where
512 type (Item (Array a)) = a
512 type (Item (Array a)) = a
513 {-# INLINE fromList #-}
513 {-# INLINE fromList #-}
514 fromList = fromList
514 fromList = fromList
@@ -517,14 +517,14 @@ instance Storable a => IsList (Array a) where
517 {-# INLINE toList #-}
517 {-# INLINE toList #-}
518 toList = toList
518 toList = toList
519
519
520−-- XXX we are assuming that Storable equality means element equality. This may
520+-- XXX we are assuming that Unboxed equality means element equality. This may
521-- or may not be correct? arrcmp is 40% faster compared to stream equality.
521-- or may not be correct? arrcmp is 40% faster compared to stream equality.
522−instance (Storable a, Eq a) => Eq (Array a) where
522+instance (Unboxed a, Eq a) => Eq (Array a) where
523 {-# INLINE (==) #-}
523 {-# INLINE (==) #-}
524 arr1 == arr2 =
524 arr1 == arr2 =
525 (==) EQ $ unsafeInlineIO $! unsafeThaw arr1 `MA.cmp` unsafeThaw arr2
525 (==) EQ $ unsafeInlineIO $! unsafeThaw arr1 `MA.cmp` unsafeThaw arr2
526
526
527−-- Since this is a Storable array we cannot have unevaluated data in it so
527+-- Since this is an Unboxed array we cannot have unevaluated data in it so
528-- this is just a no op.
528-- this is just a no op.
529instance NFData (Array a) where
529instance NFData (Array a) where
530 {-# INLINE rnf #-}
530 {-# INLINE rnf #-}
@@ -533,7 +533,7 @@ instance NFData (Array a) where
533instance NFData1 Array where
533instance NFData1 Array where
534 liftRnf _ Array{} = ()
534 liftRnf _ Array{} = ()
535
535
536−instance (Storable a, Ord a) => Ord (Array a) where
536+instance (Unboxed a, Ord a) => Ord (Array a) where
537 {-# INLINE compare #-}
537 {-# INLINE compare #-}
538 compare arr1 arr2 = runIdentity $
538 compare arr1 arr2 = runIdentity $
539 D.cmpBy compare (toStreamD arr1) (toStreamD arr2)
539 D.cmpBy compare (toStreamD arr1) (toStreamD arr2)
@@ -561,7 +561,7 @@ instance (Storable a, Ord a) => Ord (Array a) where
561 min x y = if x <= y then x else y
561 min x y = if x <= y then x else y
562
562
563#ifdef DEVBUILD
563#ifdef DEVBUILD
564−-- Definitions using the Storable constraint from the Array type. These are to
564+-- Definitions using the Unboxed constraint from the Array type. These are to
565-- make the Foldable instance possible though it is much slower (7x slower).
565-- make the Foldable instance possible though it is much slower (7x slower).
566--
566--
567{-# INLINE_NORMAL toStreamD_ #-}
567{-# INLINE_NORMAL toStreamD_ #-}
@@ -578,7 +578,7 @@ toStreamD_ size Array{..} = D.Stream step arrStart
578
578
579{-
579{-
580
580
581−XXX Why isn't Storable implicit? This does not compile unless I use the Storable
581+XXX Why isn't Unboxed implicit? This does not compile unless I use the Unboxed
582contraint.
582contraint.
583
583
584{-# INLINE_NORMAL _foldr #-}
584{-# INLINE_NORMAL _foldr #-}
@@ -599,16 +599,16 @@ instance Foldable Array where
599-- Semigroup and Monoid
599-- Semigroup and Monoid
600-------------------------------------------------------------------------------
600-------------------------------------------------------------------------------
601
601
602−instance Storable a => Semigroup (Array a) where
602+instance Unboxed a => Semigroup (Array a) where
603 arr1 <> arr2 = unsafePerformIO $ splice arr1 arr2
603 arr1 <> arr2 = unsafePerformIO $ splice arr1 arr2
604
604
605nil ::
605nil ::
606#ifdef DEVBUILD
606#ifdef DEVBUILD
607− Storable a =>
607+ Unboxed a =>
608#endif
608#endif
609 Array a
609 Array a
610nil = Array MA.nilArrayContents 0 0
610nil = Array MA.nilArrayContents 0 0
611
611
612−instance Storable a => Monoid (Array a) where
612+instance Unboxed a => Monoid (Array a) where
613 mempty = nil
613 mempty = nil
614 mappend = (<>)
614 mappend = (<>)
core/src/Streamly/Internal/Data/Stream/Bottom.hs+2−2
@@ -55,7 +55,7 @@ where
55
55
56import Control.Monad.IO.Class (MonadIO(..))
56import Control.Monad.IO.Class (MonadIO(..))
57import Streamly.Internal.Data.Fold.Type (Fold (..))
57import Streamly.Internal.Data.Fold.Type (Fold (..))
58−import Streamly.Internal.Data.Unboxed (Storable)
58+import Streamly.Internal.Data.Unboxed (Unboxed)
59import Streamly.Internal.System.IO (defaultChunkSize)
59import Streamly.Internal.System.IO (defaultChunkSize)
60
60
61import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
61import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
@@ -312,7 +312,7 @@ reverse s = fromStreamD $ D.reverse $ toStreamD s
312--
312--
313-- /Pre-release/
313-- /Pre-release/
314{-# INLINE reverse' #-}
314{-# INLINE reverse' #-}
315−reverse' :: (MonadIO m, Storable a) => Stream m a -> Stream m a
315+reverse' :: (MonadIO m, Unboxed a) => Stream m a -> Stream m a
316-- reverse' s = fromStreamD $ D.reverse' $ toStreamD s
316-- reverse' s = fromStreamD $ D.reverse' $ toStreamD s
317reverse' =
317reverse' =
318 fromStreamD
318 fromStreamD
core/src/Streamly/Internal/Data/Stream/Reduce.hs+2−2
@@ -58,7 +58,7 @@ import Streamly.Internal.Data.Parser (Parser (..))
58import Streamly.Internal.Data.Refold.Type (Refold (..))
58import Streamly.Internal.Data.Refold.Type (Refold (..))
59import Streamly.Internal.Data.Stream.Bottom (foldManyPost)
59import Streamly.Internal.Data.Stream.Bottom (foldManyPost)
60import Streamly.Internal.Data.Stream.Type (Stream, fromStreamD, toStreamD)
60import Streamly.Internal.Data.Stream.Type (Stream, fromStreamD, toStreamD)
61−import Streamly.Internal.Data.Unboxed (Storable)
61+import Streamly.Internal.Data.Unboxed (Unboxed)
62
62
63import qualified Streamly.Internal.Data.Array.Unboxed.Type as Array
63import qualified Streamly.Internal.Data.Array.Unboxed.Type as Array
64import qualified Streamly.Internal.Data.Parser.ParserD as ParserD
64import qualified Streamly.Internal.Data.Parser.ParserD as ParserD
@@ -313,6 +313,6 @@ parseIterate f i m = fromStreamD $
313--
313--
314-- /Pre-release/
314-- /Pre-release/
315{-# INLINE arraysOf #-}
315{-# INLINE arraysOf #-}
316−arraysOf :: (MonadIO m, Storable a)
316+arraysOf :: (MonadIO m, Unboxed a)
317 => Int -> Stream m a -> Stream m (Array a)
317 => Int -> Stream m a -> Stream m (Array a)
318arraysOf n = fromStreamD . Array.arraysOf n . toStreamD
318arraysOf n = fromStreamD . Array.arraysOf n . toStreamD
core/src/Streamly/Internal/Data/Unboxed.hs+1−4
@@ -2,8 +2,7 @@
2{-# LANGUAGE UnboxedTuples #-}
2{-# LANGUAGE UnboxedTuples #-}
3
3
4module Streamly.Internal.Data.Unboxed
4module Streamly.Internal.Data.Unboxed
5− ( Storable
6− , Unboxed
5+ ( Unboxed
7 , alignment
6 , alignment
8 , peekWith
7 , peekWith
9 , pokeWith
8 , pokeWith
@@ -380,8 +379,6 @@ instance forall a. Unboxed a => Unboxed (Complex a) where
380-- Functions
379-- Functions
381--------------------------------------------------------------------------------
380--------------------------------------------------------------------------------
382
381
383−type Storable a = Unboxed a
384−
385{-# INLINE peekWith #-}
382{-# INLINE peekWith #-}
386peekWith :: Unboxed a => ArrayContents a -> Int -> IO a
383peekWith :: Unboxed a => ArrayContents a -> Int -> IO a
387peekWith = readByteArray
384peekWith = readByteArray
src/Streamly/Internal/Data/Array/Stream/Foreign.hs+32−32
@@ -58,7 +58,7 @@ import Control.Monad.IO.Class (MonadIO(..))
58import Data.Semigroup (Semigroup(..))
58import Data.Semigroup (Semigroup(..))
59#endif
59#endif
60import Data.Word (Word8)
60import Data.Word (Word8)
61−import Streamly.Internal.Data.Unboxed (Storable, peekWith, sizeOf)
61+import Streamly.Internal.Data.Unboxed (Unboxed, peekWith, sizeOf)
62import Fusion.Plugin.Types (Fuse(..))
62import Fusion.Plugin.Types (Fuse(..))
63import GHC.Exts (SpecConstrAnnotation(..))
63import GHC.Exts (SpecConstrAnnotation(..))
64import GHC.Types (SPEC(..))
64import GHC.Types (SPEC(..))
@@ -105,7 +105,7 @@ import qualified Streamly.Internal.Data.Stream.Type as Stream
105--
105--
106-- /Pre-release/
106-- /Pre-release/
107{-# INLINE arraysOf #-}
107{-# INLINE arraysOf #-}
108−arraysOf :: (IsStream t, MonadIO m, Storable a)
108+arraysOf :: (IsStream t, MonadIO m, Unboxed a)
109 => Int -> t m a -> t m (Array a)
109 => Int -> t m a -> t m (Array a)
110arraysOf n str = fromStreamD $ A.arraysOf n (toStreamD str)
110arraysOf n str = fromStreamD $ A.arraysOf n (toStreamD str)
111
111
@@ -125,7 +125,7 @@ arraysOf n str = fromStreamD $ A.arraysOf n (toStreamD str)
125--
125--
126-- @since 0.7.0
126-- @since 0.7.0
127{-# INLINE concat #-}
127{-# INLINE concat #-}
128−concat :: (IsStream t, Monad m, Storable a) => t m (Array a) -> t m a
128+concat :: (IsStream t, Monad m, Unboxed a) => t m (Array a) -> t m a
129-- concat m = fromStreamD $ A.flattenArrays (toStreamD m)
129-- concat m = fromStreamD $ A.flattenArrays (toStreamD m)
130-- concat m = fromStreamD $ D.concatMap A.toStreamD (toStreamD m)
130-- concat m = fromStreamD $ D.concatMap A.toStreamD (toStreamD m)
131concat m = fromStreamD $ D.unfoldMany A.read (toStreamD m)
131concat m = fromStreamD $ D.unfoldMany A.read (toStreamD m)
@@ -137,7 +137,7 @@ concat m = fromStreamD $ D.unfoldMany A.read (toStreamD m)
137--
137--
138-- @since 0.7.0
138-- @since 0.7.0
139{-# INLINE concatRev #-}
139{-# INLINE concatRev #-}
140−concatRev :: (IsStream t, Monad m, Storable a) => t m (Array a) -> t m a
140+concatRev :: (IsStream t, Monad m, Unboxed a) => t m (Array a) -> t m a
141-- concatRev m = fromStreamD $ A.flattenArraysRev (toStreamD m)
141-- concatRev m = fromStreamD $ A.flattenArraysRev (toStreamD m)
142concatRev m = fromStreamD $ D.unfoldMany A.readRev (toStreamD m)
142concatRev m = fromStreamD $ D.unfoldMany A.readRev (toStreamD m)
143
143
@@ -150,11 +150,11 @@ concatRev m = fromStreamD $ D.unfoldMany A.readRev (toStreamD m)
150--
150--
151-- /Pre-release/
151-- /Pre-release/
152{-# INLINE interpose #-}
152{-# INLINE interpose #-}
153−interpose :: (Monad m, IsStream t, Storable a) => a -> t m (Array a) -> t m a
153+interpose :: (Monad m, IsStream t, Unboxed a) => a -> t m (Array a) -> t m a
154interpose x = S.interpose x A.read
154interpose x = S.interpose x A.read
155
155
156{-# INLINE intercalateSuffix #-}
156{-# INLINE intercalateSuffix #-}
157−intercalateSuffix :: (Monad m, IsStream t, Storable a)
157+intercalateSuffix :: (Monad m, IsStream t, Unboxed a)
158 => Array a -> t m (Array a) -> t m a
158 => Array a -> t m (Array a) -> t m a
159intercalateSuffix = S.intercalateSuffix A.read
159intercalateSuffix = S.intercalateSuffix A.read
160
160
@@ -163,7 +163,7 @@ intercalateSuffix = S.intercalateSuffix A.read
163--
163--
164-- @since 0.7.0
164-- @since 0.7.0
165{-# INLINE interposeSuffix #-}
165{-# INLINE interposeSuffix #-}
166−interposeSuffix :: (Monad m, IsStream t, Storable a)
166+interposeSuffix :: (Monad m, IsStream t, Unboxed a)
167 => a -> t m (Array a) -> t m a
167 => a -> t m (Array a) -> t m a
168-- interposeSuffix x = fromStreamD . A.unlines x . toStreamD
168-- interposeSuffix x = fromStreamD . A.unlines x . toStreamD
169interposeSuffix x = S.interposeSuffix x A.read
169interposeSuffix x = S.interposeSuffix x A.read
@@ -174,7 +174,7 @@ data FlattenState s a =
174
174
175-- XXX Remove monadIO constraint
175-- XXX Remove monadIO constraint
176{-# INLINE_NORMAL unlines #-}
176{-# INLINE_NORMAL unlines #-}
177−unlines :: forall m a. (MonadIO m, Storable a)
177+unlines :: forall m a. (MonadIO m, Unboxed a)
178 => a -> D.Stream m (Array a) -> D.Stream m a
178 => a -> D.Stream m (Array a) -> D.Stream m a
179unlines sep (D.Stream step state) = D.Stream step' (OuterLoop state)
179unlines sep (D.Stream step state) = D.Stream step' (OuterLoop state)
180 where
180 where
@@ -202,7 +202,7 @@ unlines sep (D.Stream step state) = D.Stream step' (OuterLoop state)
202-- module Streamly.Internal.Data.Array.Stream.Mut.Foreign
202-- module Streamly.Internal.Data.Array.Stream.Mut.Foreign
203--
203--
204{-# INLINE_NORMAL packArraysChunksOf #-}
204{-# INLINE_NORMAL packArraysChunksOf #-}
205−packArraysChunksOf :: (MonadIO m, Storable a)
205+packArraysChunksOf :: (MonadIO m, Unboxed a)
206 => Int -> D.Stream m (Array a) -> D.Stream m (Array a)
206 => Int -> D.Stream m (Array a) -> D.Stream m (Array a)
207packArraysChunksOf n str =
207packArraysChunksOf n str =
208 D.map A.unsafeFreeze $ AS.packArraysChunksOf n $ D.map A.unsafeThaw str
208 D.map A.unsafeFreeze $ AS.packArraysChunksOf n $ D.map A.unsafeThaw str
@@ -210,7 +210,7 @@ packArraysChunksOf n str =
210-- XXX instead of writing two different versions of this operation, we should
210-- XXX instead of writing two different versions of this operation, we should
211-- write it as a pipe.
211-- write it as a pipe.
212{-# INLINE_NORMAL lpackArraysChunksOf #-}
212{-# INLINE_NORMAL lpackArraysChunksOf #-}
213−lpackArraysChunksOf :: (MonadIO m, Storable a)
213+lpackArraysChunksOf :: (MonadIO m, Unboxed a)
214 => Int -> Fold m (Array a) () -> Fold m (Array a) ()
214 => Int -> Fold m (Array a) () -> Fold m (Array a) ()
215lpackArraysChunksOf n fld =
215lpackArraysChunksOf n fld =
216 FL.lmap A.unsafeThaw $ AS.lpackArraysChunksOf n (FL.lmap A.unsafeFreeze fld)
216 FL.lmap A.unsafeThaw $ AS.lpackArraysChunksOf n (FL.lmap A.unsafeFreeze fld)
@@ -220,7 +220,7 @@ lpackArraysChunksOf n fld =
220--
220--
221-- @since 0.7.0
221-- @since 0.7.0
222{-# INLINE compact #-}
222{-# INLINE compact #-}
223−compact :: (MonadIO m, Storable a)
223+compact :: (MonadIO m, Unboxed a)
224 => Int -> SerialT m (Array a) -> SerialT m (Array a)
224 => Int -> SerialT m (Array a) -> SerialT m (Array a)
225compact n xs = fromStreamD $ packArraysChunksOf n (toStreamD xs)
225compact n xs = fromStreamD $ packArraysChunksOf n (toStreamD xs)
226
226
@@ -317,7 +317,7 @@ splitOnSuffix byte s =
317-- to the number of times it can be called on the same stream.
317-- to the number of times it can be called on the same stream.
318--
318--
319{-# INLINE_NORMAL foldBreakD #-}
319{-# INLINE_NORMAL foldBreakD #-}
320−foldBreakD :: forall m a b. (MonadIO m, Storable a) =>
320+foldBreakD :: forall m a b. (MonadIO m, Unboxed a) =>
321 Fold m a b -> D.Stream m (Array a) -> m (b, D.Stream m (Array a))
321 Fold m a b -> D.Stream m (Array a) -> m (b, D.Stream m (Array a))
322foldBreakD (Fold fstep initial extract) stream@(D.Stream step state) = do
322foldBreakD (Fold fstep initial extract) stream@(D.Stream step state) = do
323 res <- initial
323 res <- initial
@@ -353,7 +353,7 @@ foldBreakD (Fold fstep initial extract) stream@(D.Stream step state) = do
353 FL.Partial fs1 -> goArray SPEC st fp next fs1
353 FL.Partial fs1 -> goArray SPEC st fp next fs1
354
354
355{-# INLINE_NORMAL foldBreakK #-}
355{-# INLINE_NORMAL foldBreakK #-}
356−foldBreakK :: forall m a b. (MonadIO m, Storable a) =>
356+foldBreakK :: forall m a b. (MonadIO m, Unboxed a) =>
357 Fold m a b -> K.Stream m (Array a) -> m (b, K.Stream m (Array a))
357 Fold m a b -> K.Stream m (Array a) -> m (b, K.Stream m (Array a))
358foldBreakK (Fold fstep initial extract) stream = do
358foldBreakK (Fold fstep initial extract) stream = do
359 res <- initial
359 res <- initial
@@ -394,7 +394,7 @@ foldBreakK (Fold fstep initial extract) stream = do
394--
394--
395{-# INLINE_NORMAL foldBreak #-}
395{-# INLINE_NORMAL foldBreak #-}
396foldBreak ::
396foldBreak ::
397− (MonadIO m, Storable a)
397+ (MonadIO m, Unboxed a)
398 => FL.Fold m a b
398 => FL.Fold m a b
399 -> SerialT m (A.Array a)
399 -> SerialT m (A.Array a)
400 -> m (b, SerialT m (A.Array a))
400 -> m (b, SerialT m (A.Array a))
@@ -413,7 +413,7 @@ foldBreak f =
413
413
414-- When we have to take an array partially, take the last part of the array.
414-- When we have to take an array partially, take the last part of the array.
415{-# INLINE takeArrayListRev #-}
415{-# INLINE takeArrayListRev #-}
416−takeArrayListRev :: forall a. Storable a => Int -> [Array a] -> [Array a]
416+takeArrayListRev :: forall a. Unboxed a => Int -> [Array a] -> [Array a]
417takeArrayListRev = go
417takeArrayListRev = go
418
418
419 where
419 where
@@ -434,7 +434,7 @@ takeArrayListRev = go
434-- the first split.
434-- the first split.
435{-# INLINE splitAtArrayListRev #-}
435{-# INLINE splitAtArrayListRev #-}
436splitAtArrayListRev ::
436splitAtArrayListRev ::
437− forall a. Storable a => Int -> [Array a] -> ([Array a],[Array a])
437+ forall a. Unboxed a => Int -> [Array a] -> ([Array a],[Array a])
438splitAtArrayListRev n ls
438splitAtArrayListRev n ls
439 | n <= 0 = ([], ls)
439 | n <= 0 = ([], ls)
440 | otherwise = go n ls
440 | otherwise = go n ls
@@ -464,14 +464,14 @@ splitAtArrayListRev n ls
464-- CAUTION! length must more than equal to lengths of all the arrays in the
464-- CAUTION! length must more than equal to lengths of all the arrays in the
465-- stream.
465-- stream.
466{-# INLINE spliceArraysLenUnsafe #-}
466{-# INLINE spliceArraysLenUnsafe #-}
467−spliceArraysLenUnsafe :: (MonadIO m, Storable a)
467+spliceArraysLenUnsafe :: (MonadIO m, Unboxed a)
468 => Int -> SerialT m (MA.Array a) -> m (MA.Array a)
468 => Int -> SerialT m (MA.Array a) -> m (MA.Array a)
469spliceArraysLenUnsafe len buffered = do
469spliceArraysLenUnsafe len buffered = do
470 arr <- liftIO $ MA.newArray len
470 arr <- liftIO $ MA.newArray len
471 S.foldlM' MA.spliceUnsafe (return arr) buffered
471 S.foldlM' MA.spliceUnsafe (return arr) buffered
472
472
473{-# INLINE _spliceArrays #-}
473{-# INLINE _spliceArrays #-}
474−_spliceArrays :: (MonadIO m, Storable a)
474+_spliceArrays :: (MonadIO m, Unboxed a)
475 => SerialT m (Array a) -> m (Array a)
475 => SerialT m (Array a) -> m (Array a)
476_spliceArrays s = do
476_spliceArrays s = do
477 buffered <- S.foldr S.cons S.nil s
477 buffered <- S.foldr S.cons S.nil s
@@ -485,7 +485,7 @@ _spliceArrays s = do
485 writeArr dst arr = MA.spliceUnsafe dst (A.unsafeThaw arr)
485 writeArr dst arr = MA.spliceUnsafe dst (A.unsafeThaw arr)
486
486
487{-# INLINE _spliceArraysBuffered #-}
487{-# INLINE _spliceArraysBuffered #-}
488−_spliceArraysBuffered :: (MonadIO m, Storable a)
488+_spliceArraysBuffered :: (MonadIO m, Unboxed a)
489 => SerialT m (Array a) -> m (Array a)
489 => SerialT m (Array a) -> m (Array a)
490_spliceArraysBuffered s = do
490_spliceArraysBuffered s = do
491 buffered <- S.foldr S.cons S.nil s
491 buffered <- S.foldr S.cons S.nil s
@@ -493,7 +493,7 @@ _spliceArraysBuffered s = do
493 A.unsafeFreeze <$> spliceArraysLenUnsafe len (S.map A.unsafeThaw s)
493 A.unsafeFreeze <$> spliceArraysLenUnsafe len (S.map A.unsafeThaw s)
494
494
495{-# INLINE spliceArraysRealloced #-}
495{-# INLINE spliceArraysRealloced #-}
496−spliceArraysRealloced :: forall m a. (MonadIO m, Storable a)
496+spliceArraysRealloced :: forall m a. (MonadIO m, Unboxed a)
497 => SerialT m (Array a) -> m (Array a)
497 => SerialT m (Array a) -> m (Array a)
498spliceArraysRealloced s = do
498spliceArraysRealloced s = do
499 let n = allocBytesToElemCount (undefined :: a) (4 * 1024)
499 let n = allocBytesToElemCount (undefined :: a) (4 * 1024)
@@ -509,7 +509,7 @@ spliceArraysRealloced s = do
509--
509--
510-- @since 0.7.0
510-- @since 0.7.0
511{-# INLINE toArray #-}
511{-# INLINE toArray #-}
512−toArray :: (MonadIO m, Storable a) => SerialT m (Array a) -> m (Array a)
512+toArray :: (MonadIO m, Unboxed a) => SerialT m (Array a) -> m (Array a)
513toArray = spliceArraysRealloced
513toArray = spliceArraysRealloced
514-- spliceArrays = _spliceArraysBuffered
514-- spliceArrays = _spliceArraysBuffered
515
515
@@ -520,7 +520,7 @@ toArray = spliceArraysRealloced
520--
520--
521{-
521{-
522{-# INLINE toArraysInRange #-}
522{-# INLINE toArraysInRange #-}
523−toArraysInRange :: (IsStream t, MonadIO m, Storable a)
523+toArraysInRange :: (IsStream t, MonadIO m, Unboxed a)
524 => Int -> Int -> Fold m (Array a) b -> Fold m a b
524 => Int -> Int -> Fold m (Array a) b -> Fold m a b
525toArraysInRange low high (Fold step initial extract) =
525toArraysInRange low high (Fold step initial extract) =
526-}
526-}
@@ -528,7 +528,7 @@ toArraysInRange low high (Fold step initial extract) =
528{-
528{-
529-- | Fold the input to a pure buffered stream (List) of arrays.
529-- | Fold the input to a pure buffered stream (List) of arrays.
530{-# INLINE _toArraysOf #-}
530{-# INLINE _toArraysOf #-}
531−_toArraysOf :: (MonadIO m, Storable a)
531+_toArraysOf :: (MonadIO m, Unboxed a)
532 => Int -> Fold m a (SerialT Identity (Array a))
532 => Int -> Fold m a (SerialT Identity (Array a))
533_toArraysOf n = FL.chunksOf n (A.writeNF n) FL.toStream
533_toArraysOf n = FL.chunksOf n (A.writeNF n) FL.toStream
534-}
534-}
@@ -549,7 +549,7 @@ newtype List a = List {getList :: [a]}
549-- to the number of times it can be called on the same stream.
549-- to the number of times it can be called on the same stream.
550{-# INLINE_NORMAL parseBreakD #-}
550{-# INLINE_NORMAL parseBreakD #-}
551parseBreakD ::
551parseBreakD ::
552− forall m a b. (MonadIO m, MonadThrow m, Storable a)
552+ forall m a b. (MonadIO m, MonadThrow m, Unboxed a)
553 => PRD.Parser m a b
553 => PRD.Parser m a b
554 -> D.Stream m (Array.Array a)
554 -> D.Stream m (Array.Array a)
555 -> m (b, D.Stream m (Array.Array a))
555 -> m (b, D.Stream m (Array.Array a))
@@ -629,7 +629,7 @@ parseBreakD
629
629
630{-# INLINE_NORMAL parseBreakK #-}
630{-# INLINE_NORMAL parseBreakK #-}
631parseBreakK ::
631parseBreakK ::
632− forall m a b. (MonadIO m, MonadThrow m, Storable a)
632+ forall m a b. (MonadIO m, MonadThrow m, Unboxed a)
633 => PRD.Parser m a b
633 => PRD.Parser m a b
634 -> K.Stream m (Array.Array a)
634 -> K.Stream m (Array.Array a)
635 -> m (b, K.Stream m (Array.Array a))
635 -> m (b, K.Stream m (Array.Array a))
@@ -708,7 +708,7 @@ parseBreakK (PRD.Parser pstep initial extract) stream = do
708--
708--
709{-# INLINE_NORMAL parseBreak #-}
709{-# INLINE_NORMAL parseBreak #-}
710parseBreak ::
710parseBreak ::
711− (MonadIO m, MonadThrow m, Storable a)
711+ (MonadIO m, MonadThrow m, Unboxed a)
712 => PR.Parser m a b
712 => PR.Parser m a b
713 -> SerialT m (A.Array a)
713 -> SerialT m (A.Array a)
714 -> m (b, SerialT m (A.Array a))
714 -> m (b, SerialT m (A.Array a))
@@ -734,7 +734,7 @@ parseBreak p =
734--
734--
735{-# INLINE_NORMAL runArrayParserDBreak #-}
735{-# INLINE_NORMAL runArrayParserDBreak #-}
736runArrayParserDBreak ::
736runArrayParserDBreak ::
737− forall m a b. (MonadIO m, MonadThrow m, Storable a)
737+ forall m a b. (MonadIO m, MonadThrow m, Unboxed a)
738 => PRD.Parser m (Array a) b
738 => PRD.Parser m (Array a) b
739 -> D.Stream m (Array.Array a)
739 -> D.Stream m (Array.Array a)
740 -> m (b, D.Stream m (Array.Array a))
740 -> m (b, D.Stream m (Array.Array a))
@@ -806,7 +806,7 @@ runArrayParserDBreak
806--
806--
807{-# INLINE parseArr #-}
807{-# INLINE parseArr #-}
808parseArr ::
808parseArr ::
809− (MonadIO m, MonadThrow m, Storable a)
809+ (MonadIO m, MonadThrow m, Unboxed a)
810 => ASF.Parser m a b
810 => ASF.Parser m a b
811 -> SerialT m (A.Array a)
811 -> SerialT m (A.Array a)
812 -> m (b, SerialT m (A.Array a))
812 -> m (b, SerialT m (A.Array a))
@@ -818,7 +818,7 @@ parseArr p s = fmap fromStreamD <$> parseBreakD p (toStreamD s)
818-- /Pre-release/
818-- /Pre-release/
819--
819--
820{-# INLINE runArrayFold #-}
820{-# INLINE runArrayFold #-}
821−runArrayFold :: (MonadIO m, MonadThrow m, Storable a) =>
821+runArrayFold :: (MonadIO m, MonadThrow m, Unboxed a) =>
822 ArrayFold m a b -> SerialT m (A.Array a) -> m b
822 ArrayFold m a b -> SerialT m (A.Array a) -> m b
823runArrayFold (ArrayFold p) s = fst <$> runArrayParserDBreak p (toStreamD s)
823runArrayFold (ArrayFold p) s = fst <$> runArrayParserDBreak p (toStreamD s)
824
824
@@ -827,7 +827,7 @@ runArrayFold (ArrayFold p) s = fst <$> runArrayParserDBreak p (toStreamD s)
827-- /Pre-release/
827-- /Pre-release/
828--
828--
829{-# INLINE runArrayFoldBreak #-}
829{-# INLINE runArrayFoldBreak #-}
830−runArrayFoldBreak :: (MonadIO m, MonadThrow m, Storable a) =>
830+runArrayFoldBreak :: (MonadIO m, MonadThrow m, Unboxed a) =>
831 ArrayFold m a b -> SerialT m (A.Array a) -> m (b, SerialT m (A.Array a))
831 ArrayFold m a b -> SerialT m (A.Array a) -> m (b, SerialT m (A.Array a))
832runArrayFoldBreak (ArrayFold p) s =
832runArrayFoldBreak (ArrayFold p) s =
833 second fromStreamD <$> runArrayParserDBreak p (toStreamD s)
833 second fromStreamD <$> runArrayParserDBreak p (toStreamD s)
@@ -842,7 +842,7 @@ data ParseChunksState x inpBuf st pst =
842
842
843{-# INLINE_NORMAL runArrayFoldManyD #-}
843{-# INLINE_NORMAL runArrayFoldManyD #-}
844runArrayFoldManyD
844runArrayFoldManyD
845− :: (MonadThrow m, Storable a)
845+ :: (MonadThrow m, Unboxed a)
846 => ArrayFold m a b
846 => ArrayFold m a b
847 -> D.Stream m (Array a)
847 -> D.Stream m (Array a)
848 -> D.Stream m b
848 -> D.Stream m b
@@ -970,7 +970,7 @@ runArrayFoldManyD
970-- /Pre-release/
970-- /Pre-release/
971{-# INLINE runArrayFoldMany #-}
971{-# INLINE runArrayFoldMany #-}
972runArrayFoldMany
972runArrayFoldMany
973− :: (IsStream t, MonadThrow m, Storable a)
973+ :: (IsStream t, MonadThrow m, Unboxed a)
974 => ArrayFold m a b
974 => ArrayFold m a b
975 -> t m (Array a)
975 -> t m (Array a)
976 -> t m b
976 -> t m b
src/Streamly/Internal/Data/Stream/IsStream/Common.hs+2−2
@@ -79,7 +79,7 @@ import Streamly.Internal.Data.Stream.IsStream.Type
79import Streamly.Internal.Data.Stream.Serial (SerialT)
79import Streamly.Internal.Data.Stream.Serial (SerialT)
80import Streamly.Internal.Data.Time.Units (AbsTime, RelTime64, addToAbsTime64)
80import Streamly.Internal.Data.Time.Units (AbsTime, RelTime64, addToAbsTime64)
81import Streamly.Internal.System.IO (defaultChunkSize)
81import Streamly.Internal.System.IO (defaultChunkSize)
82−import Streamly.Internal.Data.Unboxed (Storable, Unboxed)
82+import Streamly.Internal.Data.Unboxed (Unboxed)
83
83
84import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
84import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
85import qualified Streamly.Internal.Data.Stream.Async as Async
85import qualified Streamly.Internal.Data.Stream.Async as Async
@@ -499,7 +499,7 @@ reverse s = fromStreamS $ S.reverse $ toStreamS s
499--
499--
500-- /Pre-release/
500-- /Pre-release/
501{-# INLINE reverse' #-}
501{-# INLINE reverse' #-}
502−reverse' :: (IsStream t, MonadIO m, Storable a) => t m a -> t m a
502+reverse' :: (IsStream t, MonadIO m, Unboxed a) => t m a -> t m a
503-- reverse' s = fromStreamD $ D.reverse' $ toStreamD s
503-- reverse' s = fromStreamD $ D.reverse' $ toStreamD s
504reverse' =
504reverse' =
505 fromStreamD
505 fromStreamD
src/Streamly/Internal/Data/Stream/IsStream/Reduce.hs+7−7
@@ -178,7 +178,7 @@ import Streamly.Internal.Data.Stream.IsStream.Type
178import Streamly.Internal.Data.Time.Units
178import Streamly.Internal.Data.Time.Units
179 ( AbsTime, MilliSecond64(..), addToAbsTime, toRelTime
179 ( AbsTime, MilliSecond64(..), addToAbsTime, toRelTime
180 , toAbsTime)
180 , toAbsTime)
181−import Streamly.Internal.Data.Unboxed (Storable, Unboxed)
181+import Streamly.Internal.Data.Unboxed (Unboxed)
182
182
183import qualified Data.Heap as H
183import qualified Data.Heap as H
184import qualified Streamly.Data.Unfold as Unfold
184import qualified Streamly.Data.Unfold as Unfold
@@ -779,7 +779,7 @@ splitWithSuffix predicate f = foldMany (FL.takeEndBy predicate f)
779-- /Unimplemented/
779-- /Unimplemented/
780--
780--
781{-# INLINE splitOnAny #-}
781{-# INLINE splitOnAny #-}
782−splitOnAny :: -- (IsStream t, Monad m, Storable a, Integral a) =>
782+splitOnAny :: -- (IsStream t, Monad m, Unboxed a, Integral a) =>
783 [Array a] -> Fold m a b -> t m a -> t m b
783 [Array a] -> Fold m a b -> t m a -> t m b
784splitOnAny _subseq _f _m =
784splitOnAny _subseq _f _m =
785 undefined -- D.fromStreamD $ D.splitOnAny f subseq (D.toStreamD m)
785 undefined -- D.fromStreamD $ D.splitOnAny f subseq (D.toStreamD m)
@@ -889,7 +889,7 @@ splitOnSuffixSeq patt f m =
889--
889--
890-- /Unimplemented/
890-- /Unimplemented/
891{-# INLINE wordsOn #-}
891{-# INLINE wordsOn #-}
892−wordsOn :: -- (IsStream t, Monad m, Storable a, Eq a) =>
892+wordsOn :: -- (IsStream t, Monad m, Unboxed a, Eq a) =>
893 Array a -> Fold m a b -> t m a -> t m b
893 Array a -> Fold m a b -> t m a -> t m b
894wordsOn _subseq _f _m =
894wordsOn _subseq _f _m =
895 undefined -- D.fromStreamD $ D.wordsOn f subseq (D.toStreamD m)
895 undefined -- D.fromStreamD $ D.wordsOn f subseq (D.toStreamD m)
@@ -939,7 +939,7 @@ splitWithSuffixSeq patt f m =
939--
939--
940-- /Unimplemented/
940-- /Unimplemented/
941{-# INLINE splitOnSuffixSeqAny #-}
941{-# INLINE splitOnSuffixSeqAny #-}
942−splitOnSuffixSeqAny :: -- (IsStream t, Monad m, Storable a, Integral a) =>
942+splitOnSuffixSeqAny :: -- (IsStream t, Monad m, Unboxed a, Integral a) =>
943 [Array a] -> Fold m a b -> t m a -> t m b
943 [Array a] -> Fold m a b -> t m a -> t m b
944splitOnSuffixSeqAny _subseq _f _m = undefined
944splitOnSuffixSeqAny _subseq _f _m = undefined
945 -- D.fromStreamD $ D.splitPostAny f subseq (D.toStreamD m)
945 -- D.fromStreamD $ D.splitPostAny f subseq (D.toStreamD m)
@@ -975,7 +975,7 @@ chunksOf n f = fromStreamD . D.chunksOf n f . toStreamD
975--
975--
976-- /Pre-release/
976-- /Pre-release/
977{-# INLINE arraysOf #-}
977{-# INLINE arraysOf #-}
978−arraysOf :: (IsStream t, MonadIO m, Storable a)
978+arraysOf :: (IsStream t, MonadIO m, Unboxed a)
979 => Int -> t m a -> t m (Array a)
979 => Int -> t m a -> t m (Array a)
980arraysOf n = fromStreamD . A.arraysOf n . toStreamD
980arraysOf n = fromStreamD . A.arraysOf n . toStreamD
981
981
@@ -1081,7 +1081,7 @@ classifySlidingSessions tick interval slide (Fold step initial extract) str
1081-- insert the new elements, and apply an incremental fold on the sliding
1081-- insert the new elements, and apply an incremental fold on the sliding
1082-- window, supplying the outgoing elements, the new ring buffer as arguments.
1082-- window, supplying the outgoing elements, the new ring buffer as arguments.
1083slidingChunkBuffer
1083slidingChunkBuffer
1084− :: (IsStream t, Monad m, Ord a, Storable a)
1084+ :: (IsStream t, Monad m, Ord a, Unboxed a)
1085 => Int -- window size
1085 => Int -- window size
1086 -> Int -- window slide
1086 -> Int -- window slide
1087 -> Fold m (Ring a, Array a) b
1087 -> Fold m (Ring a, Array a) b
@@ -1094,7 +1094,7 @@ slidingChunkBuffer = undefined
1094-- an incremental fold on the sliding window, supplying the outgoing elements,
1094-- an incremental fold on the sliding window, supplying the outgoing elements,
1095-- and the new radix tree buffer as arguments.
1095-- and the new radix tree buffer as arguments.
1096slidingSessionBuffer
1096slidingSessionBuffer
1097− :: (IsStream t, Monad m, Ord a, Storable a)
1097+ :: (IsStream t, Monad m, Ord a, Unboxed a)
1098 => Int -- window size
1098 => Int -- window size
1099 -> Int -- tick size
1099 -> Int -- tick size
1100 -> Fold m (RTree a, Array a) b
1100 -> Fold m (RTree a, Array a) b
src/Streamly/Internal/FileSystem/FD.hs+15−15
@@ -120,7 +120,7 @@ import Control.Monad.IO.Class (MonadIO(..))
120import Data.Word (Word8)
120import Data.Word (Word8)
121-- import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
121-- import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
122import Foreign.Ptr (castPtr)
122import Foreign.Ptr (castPtr)
123−import Streamly.Internal.Data.Unboxed (Storable)
123+import Streamly.Internal.Data.Unboxed (Unboxed)
124-- import System.IO (Handle, hGetBufSome, hPutBuf)
124-- import System.IO (Handle, hGetBufSome, hPutBuf)
125import System.IO (IOMode)
125import System.IO (IOMode)
126import Prelude hiding (read)
126import Prelude hiding (read)
@@ -237,7 +237,7 @@ readArrayUpto size (Handle fd) = do
237--
237--
238-- @since 0.7.0
238-- @since 0.7.0
239{-# INLINABLE writeArray #-}
239{-# INLINABLE writeArray #-}
240−writeArray :: Storable a => Handle -> Array a -> IO ()
240+writeArray :: Unboxed a => Handle -> Array a -> IO ()
241writeArray _ arr | A.length arr == 0 = return ()
241writeArray _ arr | A.length arr == 0 = return ()
242writeArray (Handle fd) arr =
242writeArray (Handle fd) arr =
243 asPtrUnsafe arr $ \p ->
243 asPtrUnsafe arr $ \p ->
@@ -334,7 +334,7 @@ readInChunksOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
334readInChunksOf chunkSize h = AS.concat $ readArraysOfUpto chunkSize h
334readInChunksOf chunkSize h = AS.concat $ readArraysOfUpto chunkSize h
335
335
336-- TODO
336-- TODO
337−-- read :: (IsStream t, MonadIO m, Storable a) => Handle -> t m a
337+-- read :: (IsStream t, MonadIO m, Unboxed a) => Handle -> t m a
338--
338--
339-- > read = 'readByChunks' A.defaultChunkSize
339-- > read = 'readByChunks' A.defaultChunkSize
340-- | Generate a stream of elements of the given type from a file 'Handle'. The
340-- | Generate a stream of elements of the given type from a file 'Handle'. The
@@ -353,7 +353,7 @@ read = AS.concat . readArrays
353--
353--
354-- @since 0.7.0
354-- @since 0.7.0
355{-# INLINE writeArrays #-}
355{-# INLINE writeArrays #-}
356−writeArrays :: (MonadIO m, Storable a) => Handle -> Stream m (Array a) -> m ()
356+writeArrays :: (MonadIO m, Unboxed a) => Handle -> Stream m (Array a) -> m ()
357writeArrays h = S.mapM_ (liftIO . writeArray h)
357writeArrays h = S.mapM_ (liftIO . writeArray h)
358
358
359-- | Write a stream of arrays to a handle after coalescing them in chunks of
359-- | Write a stream of arrays to a handle after coalescing them in chunks of
@@ -363,7 +363,7 @@ writeArrays h = S.mapM_ (liftIO . writeArray h)
363--
363--
364-- @since 0.7.0
364-- @since 0.7.0
365{-# INLINE writeArraysPackedUpto #-}
365{-# INLINE writeArraysPackedUpto #-}
366−writeArraysPackedUpto :: (MonadIO m, Storable a)
366+writeArraysPackedUpto :: (MonadIO m, Unboxed a)
367 => Int -> Handle -> Stream m (Array a) -> m ()
367 => Int -> Handle -> Stream m (Array a) -> m ()
368writeArraysPackedUpto n h xs = writeArrays h $ AS.compact n xs
368writeArraysPackedUpto n h xs = writeArrays h $ AS.compact n xs
369
369
@@ -422,7 +422,7 @@ write = writeInChunksOf defaultChunkSize
422
422
423{-
423{-
424{-# INLINE write #-}
424{-# INLINE write #-}
425−write :: (MonadIO m, Storable a) => Handle -> Stream m a -> m ()
425+write :: (MonadIO m, Unboxed a) => Handle -> Stream m a -> m ()
426write = toHandleWith A.defaultChunkSize
426write = toHandleWith A.defaultChunkSize
427-}
427-}
428
428
@@ -481,7 +481,7 @@ readLines h f = foldLines (readUtf8 h) f
481--
481--
482-- @since 0.7.0
482-- @since 0.7.0
483{-# INLINE readFrames #-}
483{-# INLINE readFrames #-}
484−readFrames :: (IsStream t, MonadIO m, Storable a)
484+readFrames :: (IsStream t, MonadIO m, Unboxed a)
485 => Array a -> Handle -> Fold m a b -> t m b
485 => Array a -> Handle -> Fold m a b -> t m b
486readFrames = undefined -- foldFrames . read
486readFrames = undefined -- foldFrames . read
487
487
@@ -490,7 +490,7 @@ readFrames = undefined -- foldFrames . read
490--
490--
491-- @since 0.7.0
491-- @since 0.7.0
492{-# INLINE writeByFrames #-}
492{-# INLINE writeByFrames #-}
493−writeByFrames :: (IsStream t, MonadIO m, Storable a)
493+writeByFrames :: (IsStream t, MonadIO m, Unboxed a)
494 => Array a -> Handle -> t m a -> m ()
494 => Array a -> Handle -> t m a -> m ()
495writeByFrames = undefined
495writeByFrames = undefined
496
496
@@ -508,7 +508,7 @@ writeByFrames = undefined
508--
508--
509-- @since 0.7.0
509-- @since 0.7.0
510{-# INLINE readIndex #-}
510{-# INLINE readIndex #-}
511−readIndex :: Storable a => Handle -> Int -> Maybe a
511+readIndex :: Unboxed a => Handle -> Int -> Maybe a
512readIndex arr i = undefined
512readIndex arr i = undefined
513
513
514-- NOTE: To represent a range to read we have chosen (start, size) instead of
514-- NOTE: To represent a range to read we have chosen (start, size) instead of
@@ -528,7 +528,7 @@ readIndex arr i = undefined
528-- chunk is aligned with @chunkSize@ from second chunk onwards.
528-- chunk is aligned with @chunkSize@ from second chunk onwards.
529--
529--
530{-# INLINE readSliceWith #-}
530{-# INLINE readSliceWith #-}
531−readSliceWith :: (IsStream t, MonadIO m, Storable a)
531+readSliceWith :: (IsStream t, MonadIO m, Unboxed a)
532 => Int -> Handle -> Int -> Int -> t m a
532 => Int -> Handle -> Int -> Int -> t m a
533readSliceWith chunkSize h pos len = undefined
533readSliceWith chunkSize h pos len = undefined
534
534
@@ -538,7 +538,7 @@ readSliceWith chunkSize h pos len = undefined
538--
538--
539-- @since 0.7.0
539-- @since 0.7.0
540{-# INLINE readSlice #-}
540{-# INLINE readSlice #-}
541−readSlice :: (IsStream t, MonadIO m, Storable a)
541+readSlice :: (IsStream t, MonadIO m, Unboxed a)
542 => Handle -> Int -> Int -> t m a
542 => Handle -> Int -> Int -> t m a
543readSlice = readSliceWith defaultChunkSize
543readSlice = readSliceWith defaultChunkSize
544
544
@@ -548,7 +548,7 @@ readSlice = readSliceWith defaultChunkSize
548--
548--
549-- @since 0.7.0
549-- @since 0.7.0
550{-# INLINE readSliceRev #-}
550{-# INLINE readSliceRev #-}
551−readSliceRev :: (IsStream t, MonadIO m, Storable a)
551+readSliceRev :: (IsStream t, MonadIO m, Unboxed a)
552 => Handle -> Int -> Int -> t m a
552 => Handle -> Int -> Int -> t m a
553readSliceRev h i count = undefined
553readSliceRev h i count = undefined
554
554
@@ -556,7 +556,7 @@ readSliceRev h i count = undefined
556--
556--
557-- @since 0.7.0
557-- @since 0.7.0
558{-# INLINE writeIndex #-}
558{-# INLINE writeIndex #-}
559−writeIndex :: (MonadIO m, Storable a) => Handle -> Int -> a -> m ()
559+writeIndex :: (MonadIO m, Unboxed a) => Handle -> Int -> a -> m ()
560writeIndex h i a = undefined
560writeIndex h i a = undefined
561
561
562-- | @writeSlice h i count stream@ writes a stream to the file handle @h@
562-- | @writeSlice h i count stream@ writes a stream to the file handle @h@
@@ -565,7 +565,7 @@ writeIndex h i a = undefined
565--
565--
566-- @since 0.7.0
566-- @since 0.7.0
567{-# INLINE writeSlice #-}
567{-# INLINE writeSlice #-}
568−writeSlice :: (IsStream t, Monad m, Storable a)
568+writeSlice :: (IsStream t, Monad m, Unboxed a)
569 => Handle -> Int -> Int -> t m a -> m ()
569 => Handle -> Int -> Int -> t m a -> m ()
570writeSlice h i len s = undefined
570writeSlice h i len s = undefined
571
571
@@ -575,7 +575,7 @@ writeSlice h i len s = undefined
575--
575--
576-- @since 0.7.0
576-- @since 0.7.0
577{-# INLINE writeSliceRev #-}
577{-# INLINE writeSliceRev #-}
578−writeSliceRev :: (IsStream t, Monad m, Storable a)
578+writeSliceRev :: (IsStream t, Monad m, Unboxed a)
579 => Handle -> Int -> Int -> t m a -> m ()
579 => Handle -> Int -> Int -> t m a -> m ()
580writeSliceRev arr i len s = undefined
580writeSliceRev arr i len s = undefined
581-}
581-}
src/Streamly/Internal/FileSystem/Handle.hs+15−15
@@ -114,7 +114,7 @@ import Control.Monad.IO.Class (MonadIO(..))
114import Data.Function ((&))
114import Data.Function ((&))
115import Data.Maybe (isNothing, fromJust)
115import Data.Maybe (isNothing, fromJust)
116import Data.Word (Word8)
116import Data.Word (Word8)
117−import Streamly.Internal.Data.Unboxed (Storable)
117+import Streamly.Internal.Data.Unboxed (Unboxed)
118import System.IO (Handle, SeekMode(..), hGetBufSome, hPutBuf, hSeek)
118import System.IO (Handle, SeekMode(..), hGetBufSome, hPutBuf, hSeek)
119import Prelude hiding (read)
119import Prelude hiding (read)
120
120
@@ -365,7 +365,7 @@ getBytesWith size h = AS.concat $ getChunksWith size h
365
365
366-- TODO
366-- TODO
367-- Generate a stream of elements of the given type from a file 'Handle'.
367-- Generate a stream of elements of the given type from a file 'Handle'.
368−-- read :: (IsStream t, MonadIO m, Storable a) => Handle -> t m a
368+-- read :: (IsStream t, MonadIO m, Unboxed a) => Handle -> t m a
369--
369--
370-- | Unfolds a file handle into a byte stream. IO requests to the device are
370-- | Unfolds a file handle into a byte stream. IO requests to the device are
371-- performed in sizes of
371-- performed in sizes of
@@ -438,7 +438,7 @@ putChunks h = S.mapM_ (putChunk h)
438--
438--
439-- @since 0.9.0
439-- @since 0.9.0
440{-# INLINE putChunksWith #-}
440{-# INLINE putChunksWith #-}
441−putChunksWith :: (MonadIO m, Storable a)
441+putChunksWith :: (MonadIO m, Unboxed a)
442 => Int -> Handle -> Stream m (Array a) -> m ()
442 => Int -> Handle -> Stream m (Array a) -> m ()
443putChunksWith n h xs = putChunks h $ AS.compact n xs
443putChunksWith n h xs = putChunks h $ AS.compact n xs
444
444
@@ -495,7 +495,7 @@ consumeChunks = Refold.drainBy putChunk
495--
495--
496-- @since 0.9.0
496-- @since 0.9.0
497{-# INLINE writeChunksWith #-}
497{-# INLINE writeChunksWith #-}
498−writeChunksWith :: (MonadIO m, Storable a)
498+writeChunksWith :: (MonadIO m, Unboxed a)
499 => Int -> Handle -> Fold m (Array a) ()
499 => Int -> Handle -> Fold m (Array a) ()
500writeChunksWith n h = lpackArraysChunksOf n (writeChunks h)
500writeChunksWith n h = lpackArraysChunksOf n (writeChunks h)
501
501
@@ -504,7 +504,7 @@ writeChunksWith n h = lpackArraysChunksOf n (writeChunks h)
504-- @since 0.7.0
504-- @since 0.7.0
505{-# DEPRECATED writeChunksWithBufferOf "Please use writeChunksWith instead." #-}
505{-# DEPRECATED writeChunksWithBufferOf "Please use writeChunksWith instead." #-}
506{-# INLINE writeChunksWithBufferOf #-}
506{-# INLINE writeChunksWithBufferOf #-}
507−writeChunksWithBufferOf :: (MonadIO m, Storable a)
507+writeChunksWithBufferOf :: (MonadIO m, Unboxed a)
508 => Int -> Handle -> Fold m (Array a) ()
508 => Int -> Handle -> Fold m (Array a) ()
509writeChunksWithBufferOf = writeChunksWith
509writeChunksWithBufferOf = writeChunksWith
510
510
@@ -578,7 +578,7 @@ consumer = consumerWith defaultChunkSize
578
578
579{-
579{-
580{-# INLINE write #-}
580{-# INLINE write #-}
581−write :: (MonadIO m, Storable a) => Handle -> Stream m a -> m ()
581+write :: (MonadIO m, Unboxed a) => Handle -> Stream m a -> m ()
582write = toHandleWith A.defaultChunkSize
582write = toHandleWith A.defaultChunkSize
583-}
583-}
584
584
@@ -641,7 +641,7 @@ readLines h f = foldLines (readUtf8 h) f
641--
641--
642-- @since 0.7.0
642-- @since 0.7.0
643{-# INLINE readFrames #-}
643{-# INLINE readFrames #-}
644−readFrames :: (IsStream t, MonadIO m, Storable a)
644+readFrames :: (IsStream t, MonadIO m, Unboxed a)
645 => Array a -> Handle -> Fold m a b -> t m b
645 => Array a -> Handle -> Fold m a b -> t m b
646readFrames = undefined -- foldFrames . read
646readFrames = undefined -- foldFrames . read
647
647
@@ -650,7 +650,7 @@ readFrames = undefined -- foldFrames . read
650--
650--
651-- @since 0.7.0
651-- @since 0.7.0
652{-# INLINE writeByFrames #-}
652{-# INLINE writeByFrames #-}
653−writeByFrames :: (IsStream t, MonadIO m, Storable a)
653+writeByFrames :: (IsStream t, MonadIO m, Unboxed a)
654 => Array a -> Handle -> t m a -> m ()
654 => Array a -> Handle -> t m a -> m ()
655writeByFrames = undefined
655writeByFrames = undefined
656
656
@@ -685,7 +685,7 @@ writeBySessionsOf n = writeByChunksOrSessionsOf defaultChunkSize n
685--
685--
686-- @since 0.7.0
686-- @since 0.7.0
687{-# INLINE readIndex #-}
687{-# INLINE readIndex #-}
688−readIndex :: Storable a => Handle -> Int -> Maybe a
688+readIndex :: Unboxed a => Handle -> Int -> Maybe a
689readIndex arr i = undefined
689readIndex arr i = undefined
690
690
691-- NOTE: To represent a range to read we have chosen (start, size) instead of
691-- NOTE: To represent a range to read we have chosen (start, size) instead of
@@ -705,7 +705,7 @@ readIndex arr i = undefined
705-- chunk is aligned with @chunkSize@ from second chunk onwards.
705-- chunk is aligned with @chunkSize@ from second chunk onwards.
706--
706--
707{-# INLINE readSliceWith #-}
707{-# INLINE readSliceWith #-}
708−readSliceWith :: (IsStream t, MonadIO m, Storable a)
708+readSliceWith :: (IsStream t, MonadIO m, Unboxed a)
709 => Int -> Handle -> Int -> Int -> t m a
709 => Int -> Handle -> Int -> Int -> t m a
710readSliceWith chunkSize h pos len = undefined
710readSliceWith chunkSize h pos len = undefined
711
711
@@ -715,7 +715,7 @@ readSliceWith chunkSize h pos len = undefined
715--
715--
716-- @since 0.7.0
716-- @since 0.7.0
717{-# INLINE readSlice #-}
717{-# INLINE readSlice #-}
718−readSlice :: (IsStream t, MonadIO m, Storable a)
718+readSlice :: (IsStream t, MonadIO m, Unboxed a)
719 => Handle -> Int -> Int -> t m a
719 => Handle -> Int -> Int -> t m a
720readSlice = readSliceWith A.defaultChunkSize
720readSlice = readSliceWith A.defaultChunkSize
721
721
@@ -725,7 +725,7 @@ readSlice = readSliceWith A.defaultChunkSize
725--
725--
726-- @since 0.7.0
726-- @since 0.7.0
727{-# INLINE readSliceRev #-}
727{-# INLINE readSliceRev #-}
728−readSliceRev :: (IsStream t, MonadIO m, Storable a)
728+readSliceRev :: (IsStream t, MonadIO m, Unboxed a)
729 => Handle -> Int -> Int -> t m a
729 => Handle -> Int -> Int -> t m a
730readSliceRev h i count = undefined
730readSliceRev h i count = undefined
731
731
@@ -733,7 +733,7 @@ readSliceRev h i count = undefined
733--
733--
734-- @since 0.7.0
734-- @since 0.7.0
735{-# INLINE writeIndex #-}
735{-# INLINE writeIndex #-}
736−writeIndex :: (MonadIO m, Storable a) => Handle -> Int -> a -> m ()
736+writeIndex :: (MonadIO m, Unboxed a) => Handle -> Int -> a -> m ()
737writeIndex h i a = undefined
737writeIndex h i a = undefined
738
738
739-- | @writeSlice h i count stream@ writes a stream to the file handle @h@
739-- | @writeSlice h i count stream@ writes a stream to the file handle @h@
@@ -742,7 +742,7 @@ writeIndex h i a = undefined
742--
742--
743-- @since 0.7.0
743-- @since 0.7.0
744{-# INLINE writeSlice #-}
744{-# INLINE writeSlice #-}
745−writeSlice :: (IsStream t, Monad m, Storable a)
745+writeSlice :: (IsStream t, Monad m, Unboxed a)
746 => Handle -> Int -> Int -> t m a -> m ()
746 => Handle -> Int -> Int -> t m a -> m ()
747writeSlice h i len s = undefined
747writeSlice h i len s = undefined
748
748
@@ -752,7 +752,7 @@ writeSlice h i len s = undefined
752--
752--
753-- @since 0.7.0
753-- @since 0.7.0
754{-# INLINE writeSliceRev #-}
754{-# INLINE writeSliceRev #-}
755−writeSliceRev :: (IsStream t, Monad m, Storable a)
755+writeSliceRev :: (IsStream t, Monad m, Unboxed a)
756 => Handle -> Int -> Int -> t m a -> m ()
756 => Handle -> Int -> Int -> t m a -> m ()
757writeSliceRev arr i len s = undefined
757writeSliceRev arr i len s = undefined
758-}
758-}
src/Streamly/Internal/Network/Socket.hs+11−11
@@ -76,7 +76,7 @@ import Control.Monad (forM_, when)
76import Data.Maybe (isNothing, fromJust)
76import Data.Maybe (isNothing, fromJust)
77import Data.Word (Word8)
77import Data.Word (Word8)
78import Foreign.Ptr (plusPtr, Ptr, castPtr)
78import Foreign.Ptr (plusPtr, Ptr, castPtr)
79−import Streamly.Internal.Data.Unboxed (Storable)
79+import Streamly.Internal.Data.Unboxed (Unboxed)
80import Network.Socket
80import Network.Socket
81 (Socket, SocketOption(..), Family(..), SockAddr(..),
81 (Socket, SocketOption(..), Family(..), SockAddr(..),
82 ProtocolNumber, withSocketsDo, SocketType(..), socket, bind,
82 ProtocolNumber, withSocketsDo, SocketType(..), socket, bind,
@@ -303,7 +303,7 @@ sendAll s p len = do
303 when (sent >= 0) $ sendAll s (p `plusPtr` sent) (len - sent)
303 when (sent >= 0) $ sendAll s (p `plusPtr` sent) (len - sent)
304
304
305{-# INLINABLE writeArrayWith #-}
305{-# INLINABLE writeArrayWith #-}
306−writeArrayWith :: Storable a
306+writeArrayWith :: Unboxed a
307 => (h -> Ptr Word8 -> Int -> IO ())
307 => (h -> Ptr Word8 -> Int -> IO ())
308 -> h
308 -> h
309 -> Array a
309 -> Array a
@@ -319,7 +319,7 @@ writeArrayWith f h arr = A.asPtrUnsafe arr $ \ptr -> f h (castPtr ptr) aLen
319--
319--
320-- @since 0.8.0
320-- @since 0.8.0
321{-# INLINABLE writeChunk #-}
321{-# INLINABLE writeChunk #-}
322−writeChunk :: Storable a => Socket -> Array a -> IO ()
322+writeChunk :: Unboxed a => Socket -> Array a -> IO ()
323writeChunk = writeArrayWith sendAll
323writeChunk = writeArrayWith sendAll
324
324
325-------------------------------------------------------------------------------
325-------------------------------------------------------------------------------
@@ -423,7 +423,7 @@ readWith chunkSize h = A.flattenArrays $ readChunksUpto chunkSize h
423-}
423-}
424
424
425-- TODO
425-- TODO
426−-- read :: (IsStream t, MonadIO m, Storable a) => Handle -> t m a
426+-- read :: (IsStream t, MonadIO m, Unboxed a) => Handle -> t m a
427--
427--
428-- > read = 'readByChunks' defaultChunkSize
428-- > read = 'readByChunks' defaultChunkSize
429-- | Generate a stream of elements of the given type from a socket. The
429-- | Generate a stream of elements of the given type from a socket. The
@@ -467,7 +467,7 @@ read = UF.first defaultChunkSize readWith
467--
467--
468-- @since 0.7.0
468-- @since 0.7.0
469{-# INLINE putChunks #-}
469{-# INLINE putChunks #-}
470−putChunks :: (MonadIO m, Storable a)
470+putChunks :: (MonadIO m, Unboxed a)
471 => Socket -> Stream m (Array a) -> m ()
471 => Socket -> Stream m (Array a) -> m ()
472putChunks h = S.mapM_ (liftIO . writeChunk h)
472putChunks h = S.mapM_ (liftIO . writeChunk h)
473
473
@@ -476,7 +476,7 @@ putChunks h = S.mapM_ (liftIO . writeChunk h)
476--
476--
477-- @since 0.7.0
477-- @since 0.7.0
478{-# INLINE writeChunks #-}
478{-# INLINE writeChunks #-}
479−writeChunks :: (MonadIO m, Storable a) => Socket -> Fold m (Array a) ()
479+writeChunks :: (MonadIO m, Unboxed a) => Socket -> Fold m (Array a) ()
480writeChunks h = FL.drainBy (liftIO . writeChunk h)
480writeChunks h = FL.drainBy (liftIO . writeChunk h)
481
481
482-- | @writeChunksWith bufsize socket@ writes a stream of arrays to
482-- | @writeChunksWith bufsize socket@ writes a stream of arrays to
@@ -487,7 +487,7 @@ writeChunks h = FL.drainBy (liftIO . writeChunk h)
487--
487--
488-- @since 0.9.0
488-- @since 0.9.0
489{-# INLINE writeChunksWith #-}
489{-# INLINE writeChunksWith #-}
490−writeChunksWith :: (MonadIO m, Storable a)
490+writeChunksWith :: (MonadIO m, Unboxed a)
491 => Int -> Socket -> Fold m (Array a) ()
491 => Int -> Socket -> Fold m (Array a) ()
492writeChunksWith n h = lpackArraysChunksOf n (writeChunks h)
492writeChunksWith n h = lpackArraysChunksOf n (writeChunks h)
493
493
@@ -496,7 +496,7 @@ writeChunksWith n h = lpackArraysChunksOf n (writeChunks h)
496-- @since 0.7.0
496-- @since 0.7.0
497{-# DEPRECATED writeChunksWithBufferOf "Please use 'writeChunksWith' instead" #-}
497{-# DEPRECATED writeChunksWithBufferOf "Please use 'writeChunksWith' instead" #-}
498{-# INLINE writeChunksWithBufferOf #-}
498{-# INLINE writeChunksWithBufferOf #-}
499−writeChunksWithBufferOf :: (MonadIO m, Storable a)
499+writeChunksWithBufferOf :: (MonadIO m, Unboxed a)
500 => Int -> Socket -> Fold m (Array a) ()
500 => Int -> Socket -> Fold m (Array a) ()
501writeChunksWithBufferOf = writeChunksWith
501writeChunksWithBufferOf = writeChunksWith
502
502
@@ -571,7 +571,7 @@ write = writeWith defaultChunkSize
571
571
572{-
572{-
573{-# INLINE write #-}
573{-# INLINE write #-}
574−write :: (MonadIO m, Storable a) => Handle -> Stream m a -> m ()
574+write :: (MonadIO m, Unboxed a) => Handle -> Stream m a -> m ()
575write = toHandleWith defaultChunkSize
575write = toHandleWith defaultChunkSize
576-}
576-}
577
577
@@ -630,7 +630,7 @@ readLines h f = foldLines (readUtf8 h) f
630--
630--
631-- @since 0.7.0
631-- @since 0.7.0
632{-# INLINE readFrames #-}
632{-# INLINE readFrames #-}
633−readFrames :: (IsStream t, MonadIO m, Storable a)
633+readFrames :: (IsStream t, MonadIO m, Unboxed a)
634 => Array a -> Handle -> Fold m a b -> t m b
634 => Array a -> Handle -> Fold m a b -> t m b
635readFrames = undefined -- foldFrames . read
635readFrames = undefined -- foldFrames . read
636
636
@@ -639,7 +639,7 @@ readFrames = undefined -- foldFrames . read
639--
639--
640-- @since 0.7.0
640-- @since 0.7.0
641{-# INLINE writeByFrames #-}
641{-# INLINE writeByFrames #-}
642−writeByFrames :: (IsStream t, MonadIO m, Storable a)
642+writeByFrames :: (IsStream t, MonadIO m, Unboxed a)
643 => Array a -> Handle -> t m a -> m ()
643 => Array a -> Handle -> t m a -> m ()
644writeByFrames = undefined
644writeByFrames = undefined
645-}
645-}