@@ -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
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.
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)
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
315-- $arrayNotes
315-- $arrayNotes
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
341data Array a =
341data Array a =
342#ifdef DEVBUILD
342#ifdef DEVBUILD
343− Storable a =>
343+ Unboxed a =>
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
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 =
427#ifdef DEVBUILD
427#ifdef DEVBUILD
428− Storable a =>
428+ Unboxed a =>
431nil = Array nilArrayContents 0 0 0
431nil = Array nilArrayContents 0 0 0
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.
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)
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?
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.
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))
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.
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
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 =
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
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 ())
@@ -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.
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.
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
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
@@ -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.
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))
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
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.
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.
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))
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.
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.
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.
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).
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
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) =>
770 -> (Int -> Int)
770 -> (Int -> Int)
@@ -799,7 +799,7 @@ reallocWith label capSizer minIncrBytes arr = do
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
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
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
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
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
@@ -888,7 +888,7 @@ snocUnsafe arr@Array{..} = snocNewEnd (INDEX_NEXT(aEnd,a)) arr
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
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
@@ -921,7 +921,7 @@ snocWithRealloc sizer arr x = do
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
@@ -943,7 +943,7 @@ snocWith allocSize arr x = liftIO $ do
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)
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)
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
@@ -981,7 +981,7 @@ snoc = snocWith f
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.
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.
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 =
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
@@ -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
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
1045-------------------------------------------------------------------------------
1045-------------------------------------------------------------------------------
@@ -1056,7 +1056,7 @@ getIndices = getIndicesD liftIO . Stream.toStreamD
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 _) =
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 _) =
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
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{..} =
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
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.
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)
@@ -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.
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)
@@ -1436,7 +1436,7 @@ toArrayUnsafe (Array contents start end _) = ArrayUnsafe contents start end
1437fromArrayUnsafe ::
1437fromArrayUnsafe ::
1438#ifdef DEVBUILD
1438#ifdef DEVBUILD
1439− Storable a =>
1439+ Unboxed a =>
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) =
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
@@ -1465,19 +1465,19 @@ producerWith liftio = Producer step (return . toArrayUnsafe) extract
1465-- | Resumable unfold of an array.
1465-- | Resumable unfold of an array.
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
1471-- | Unfold an array into a stream.
1471-- | Unfold an array into a stream.
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
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
@@ -1496,7 +1496,7 @@ readRevWith liftio = Unfold step inject
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
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
@@ -1532,7 +1532,7 @@ toListFB c n Array{..} = go arrStart
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
@@ -1543,7 +1543,7 @@ toList Array{..} = liftIO $ go arrStart
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
@@ -1561,12 +1561,12 @@ toStreamDWith liftio Array{..} = D.Stream step arrStart
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
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
@@ -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))
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
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{..} =
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
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))
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
1632-------------------------------------------------------------------------------
1632-------------------------------------------------------------------------------
@@ -1638,12 +1638,12 @@ toStreamKRev = toStreamKRevWith liftIO
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
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
1649-------------------------------------------------------------------------------
1649-------------------------------------------------------------------------------
@@ -1667,7 +1667,7 @@ foldr f z arr = D.foldr f z $ toStreamD arr
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)
1673 -> Fold m a (Array a)
1673 -> Fold m a (Array a)
@@ -1700,7 +1700,7 @@ appendNUnsafe action n =
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)
@@ -1715,7 +1715,7 @@ appendN initial n = FL.take n (appendNUnsafe initial n)
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)
@@ -1729,7 +1729,7 @@ appendWith sizer = FL.foldlM' (snocWith sizer)
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)
@@ -1743,7 +1743,7 @@ append = appendWith (* 2)
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
@@ -1766,7 +1766,7 @@ writeNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
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
@@ -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
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)
@@ -1790,14 +1790,14 @@ writeNWith alloc n = FL.take n (writeNWithUnsafe alloc n)
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
1796-- | Like writeNWithUnsafe but writes the array in reverse order.
1796-- | Like writeNWithUnsafe but writes the array in reverse order.
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
@@ -1818,7 +1818,7 @@ writeRevNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
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)
@@ -1826,7 +1826,7 @@ writeRevNWith alloc n = FL.take n (writeRevNWithUnsafe alloc n)
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
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/
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)
@@ -1856,7 +1856,7 @@ writeNAligned align = writeNWith (newArrayAligned align)
1856-- /Unimplemented/
1856-- /Unimplemented/
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
@@ -1889,7 +1889,7 @@ writeChunks n = FL.many (writeN n) FL.toStreamK
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 =
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)
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)
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
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
1966-- | Like fromListN but writes the array in reverse order.
1966-- | Like fromListN but writes the array in reverse order.
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
1973-------------------------------------------------------------------------------
1973-------------------------------------------------------------------------------
@@ -1975,14 +1975,14 @@ fromListRevN n xs = D.fold (writeRevN n) $ D.fromList xs
1975-------------------------------------------------------------------------------
1975-------------------------------------------------------------------------------
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)
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.
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
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
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.
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
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
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
2023-------------------------------------------------------------------------------
2023-------------------------------------------------------------------------------
@@ -2042,7 +2042,7 @@ putSliceUnsafe src srcStartBytes dst dstStartBytes lenBytes = liftIO $ do
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 =
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
@@ -2118,7 +2118,7 @@ spliceWith sizer dst@(Array _ start end bound) src = do
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 (+)
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 (+)
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))
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.
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{..} =
2209castUnsafe ::
2209castUnsafe ::
2210#ifdef DEVBUILD
2210#ifdef DEVBUILD
2211− Storable b =>
2211+ Unboxed b =>
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
2228-- /Pre-release/
2228-- /Pre-release/
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-------------------------------------------------------------------------------
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
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
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