Merge pull request #1696 from composewell/Rename_Storable_constraint_Unboxed

Rename Storable constraint to Prim
This commit is contained in:
Harendra Kumar 2022-08-06 16:27:43 +05:30 committed by GitHub
commit d2aaef0004
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 287 additions and 291 deletions

View File

@ -48,7 +48,7 @@ import Streamly.Benchmark.Common
import Streamly.Benchmark.Common.Handle
#ifdef INSPECTION
import Streamly.Internal.Data.Unboxed (Storable)
import Streamly.Internal.Data.Unboxed (Unboxed)
import Streamly.Internal.Data.Stream.StreamD.Type (Step(..))
import Test.Inspection
#endif
@ -185,7 +185,7 @@ copyChunksSplitInterposeSuffix inh outh =
$ Handle.getChunks inh
#ifdef INSPECTION
inspect $ hasNoTypeClassesExcept 'copyChunksSplitInterposeSuffix [''Storable]
inspect $ hasNoTypeClassesExcept 'copyChunksSplitInterposeSuffix [''Unboxed]
inspect $ 'copyChunksSplitInterposeSuffix `hasNoType` ''Step
#endif
@ -200,7 +200,7 @@ copyChunksSplitInterpose inh outh =
$ Handle.getChunks inh
#ifdef INSPECTION
inspect $ hasNoTypeClassesExcept 'copyChunksSplitInterpose [''Storable]
inspect $ hasNoTypeClassesExcept 'copyChunksSplitInterpose [''Unboxed]
inspect $ 'copyChunksSplitInterpose `hasNoType` ''Step
#endif

View File

@ -35,7 +35,7 @@ import Streamly.Benchmark.Common
import Streamly.Benchmark.Common.Handle
#ifdef INSPECTION
import Streamly.Internal.Data.Unboxed (Storable)
import Streamly.Internal.Data.Unboxed (Unboxed)
import Streamly.Internal.Data.Stream.StreamD.Type (Step(..))
import qualified Streamly.Internal.Data.Fold.Type as Fold
import qualified Streamly.Internal.Data.Tuple.Strict as Strict
@ -105,7 +105,7 @@ linesUnlinesArrayCharCopy inh outh =
$ Stream.unfold Handle.read inh
#ifdef INSPECTION
inspect $ hasNoTypeClassesExcept 'linesUnlinesArrayCharCopy [''Storable]
inspect $ hasNoTypeClassesExcept 'linesUnlinesArrayCharCopy [''Unboxed]
-- inspect $ 'linesUnlinesArrayCharCopy `hasNoType` ''Step
#endif

View File

@ -60,7 +60,7 @@ import Control.Applicative (liftA2)
import Control.Exception (assert)
import Control.Monad.Catch (MonadThrow)
import Control.Monad.IO.Class (MonadIO(..))
import Streamly.Internal.Data.Unboxed (Storable, peekWith, sizeOf)
import Streamly.Internal.Data.Unboxed (peekWith, sizeOf, Unboxed)
import GHC.Types (SPEC(..))
import Streamly.Internal.Data.Array.Unboxed.Mut.Type (touch)
import Streamly.Internal.Data.Array.Unboxed.Type (Array(..))
@ -97,7 +97,7 @@ newtype ArrayFold m a b = ArrayFold (ParserD.Parser m (Array a) b)
--
-- /Pre-release/
{-# INLINE fromFold #-}
fromFold :: forall m a b. (MonadIO m, Storable a) =>
fromFold :: forall m a b. (MonadIO m, Unboxed a) =>
Fold.Fold m a b -> ArrayFold m a b
fromFold (Fold.Fold fstep finitial fextract) =
ArrayFold (ParserD.Parser step initial fextract)
@ -135,7 +135,7 @@ fromFold (Fold.Fold fstep finitial fextract) =
--
-- /Pre-release/
{-# INLINE fromParserD #-}
fromParserD :: forall m a b. (MonadIO m, Storable a) =>
fromParserD :: forall m a b. (MonadIO m, Unboxed a) =>
ParserD.Parser m a b -> ArrayFold m a b
fromParserD (ParserD.Parser step1 initial1 extract1) =
ArrayFold (ParserD.Parser step initial1 extract1)
@ -177,7 +177,7 @@ fromParserD (ParserD.Parser step1 initial1 extract1) =
--
-- /Pre-release/
{-# INLINE fromParser #-}
fromParser :: forall m a b. (MonadThrow m, MonadIO m, Storable a) =>
fromParser :: forall m a b. (MonadThrow m, MonadIO m, Unboxed a) =>
Parser.Parser m a b -> ArrayFold m a b
fromParser = fromParserD . ParserD.fromParserK
@ -301,7 +301,7 @@ instance MonadThrow m => Monad (ArrayFold m a) where
-- | Take @n@ array elements (@a@) from a stream of arrays (@Array a@).
{-# INLINE take #-}
take :: forall m a b. (Monad m, Storable a) =>
take :: forall m a b. (Monad m, Unboxed a) =>
Int -> ArrayFold m a b -> ArrayFold m a b
take n (ArrayFold (ParserD.Parser step1 initial1 extract1)) =
ArrayFold $ ParserD.Parser step initial extract

View File

@ -31,7 +31,7 @@ import Control.Monad.IO.Class (MonadIO(..))
import Control.Monad (when)
import Control.Monad.Catch (MonadThrow)
import Data.Bifunctor (first)
import Streamly.Internal.Data.Unboxed (Storable, sizeOf)
import Streamly.Internal.Data.Unboxed (Unboxed, sizeOf)
import Streamly.Internal.Data.Array.Unboxed.Mut.Type (Array(..))
import Streamly.Internal.Data.Fold.Type (Fold(..))
import Streamly.Internal.Data.Stream.Type (Stream)
@ -52,7 +52,7 @@ import qualified Streamly.Internal.Data.Stream.Type as Stream
--
-- /Pre-release/
{-# INLINE arraysOf #-}
arraysOf :: (MonadIO m, Storable a)
arraysOf :: (MonadIO m, Unboxed a)
=> Int -> Stream m a -> Stream m (Array a)
arraysOf n = Stream.fromStreamD . MArray.arraysOf n . Stream.toStreamD
@ -81,7 +81,7 @@ data SpliceState s arr
--
-- @since 0.7.0
{-# INLINE_NORMAL packArraysChunksOf #-}
packArraysChunksOf :: (MonadIO m, Storable a)
packArraysChunksOf :: (MonadIO m, Unboxed a)
=> Int -> D.Stream m (Array a) -> D.Stream m (Array a)
packArraysChunksOf n (D.Stream step state) =
D.Stream step' (SpliceInitial state)
@ -129,7 +129,7 @@ packArraysChunksOf n (D.Stream step state) =
-- lpackArraysChunksOf = Fold.many compactLEFold
--
{-# INLINE_NORMAL lpackArraysChunksOf #-}
lpackArraysChunksOf :: (MonadIO m, Storable a)
lpackArraysChunksOf :: (MonadIO m, Unboxed a)
=> Int -> Fold m (Array a) () -> Fold m (Array a) ()
lpackArraysChunksOf n (Fold step1 initial1 extract1) =
Fold step initial extract
@ -191,7 +191,7 @@ lpackArraysChunksOf n (Fold step1 initial1 extract1) =
--
-- /Internal/
{-# INLINE compact #-}
compact :: (MonadIO m, Storable a)
compact :: (MonadIO m, Unboxed a)
=> Int -> Stream m (Array a) -> Stream m (Array a)
compact n = Stream.fromStreamD . packArraysChunksOf n . Stream.toStreamD
@ -204,7 +204,7 @@ compact n = Stream.fromStreamD . packArraysChunksOf n . Stream.toStreamD
-- /Internal/
{-# INLINE_NORMAL compactLEParserD #-}
compactLEParserD ::
forall m a. (MonadThrow m, MonadIO m, Storable a)
forall m a. (MonadThrow m, MonadIO m, Unboxed a)
=> Int -> ParserD.Parser m (Array a) (Array a)
compactLEParserD n = ParserD.Parser step initial extract
@ -254,7 +254,7 @@ compactLEParserD n = ParserD.Parser step initial extract
-- /Internal/
{-# INLINE_NORMAL compactGEFold #-}
compactGEFold ::
forall m a. (MonadIO m, Storable a)
forall m a. (MonadIO m, Unboxed a)
=> Int -> FL.Fold m (Array a) (Array a)
compactGEFold n = Fold step initial extract
@ -298,7 +298,7 @@ compactGEFold n = Fold step initial extract
-- maximum specified size in bytes.
--
-- /Internal/
compactLE :: (MonadThrow m, MonadIO m, Storable a) =>
compactLE :: (MonadThrow m, MonadIO m, Unboxed a) =>
Int -> Stream m (Array a) -> Stream m (Array a)
compactLE n =
Stream.fromStreamD . D.parseMany (compactLEParserD n) . Stream.toStreamD
@ -308,7 +308,7 @@ compactLE n =
--
-- /Unimplemented/
{-# INLINE compactEQ #-}
compactEQ :: -- (MonadIO m, Storable a) =>
compactEQ :: -- (MonadIO m, Unboxed a) =>
Int -> Stream m (Array a) -> Stream m (Array a)
compactEQ _n _xs = undefined
-- IsStream.fromStreamD $ D.foldMany (compactEQFold n) (IsStream.toStreamD xs)
@ -319,7 +319,7 @@ compactEQ _n _xs = undefined
-- /Internal/
{-# INLINE compactGE #-}
compactGE ::
(MonadIO m, Storable a)
(MonadIO m, Unboxed a)
=> Int -> Stream m (Array a) -> Stream m (Array a)
compactGE n =
Stream.fromStreamD . D.foldMany (compactGEFold n) . Stream.toStreamD

View File

@ -116,10 +116,8 @@ import Data.Functor.Identity (Identity)
import Data.Word (Word8)
import Foreign.C.String (CString)
import Foreign.Ptr (castPtr)
import qualified Foreign.Storable as Storable (Storable)
import Streamly.Internal.Data.Unboxed
( Storable
, Unboxed
( Unboxed
, castContents
, peekWith
, sizeOf
@ -136,6 +134,7 @@ import Streamly.Internal.Data.Tuple.Strict (Tuple3Fused'(..))
import Streamly.Internal.Data.Unfold.Type (Unfold(..))
import Streamly.Internal.System.IO (unsafeInlineIO)
import qualified Foreign.Storable as Storable
import qualified Streamly.Internal.Data.Array.Unboxed.Mut.Type as MA
import qualified Streamly.Internal.Data.Array.Unboxed.Mut as MA
import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
@ -158,7 +157,7 @@ import qualified Streamly.Internal.Data.Unfold as Unfold
--
-- /Pre-release/
{-# INLINE fromStreamN #-}
fromStreamN :: (MonadIO m, Storable a) => Int -> Stream m a -> m (Array a)
fromStreamN :: (MonadIO m, Unboxed a) => Int -> Stream m a -> m (Array a)
fromStreamN n m = do
when (n < 0) $ error "writeN: negative write count specified"
A.fromStreamDN n $ Stream.toStreamD m
@ -173,7 +172,7 @@ fromStreamN n m = do
--
-- /Pre-release/
{-# INLINE fromStream #-}
fromStream :: (MonadIO m, Storable a) => Stream m a -> m (Array a)
fromStream :: (MonadIO m, Unboxed a) => Stream m a -> m (Array a)
fromStream m = P.fold A.write $ Stream.toStreamK m
-- write m = A.fromStreamD $ D.fromStreamK m
@ -182,7 +181,7 @@ fromStream m = P.fold A.write $ Stream.toStreamK m
-------------------------------------------------------------------------------
{-# INLINE_NORMAL producer #-}
producer :: forall m a. (Monad m, Storable a) => Producer m (Array a) a
producer :: forall m a. (Monad m, Unboxed a) => Producer m (Array a) a
producer =
Producer.translate A.unsafeThaw A.unsafeFreeze
$ MA.producerWith (return . unsafeInlineIO)
@ -193,7 +192,7 @@ producer =
--
-- @since 0.8.0
{-# INLINE_NORMAL read #-}
read :: forall m a. (Monad m, Storable a) => Unfold m (Array a) a
read :: forall m a. (Monad m, Unboxed a) => Unfold m (Array a) a
read = Producer.simplify producer
-- | Unfold an array into a stream, does not check the end of the array, the
@ -208,7 +207,7 @@ read = Producer.simplify producer
-- /Pre-release/
--
{-# INLINE_NORMAL unsafeRead #-}
unsafeRead :: forall m a. (Monad m, Storable a) => Unfold m (Array a) a
unsafeRead :: forall m a. (Monad m, Unboxed a) => Unfold m (Array a) a
unsafeRead = Unfold step inject
where
@ -243,7 +242,7 @@ null arr = A.byteLength arr == 0
--
-- /Pre-release/
{-# INLINE getIndexRev #-}
getIndexRev :: forall a. Storable a => Int -> Array a -> Maybe a
getIndexRev :: forall a. Unboxed a => Int -> Array a -> Maybe a
getIndexRev i arr =
unsafeInlineIO
$ do
@ -259,7 +258,7 @@ getIndexRev i arr =
--
-- /Pre-release/
{-# INLINE last #-}
last :: Storable a => Array a -> Maybe a
last :: Unboxed a => Array a -> Maybe a
last = getIndexRev 0
-------------------------------------------------------------------------------
@ -352,7 +351,7 @@ find = Unfold.fold Fold.null . Stream.unfold (findIndicesOf p)
-- /Pre-release/
{-# INLINE getSliceUnsafe #-}
getSliceUnsafe ::
forall a. Storable a
forall a. Unboxed a
=> Int -- ^ starting index
-> Int -- ^ length of the slice
-> Array a
@ -368,7 +367,7 @@ getSliceUnsafe index len (Array contents start e) =
--
-- /Pre-release/
{-# INLINE splitOn #-}
splitOn :: (Monad m, Storable a) =>
splitOn :: (Monad m, Unboxed a) =>
(a -> Bool) -> Array a -> Stream m (Array a)
splitOn predicate arr =
Stream.fromStreamD
@ -376,7 +375,7 @@ splitOn predicate arr =
$ D.sliceOnSuffix predicate (A.toStreamD arr)
{-# INLINE genSlicesFromLen #-}
genSlicesFromLen :: forall m a. (Monad m, Storable a)
genSlicesFromLen :: forall m a. (Monad m, Unboxed a)
=> Int -- ^ from index
-> Int -- ^ length of the slice
-> Unfold m (Array a) (Int, Int)
@ -389,7 +388,7 @@ genSlicesFromLen from len =
--
-- /Pre-release//
{-# INLINE getSlicesFromLen #-}
getSlicesFromLen :: forall m a. (Monad m, Storable a)
getSlicesFromLen :: forall m a. (Monad m, Unboxed a)
=> Int -- ^ from index
-> Int -- ^ length of the slice
-> Unfold m (Array a) (Array a)
@ -408,7 +407,7 @@ getSlicesFromLen from len =
--
-- @since 0.8.0
{-# INLINE getIndex #-}
getIndex :: forall a. Storable a => Int -> Array a -> Maybe a
getIndex :: forall a. Unboxed a => Int -> Array a -> Maybe a
getIndex i arr =
unsafeInlineIO
$ do
@ -435,7 +434,7 @@ getIndex i arr =
--
-- /Pre-release/
{-# INLINE getIndices #-}
getIndices :: (Monad m, Storable a) => Stream m Int -> Unfold m (Array a) a
getIndices :: (Monad m, Unboxed a) => Stream m Int -> Unfold m (Array a) a
getIndices m =
let unf = MA.getIndicesD (return . unsafeInlineIO) $ D.fromStreamK $ Stream.toStreamK m
in Unfold.lmap A.unsafeThaw unf
@ -472,7 +471,7 @@ getIndicesFromThenTo = undefined
--
-- @since 0.7.0
{-# INLINE runPipe #-}
runPipe :: (MonadIO m, Storable a, Storable b)
runPipe :: (MonadIO m, Unboxed a, Unboxed b)
=> Pipe m a b -> Array a -> m (Array b)
runPipe f arr = P.runPipe (toArrayMinChunk (length arr)) $ f (A.read arr)
-}
@ -485,7 +484,7 @@ runPipe f arr = P.runPipe (toArrayMinChunk (length arr)) $ f (A.read arr)
--
-- /Pre-release/
{-# INLINE streamTransform #-}
streamTransform :: forall m a b. (MonadIO m, Storable a, Storable b)
streamTransform :: forall m a b. (MonadIO m, Unboxed a, Unboxed b)
=> (Stream m a -> Stream m b) -> Array a -> m (Array b)
streamTransform f arr =
P.fold (A.writeWith (length arr)) $ Stream.toStreamK $ f (A.toStream arr)
@ -503,7 +502,7 @@ streamTransform f arr =
--
castUnsafe ::
#ifdef DEVBUILD
Storable b =>
Unboxed b =>
#endif
Array a -> Array b
castUnsafe (Array contents start end) =
@ -522,7 +521,7 @@ asBytes = castUnsafe
--
-- @since 0.8.0
--
cast :: forall a b. (Storable b) => Array a -> Maybe (Array b)
cast :: forall a b. (Unboxed b) => Array a -> Maybe (Array b)
cast arr =
let len = A.byteLength arr
r = len `mod` SIZE_OF(b)
@ -552,12 +551,12 @@ asCStringUnsafe arr act = do
--
-- /Pre-release/
{-# INLINE fold #-}
fold :: forall m a b. (Monad m, Storable a) => Fold m a b -> Array a -> m b
fold :: forall m a b. (Monad m, Unboxed a) => Fold m a b -> Array a -> m b
fold f arr = P.fold f (Stream.toStreamK (A.toStream arr))
-- | Fold an array using a stream fold operation.
--
-- /Pre-release/
{-# INLINE streamFold #-}
streamFold :: (Monad m, Storable a) => (Stream m a -> m b) -> Array a -> m b
streamFold :: (Monad m, Unboxed a) => (Stream m a -> m b) -> Array a -> m b
streamFold f arr = f (A.toStream arr)

View File

@ -8,7 +8,7 @@
-- Stability : experimental
-- Portability : GHC
--
-- Unboxed pinned mutable array type for 'Storable' types with an option to use
-- Unboxed pinned mutable array type for 'Unboxed' types with an option to use
-- foreign (non-GHC) memory allocators. Fulfils the following goals:
--
-- * Random access (array)
@ -33,7 +33,7 @@ module Streamly.Internal.Data.Array.Unboxed.Mut
where
import Control.Monad.IO.Class (MonadIO(..))
import Streamly.Internal.Data.Unboxed (Storable)
import Streamly.Internal.Data.Unboxed (Unboxed)
import Streamly.Internal.Data.Stream (Stream)
import Streamly.Internal.Data.Unfold.Type (Unfold(..))
@ -50,7 +50,7 @@ import Streamly.Internal.Data.Array.Unboxed.Mut.Type
--
-- /Pre-release/
{-# INLINE splitOn #-}
splitOn :: (MonadIO m, Storable a) =>
splitOn :: (MonadIO m, Unboxed a) =>
(a -> Bool) -> Array a -> Stream m (Array a)
splitOn predicate arr =
Stream.fromStreamD
@ -63,7 +63,7 @@ splitOn predicate arr =
--
-- /Pre-release/
{-# INLINE genSlicesFromLen #-}
genSlicesFromLen :: forall m a. (Monad m, Storable a)
genSlicesFromLen :: forall m a. (Monad m, Unboxed a)
=> Int -- ^ from index
-> Int -- ^ length of the slice
-> Unfold m (Array a) (Int, Int)
@ -80,7 +80,7 @@ genSlicesFromLen from len =
--
-- /Pre-release/
{-# INLINE getSlicesFromLen #-}
getSlicesFromLen :: forall m a. (Monad m, Storable a)
getSlicesFromLen :: forall m a. (Monad m, Unboxed a)
=> Int -- ^ from index
-> Int -- ^ length of the slice
-> Unfold m (Array a) (Array a)
@ -98,6 +98,6 @@ getSlicesFromLen from len =
--
-- /Pre-release/
{-# INLINE fromStream #-}
fromStream :: (MonadIO m, Storable a) => Stream m a -> m (Array a)
fromStream :: (MonadIO m, Unboxed a) => Stream m a -> m (Array a)
fromStream = fromStreamD . Stream.toStreamD
-- fromStream (Stream m) = P.fold write m

View File

@ -228,7 +228,7 @@ import Foreign.Ptr (plusPtr, minusPtr, nullPtr)
import Streamly.Internal.Control.Exception (assertM)
import Streamly.Internal.Data.Unboxed
( ArrayContents(..)
, Storable
, Unboxed
, alignment
, castContents
, getMutableByteArray#
@ -289,11 +289,11 @@ foreign import ccall unsafe "string.h memchr" c_memchr
foreign import ccall unsafe "string.h memcmp" c_memcmp
:: Ptr Word8 -> Ptr Word8 -> CSize -> IO CInt
-- | Given a 'Storable' type (unused first arg) and a number of bytes, return
-- | Given an 'Unboxed' type (unused first arg) and a number of bytes, return
-- how many elements of that type will completely fit in those bytes.
--
{-# INLINE bytesToElemCount #-}
bytesToElemCount :: forall a. Storable a => a -> Int -> Int
bytesToElemCount :: forall a. Unboxed a => a -> Int -> Int
bytesToElemCount _ n = n `div` SIZE_OF(a)
-- XXX we are converting Int to CSize
@ -314,7 +314,7 @@ memcmp p1 p2 len = do
-- $arrayNotes
--
-- We can use a 'Storable' constraint in the Array type and the constraint can
-- We can use an 'Unboxed' constraint in the Array type and the constraint can
-- be automatically provided to a function that pattern matches on the Array
-- type. However, it has huge performance cost, so we do not use it.
-- Investigate a GHC improvement possiblity.
@ -340,7 +340,7 @@ memcmp p1 p2 len = do
--
data Array a =
#ifdef DEVBUILD
Storable a =>
Unboxed a =>
#endif
-- The array is a range into arrContents. arrContents may be a superset of
-- the slice represented by the array. All offsets are in bytes.
@ -394,7 +394,7 @@ unpin arr@(Array{..}) = do
--
-- /Pre-release/
{-# INLINE newArrayWith #-}
newArrayWith :: forall m a. (MonadIO m, Storable a)
newArrayWith :: forall m a. (MonadIO m, Unboxed a)
=> (Int -> Int -> m (ArrayContents a)) -> Int -> Int -> m (Array a)
newArrayWith alloc alignSize count = do
let size = max (count * SIZE_OF(a)) 0
@ -425,17 +425,17 @@ nilArrayContents =
nil ::
#ifdef DEVBUILD
Storable a =>
Unboxed a =>
#endif
Array a
nil = Array nilArrayContents 0 0 0
-- | Like 'newArrayWith' but using an allocator that aligns the memory to the
-- alignment dictated by the 'Storable' instance of the type.
-- alignment dictated by the 'Unboxed' instance of the type.
--
-- /Internal/
{-# INLINE newArrayAligned #-}
newArrayAligned :: (MonadIO m, Storable a) => Int -> Int -> m (Array a)
newArrayAligned :: (MonadIO m, Unboxed a) => Int -> Int -> m (Array a)
newArrayAligned = newArrayWith (\s a -> liftIO $ newAlignedArrayContents s a)
-- XXX Intead of newArray, make newPinnedArray and newUnpinnedArray. Make it
@ -443,21 +443,21 @@ newArrayAligned = newArrayWith (\s a -> liftIO $ newAlignedArrayContents s a)
-- XXX can unaligned allocation be more efficient when alignment is not needed?
--
-- | Allocates an empty array that can hold 'count' items. The memory of the
-- array is uninitialized and the allocation is aligned as per the 'Storable'
-- array is uninitialized and the allocation is aligned as per the 'Unboxed'
-- instance of the type.
--
-- /Pre-release/
{-# INLINE newArray #-}
newArray :: forall m a. (MonadIO m, Storable a) => Int -> m (Array a)
newArray :: forall m a. (MonadIO m, Unboxed a) => Int -> m (Array a)
newArray = newArrayAligned (alignment (undefined :: a))
-- | Allocates a pinned empty array that can hold 'count' items. The memory of
-- the array is uninitialized and the allocation is aligned as per the
-- 'Storable' instance of the type.
-- 'Unboxed' instance of the type.
--
-- /Pre-release/
{-# INLINE newPinnedArrayBytes #-}
newPinnedArrayBytes :: forall m a. (MonadIO m, Storable a) => Int -> m (Array a)
newPinnedArrayBytes :: forall m a. (MonadIO m, Unboxed a) => Int -> m (Array a)
newPinnedArrayBytes bytes = do
contents <-
liftIO $ newAlignedArrayContents bytes (alignment (undefined :: a))
@ -474,7 +474,7 @@ newPinnedArrayBytes bytes = do
-- /Internal/
{-# INLINE withNewArrayUnsafe #-}
withNewArrayUnsafe ::
(MonadIO m, Storable a) => Int -> (Ptr a -> m ()) -> m (Array a)
(MonadIO m, Unboxed a) => Int -> (Ptr a -> m ()) -> m (Array a)
withNewArrayUnsafe count f = do
arr <- newArray count
asPtrUnsafe arr
@ -489,7 +489,7 @@ withNewArrayUnsafe count f = do
--
-- /Pre-release/
{-# INLINE putIndexUnsafe #-}
putIndexUnsafe :: forall m a. (MonadIO m, Storable a)
putIndexUnsafe :: forall m a. (MonadIO m, Unboxed a)
=> Int -> a -> Array a -> m ()
putIndexUnsafe i x (Array {..}) = do
let index = INDEX_OF(arrStart, i, a)
@ -509,7 +509,7 @@ invalidIndex label i =
--
-- /Pre-release/
{-# INLINE putIndex #-}
putIndex :: forall m a. (MonadIO m, Storable a) => Int -> a -> Array a -> m ()
putIndex :: forall m a. (MonadIO m, Unboxed a) => Int -> a -> Array a -> m ()
putIndex i x Array{..} = do
let index = INDEX_OF(arrStart,i,a)
if i >= 0 && INDEX_VALID(index,aEnd,a)
@ -521,7 +521,7 @@ putIndex i x Array{..} = do
--
-- /Pre-release/
{-# INLINE putIndices #-}
putIndices :: forall m a. (MonadIO m, Storable a)
putIndices :: forall m a. (MonadIO m, Unboxed a)
=> Array a -> Fold m (Int, a) ()
putIndices arr = FL.foldlM' step (return ())
@ -532,7 +532,7 @@ putIndices arr = FL.foldlM' step (return ())
-- | Modify a given index of an array using a modifier function.
--
-- /Pre-release/
modifyIndexUnsafe :: forall m a b. (MonadIO m, Storable a) =>
modifyIndexUnsafe :: forall m a b. (MonadIO m, Unboxed a) =>
Int -> (a -> (a, b)) -> Array a -> m b
modifyIndexUnsafe i f (Array{..}) = liftIO $ do
let index = INDEX_OF(arrStart,i,a)
@ -545,7 +545,7 @@ modifyIndexUnsafe i f (Array{..}) = liftIO $ do
-- | Modify a given index of an array using a modifier function.
--
-- /Pre-release/
modifyIndex :: forall m a b. (MonadIO m, Storable a) =>
modifyIndex :: forall m a b. (MonadIO m, Unboxed a) =>
Int -> (a -> (a, b)) -> Array a -> m b
modifyIndex i f Array{..} = do
let index = INDEX_OF(arrStart,i,a)
@ -562,7 +562,7 @@ modifyIndex i f Array{..} = do
--
-- /Pre-release/
{-# INLINE modifyIndices #-}
modifyIndices :: forall m a . (MonadIO m, Storable a)
modifyIndices :: forall m a . (MonadIO m, Unboxed a)
=> (Int -> a -> a) -> Array a -> Fold m Int ()
modifyIndices f arr = FL.foldlM' step initial
@ -577,7 +577,7 @@ modifyIndices f arr = FL.foldlM' step initial
-- | Modify each element of an array using the supplied modifier function.
--
-- /Pre-release/
modify :: forall m a. (MonadIO m, Storable a)
modify :: forall m a. (MonadIO m, Unboxed a)
=> (a -> a) -> Array a -> m ()
modify f Array{..} = liftIO $
go arrStart
@ -591,7 +591,7 @@ modify f Array{..} = liftIO $
go (INDEX_NEXT(i,a))
{-# INLINE swapArrayByteIndices #-}
swapArrayByteIndices :: Storable a => ArrayContents a -> Int -> Int -> IO ()
swapArrayByteIndices :: Unboxed a => ArrayContents a -> Int -> Int -> IO ()
swapArrayByteIndices arrContents i1 i2 = do
r1 <- peekWith arrContents i1
r2 <- peekWith arrContents i2
@ -604,7 +604,7 @@ swapArrayByteIndices arrContents i1 i2 = do
--
-- /Pre-release/
{-# INLINE unsafeSwapIndices #-}
unsafeSwapIndices :: forall m a. (MonadIO m, Storable a)
unsafeSwapIndices :: forall m a. (MonadIO m, Unboxed a)
=> Int -> Int -> Array a -> m ()
unsafeSwapIndices i1 i2 Array{..} = liftIO $ do
let t1 = INDEX_OF(arrStart,i1,a)
@ -614,7 +614,7 @@ unsafeSwapIndices i1 i2 Array{..} = liftIO $ do
-- | Swap the elements at two indices.
--
-- /Pre-release/
swapIndices :: forall m a. (MonadIO m, Storable a)
swapIndices :: forall m a. (MonadIO m, Unboxed a)
=> Int -> Int -> Array a -> m ()
swapIndices i1 i2 Array{..} = liftIO $ do
let t1 = INDEX_OF(arrStart,i1,a)
@ -685,15 +685,15 @@ roundUpToPower2 n =
-- case it returns one element's size.
--
{-# INLINE allocBytesToBytes #-}
allocBytesToBytes :: forall a. Storable a => a -> Int -> Int
allocBytesToBytes :: forall a. Unboxed a => a -> Int -> Int
allocBytesToBytes _ n = max (arrayPayloadSize n) (SIZE_OF(a))
-- | Given a 'Storable' type (unused first arg) and real allocation size
-- | Given an 'Unboxed' type (unused first arg) and real allocation size
-- (including overhead), return how many elements of that type will completely
-- fit in it, returns at least 1.
--
{-# INLINE allocBytesToElemCount #-}
allocBytesToElemCount :: Storable a => a -> Int -> Int
allocBytesToElemCount :: Unboxed a => a -> Int -> Int
allocBytesToElemCount x bytes =
let n = bytesToElemCount x (allocBytesToBytes x bytes)
in assert (n >= 1) n
@ -715,8 +715,8 @@ roundDownTo elemSize size = size - (size `mod` elemSize)
-- XXX See if resizing can be implemented by reading the old array as a stream
-- and then using writeN to the new array.
--
-- NOTE: we are passing elemSize explicitly to avoid a Storable constraint.
-- Since this is not inlined Storable consrraint leads to dictionary passing
-- NOTE: we are passing elemSize explicitly to avoid an Unboxed constraint.
-- Since this is not inlined Unboxed consrraint leads to dictionary passing
-- which complicates some inspection tests.
--
{-# NOINLINE reallocAligned #-}
@ -758,14 +758,14 @@ reallocAligned elemSize alignSize newCapacityInBytes Array{..} = do
-- 'largeObjectThreshold' then it is rounded up to the block size (4K).
--
{-# INLINABLE realloc #-}
realloc :: forall m a. (MonadIO m, Storable a) => Int -> Array a -> m (Array a)
realloc :: forall m a. (MonadIO m, Unboxed a) => Int -> Array a -> m (Array a)
realloc bytes arr =
liftIO $ reallocAligned (SIZE_OF(a)) (alignment (undefined :: a)) bytes arr
-- | @reallocWith label capSizer minIncrBytes array@. The label is used
-- in error messages and the capSizer is used to determine the capacity of the
-- new array in bytes given the current byte length of the array.
reallocWith :: forall m a. (MonadIO m , Storable a) =>
reallocWith :: forall m a. (MonadIO m , Unboxed a) =>
String
-> (Int -> Int)
-> Int
@ -799,7 +799,7 @@ reallocWith label capSizer minIncrBytes arr = do
--
-- /Pre-release/
{-# INLINE resize #-}
resize :: forall m a. (MonadIO m, Storable a) =>
resize :: forall m a. (MonadIO m, Unboxed a) =>
Int -> Array a -> m (Array a)
resize nElems arr@Array{..} = do
let req = SIZE_OF(a) * nElems
@ -813,7 +813,7 @@ resize nElems arr@Array{..} = do
--
-- /Pre-release/
{-# INLINE resizeExp #-}
resizeExp :: forall m a. (MonadIO m, Storable a) =>
resizeExp :: forall m a. (MonadIO m, Unboxed a) =>
Int -> Array a -> m (Array a)
resizeExp nElems arr@Array{..} = do
let req = roundUpLargeArray (SIZE_OF(a) * nElems)
@ -835,7 +835,7 @@ resizeExp nElems arr@Array{..} = do
--
-- /Pre-release/
{-# INLINE rightSize #-}
rightSize :: forall m a. (MonadIO m, Storable a) => Array a -> m (Array a)
rightSize :: forall m a. (MonadIO m, Unboxed a) => Array a -> m (Array a)
rightSize arr@Array{..} = do
assert (aEnd <= aBound) (return ())
let start = arrStart
@ -867,7 +867,7 @@ rightSize arr@Array{..} = do
--
-- /Internal/
{-# INLINE snocNewEnd #-}
snocNewEnd :: (MonadIO m, Storable a) => Int -> Array a -> a -> m (Array a)
snocNewEnd :: (MonadIO m, Unboxed a) => Int -> Array a -> a -> m (Array a)
snocNewEnd newEnd arr@Array{..} x = liftIO $ do
assert (newEnd <= aBound) (return ())
pokeWith arrContents aEnd x
@ -879,7 +879,7 @@ snocNewEnd newEnd arr@Array{..} x = liftIO $ do
--
-- /Internal/
{-# INLINE snocUnsafe #-}
snocUnsafe :: forall m a. (MonadIO m, Storable a) =>
snocUnsafe :: forall m a. (MonadIO m, Unboxed a) =>
Array a -> a -> m (Array a)
snocUnsafe arr@Array{..} = snocNewEnd (INDEX_NEXT(aEnd,a)) arr
@ -888,7 +888,7 @@ snocUnsafe arr@Array{..} = snocNewEnd (INDEX_NEXT(aEnd,a)) arr
--
-- /Internal/
{-# INLINE snocMay #-}
snocMay :: forall m a. (MonadIO m, Storable a) =>
snocMay :: forall m a. (MonadIO m, Unboxed a) =>
Array a -> a -> m (Maybe (Array a))
snocMay arr@Array{..} x = liftIO $ do
let newEnd = INDEX_NEXT(aEnd,a)
@ -898,7 +898,7 @@ snocMay arr@Array{..} x = liftIO $ do
-- NOINLINE to move it out of the way and not pollute the instruction cache.
{-# NOINLINE snocWithRealloc #-}
snocWithRealloc :: forall m a. (MonadIO m, Storable a) =>
snocWithRealloc :: forall m a. (MonadIO m, Unboxed a) =>
(Int -> Int)
-> Array a
-> a
@ -921,7 +921,7 @@ snocWithRealloc sizer arr x = do
--
-- /Pre-release/
{-# INLINE snocWith #-}
snocWith :: forall m a. (MonadIO m, Storable a) =>
snocWith :: forall m a. (MonadIO m, Unboxed a) =>
(Int -> Int)
-> Array a
-> a
@ -943,7 +943,7 @@ snocWith allocSize arr x = liftIO $ do
--
-- /Pre-release/
{-# INLINE snocLinear #-}
snocLinear :: forall m a. (MonadIO m, Storable a) => Array a -> a -> m (Array a)
snocLinear :: forall m a. (MonadIO m, Unboxed a) => Array a -> a -> m (Array a)
snocLinear = snocWith (+ allocBytesToBytes (undefined :: a) arrayChunkBytes)
-- | 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)
--
-- /Pre-release/
{-# INLINE snoc #-}
snoc :: forall m a. (MonadIO m, Storable a) => Array a -> a -> m (Array a)
snoc :: forall m a. (MonadIO m, Unboxed a) => Array a -> a -> m (Array a)
snoc = snocWith f
where
@ -981,7 +981,7 @@ snoc = snocWith f
--
-- Unsafe because it does not check the bounds of the array.
{-# INLINE_NORMAL getIndexUnsafe #-}
getIndexUnsafe :: forall m a. (MonadIO m, Storable a) => Int -> Array a -> m a
getIndexUnsafe :: forall m a. (MonadIO m, Unboxed a) => Int -> Array a -> m a
getIndexUnsafe i (Array {..}) = do
let index = INDEX_OF(arrStart,i,a)
assert (i >= 0 && INDEX_VALID(index,aEnd,a)) (return ())
@ -990,7 +990,7 @@ getIndexUnsafe i (Array {..}) = do
-- | /O(1)/ Lookup the element at the given index. Index starts from 0.
--
{-# INLINE getIndex #-}
getIndex :: forall m a. (MonadIO m, Storable a) => Int -> Array a -> m a
getIndex :: forall m a. (MonadIO m, Unboxed a) => Int -> Array a -> m a
getIndex i Array{..} = do
let index = INDEX_OF(arrStart,i,a)
if i >= 0 && INDEX_VALID(index,aEnd,a)
@ -1003,7 +1003,7 @@ getIndex i Array{..} = do
-- Slightly faster than computing the forward index and using getIndex.
--
{-# INLINE getIndexRev #-}
getIndexRev :: forall m a. (MonadIO m, Storable a) => Int -> Array a -> m a
getIndexRev :: forall m a. (MonadIO m, Unboxed a) => Int -> Array a -> m a
getIndexRev i Array{..} = do
let index = RINDEX_OF(aEnd,i,a)
if i >= 0 && index >= arrStart
@ -1019,7 +1019,7 @@ data GetIndicesState contents start end st =
--
-- /Pre-release/
{-# INLINE getIndicesD #-}
getIndicesD :: (Monad m, Storable a) =>
getIndicesD :: (Monad m, Unboxed a) =>
(forall b. IO b -> m b) -> D.Stream m Int -> Unfold m (Array a) a
getIndicesD liftio (D.Stream stepi sti) = Unfold step inject
@ -1039,7 +1039,7 @@ getIndicesD liftio (D.Stream stepi sti) = Unfold step inject
D.Stop -> return D.Stop
{-# INLINE getIndices #-}
getIndices :: (MonadIO m, Storable a) => Stream m Int -> Unfold m (Array a) a
getIndices :: (MonadIO m, Unboxed a) => Stream m Int -> Unfold m (Array a) a
getIndices = getIndicesD liftIO . Stream.toStreamD
-------------------------------------------------------------------------------
@ -1056,7 +1056,7 @@ getIndices = getIndicesD liftIO . Stream.toStreamD
--
-- /Pre-release/
{-# INLINE getSliceUnsafe #-}
getSliceUnsafe :: forall a. Storable a
getSliceUnsafe :: forall a. Unboxed a
=> Int -- ^ from index
-> Int -- ^ length of the slice
-> Array a
@ -1075,7 +1075,7 @@ getSliceUnsafe index len (Array contents start e _) =
--
-- /Pre-release/
{-# INLINE getSlice #-}
getSlice :: forall a. Storable a =>
getSlice :: forall a. Unboxed a =>
Int -- ^ from index
-> Int -- ^ length of the slice
-> Array a
@ -1104,7 +1104,7 @@ getSlice index len (Array contents start e _) =
--
-- /Pre-release/
{-# INLINE reverse #-}
reverse :: forall m a. (MonadIO m, Storable a) => Array a -> m ()
reverse :: forall m a. (MonadIO m, Unboxed a) => Array a -> m ()
reverse Array{..} = liftIO $ do
let l = arrStart
h = INDEX_PREV(aEnd,a)
@ -1131,7 +1131,7 @@ permute = undefined
--
-- /Pre-release/
{-# INLINE partitionBy #-}
partitionBy :: forall m a. (MonadIO m, Storable a)
partitionBy :: forall m a. (MonadIO m, Unboxed a)
=> (a -> Bool) -> Array a -> m (Array a, Array a)
partitionBy f arr@Array{..} = liftIO $ do
if arrStart >= aEnd
@ -1255,7 +1255,7 @@ byteLength Array{..} =
--
-- @since 0.7.0
{-# INLINE length #-}
length :: forall a. Storable a => Array a -> Int
length :: forall a. Unboxed a => Array a -> Int
length arr =
let elemSize = SIZE_OF(a)
blen = byteLength arr
@ -1299,7 +1299,7 @@ data GroupState s contents start end bound
--
-- /Pre-release/
{-# INLINE_NORMAL arraysOf #-}
arraysOf :: forall m a. (MonadIO m, Storable a)
arraysOf :: forall m a. (MonadIO m, Unboxed a)
=> Int -> D.Stream m a -> D.Stream m (Array a)
-- XXX the idiomatic implementation leads to large regression in the D.reverse'
-- benchmark. It seems it has difficulty producing optimized code when
@ -1346,7 +1346,7 @@ arraysOf n (D.Stream step state) =
-- XXX buffer to a list instead?
-- | Buffer the stream into arrays in memory.
{-# INLINE arrayStreamKFromStreamD #-}
arrayStreamKFromStreamD :: forall m a. (MonadIO m, Storable a) =>
arrayStreamKFromStreamD :: forall m a. (MonadIO m, Unboxed a) =>
D.Stream m a -> m (K.Stream m (Array a))
arrayStreamKFromStreamD =
let n = allocBytesToElemCount (undefined :: a) defaultChunkSize
@ -1367,7 +1367,7 @@ data FlattenState s contents a =
-- We can try this if there are any fusion issues in the unfold.
--
{-# INLINE_NORMAL flattenArrays #-}
flattenArrays :: forall m a. (MonadIO m, Storable a)
flattenArrays :: forall m a. (MonadIO m, Unboxed a)
=> D.Stream m (Array a) -> D.Stream m a
flattenArrays (D.Stream step state) = D.Stream step' (OuterLoop state)
@ -1396,7 +1396,7 @@ flattenArrays (D.Stream step state) = D.Stream step' (OuterLoop state)
-- We can try this if there are any fusion issues in the unfold.
--
{-# INLINE_NORMAL flattenArraysRev #-}
flattenArraysRev :: forall m a. (MonadIO m, Storable a)
flattenArraysRev :: forall m a. (MonadIO m, Unboxed a)
=> D.Stream m (Array a) -> D.Stream m a
flattenArraysRev (D.Stream step state) = D.Stream step' (OuterLoop state)
@ -1436,7 +1436,7 @@ toArrayUnsafe (Array contents start end _) = ArrayUnsafe contents start end
fromArrayUnsafe ::
#ifdef DEVBUILD
Storable a =>
Unboxed a =>
#endif
ArrayUnsafe a -> Array a
fromArrayUnsafe (ArrayUnsafe contents start end) =
@ -1444,7 +1444,7 @@ fromArrayUnsafe (ArrayUnsafe contents start end) =
{-# INLINE_NORMAL producerWith #-}
producerWith ::
forall m a. (Monad m, Storable a)
forall m a. (Monad m, Unboxed a)
=> (forall b. IO b -> m b) -> Producer m (Array a) a
producerWith liftio = Producer step (return . toArrayUnsafe) extract
where
@ -1465,19 +1465,19 @@ producerWith liftio = Producer step (return . toArrayUnsafe) extract
-- | Resumable unfold of an array.
--
{-# INLINE_NORMAL producer #-}
producer :: forall m a. (MonadIO m, Storable a) => Producer m (Array a) a
producer :: forall m a. (MonadIO m, Unboxed a) => Producer m (Array a) a
producer = producerWith liftIO
-- | Unfold an array into a stream.
--
-- @since 0.7.0
{-# INLINE_NORMAL read #-}
read :: forall m a. (MonadIO m, Storable a) => Unfold m (Array a) a
read :: forall m a. (MonadIO m, Unboxed a) => Unfold m (Array a) a
read = Producer.simplify producer
{-# INLINE_NORMAL readRevWith #-}
readRevWith ::
forall m a. (Monad m, Storable a)
forall m a. (Monad m, Unboxed a)
=> (forall b. IO b -> m b) -> Unfold m (Array a) a
readRevWith liftio = Unfold step inject
where
@ -1496,7 +1496,7 @@ readRevWith liftio = Unfold step inject
--
-- /Pre-release/
{-# INLINE_NORMAL readRev #-}
readRev :: forall m a. (MonadIO m, Storable a) => Unfold m (Array a) a
readRev :: forall m a. (MonadIO m, Unboxed a) => Unfold m (Array a) a
readRev = readRevWith liftIO
-------------------------------------------------------------------------------
@ -1507,7 +1507,7 @@ readRev = readRevWith liftIO
-- Use foldr/build fusion to fuse with list consumers
-- This can be useful when using the IsList instance
{-# INLINE_LATE toListFB #-}
toListFB :: forall a b. Storable a => (a -> b -> b) -> b -> Array a -> b
toListFB :: forall a b. Unboxed a => (a -> b -> b) -> b -> Array a -> b
toListFB c n Array{..} = go arrStart
where
@ -1532,7 +1532,7 @@ toListFB c n Array{..} = go arrStart
--
-- @since 0.7.0
{-# INLINE toList #-}
toList :: forall m a. (MonadIO m, Storable a) => Array a -> m [a]
toList :: forall m a. (MonadIO m, Unboxed a) => Array a -> m [a]
toList Array{..} = liftIO $ go arrStart
where
@ -1543,7 +1543,7 @@ toList Array{..} = liftIO $ go arrStart
{-# INLINE_NORMAL toStreamDWith #-}
toStreamDWith ::
forall m a. (Monad m, Storable a)
forall m a. (Monad m, Unboxed a)
=> (forall b. IO b -> m b) -> Array a -> D.Stream m a
toStreamDWith liftio Array{..} = D.Stream step arrStart
@ -1561,12 +1561,12 @@ toStreamDWith liftio Array{..} = D.Stream step arrStart
--
-- We can try this if the unfold has any performance issues.
{-# INLINE_NORMAL toStreamD #-}
toStreamD :: forall m a. (MonadIO m, Storable a) => Array a -> D.Stream m a
toStreamD :: forall m a. (MonadIO m, Unboxed a) => Array a -> D.Stream m a
toStreamD = toStreamDWith liftIO
{-# INLINE toStreamKWith #-}
toStreamKWith ::
forall m a. (Monad m, Storable a)
forall m a. (Monad m, Unboxed a)
=> (forall b. IO b -> m b) -> Array a -> K.Stream m a
toStreamKWith liftio Array{..} = go arrStart
@ -1580,12 +1580,12 @@ toStreamKWith liftio Array{..} = go arrStart
in liftio elemM `K.consM` go (INDEX_NEXT(p,a))
{-# INLINE toStreamK #-}
toStreamK :: forall m a. (MonadIO m, Storable a) => Array a -> K.Stream m a
toStreamK :: forall m a. (MonadIO m, Unboxed a) => Array a -> K.Stream m a
toStreamK = toStreamKWith liftIO
{-# INLINE_NORMAL toStreamDRevWith #-}
toStreamDRevWith ::
forall m a. (Monad m, Storable a)
forall m a. (Monad m, Unboxed a)
=> (forall b. IO b -> m b) -> Array a -> D.Stream m a
toStreamDRevWith liftio Array{..} =
let p = INDEX_PREV(aEnd,a)
@ -1605,12 +1605,12 @@ toStreamDRevWith liftio Array{..} =
--
-- We can try this if the unfold has any perf issues.
{-# INLINE_NORMAL toStreamDRev #-}
toStreamDRev :: forall m a. (MonadIO m, Storable a) => Array a -> D.Stream m a
toStreamDRev :: forall m a. (MonadIO m, Unboxed a) => Array a -> D.Stream m a
toStreamDRev = toStreamDRevWith liftIO
{-# INLINE toStreamKRevWith #-}
toStreamKRevWith ::
forall m a. (Monad m, Storable a)
forall m a. (Monad m, Unboxed a)
=> (forall b. IO b -> m b) -> Array a -> K.Stream m a
toStreamKRevWith liftio Array {..} =
let p = INDEX_PREV(aEnd,a)
@ -1626,7 +1626,7 @@ toStreamKRevWith liftio Array {..} =
in liftio elemM `K.consM` go (INDEX_PREV(p,a))
{-# INLINE toStreamKRev #-}
toStreamKRev :: forall m a. (MonadIO m, Storable a) => Array a -> K.Stream m a
toStreamKRev :: forall m a. (MonadIO m, Unboxed a) => Array a -> K.Stream m a
toStreamKRev = toStreamKRevWith liftIO
-------------------------------------------------------------------------------
@ -1638,12 +1638,12 @@ toStreamKRev = toStreamKRevWith liftIO
--
-- | Strict left fold of an array.
{-# INLINE_NORMAL foldl' #-}
foldl' :: (MonadIO m, Storable a) => (b -> a -> b) -> b -> Array a -> m b
foldl' :: (MonadIO m, Unboxed a) => (b -> a -> b) -> b -> Array a -> m b
foldl' f z arr = D.foldl' f z $ toStreamD arr
-- | Right fold of an array.
{-# INLINE_NORMAL foldr #-}
foldr :: (MonadIO m, Storable a) => (a -> b -> b) -> b -> Array a -> m b
foldr :: (MonadIO m, Unboxed a) => (a -> b -> b) -> b -> Array a -> m b
foldr f z arr = D.foldr f z $ toStreamD arr
-------------------------------------------------------------------------------
@ -1667,7 +1667,7 @@ foldr f z arr = D.foldr f z $ toStreamD arr
--
-- /Internal/
{-# INLINE_NORMAL appendNUnsafe #-}
appendNUnsafe :: forall m a. (MonadIO m, Storable a) =>
appendNUnsafe :: forall m a. (MonadIO m, Unboxed a) =>
m (Array a)
-> Int
-> Fold m a (Array a)
@ -1700,7 +1700,7 @@ appendNUnsafe action n =
--
-- /Pre-release/
{-# INLINE_NORMAL appendN #-}
appendN :: forall m a. (MonadIO m, Storable a) =>
appendN :: forall m a. (MonadIO m, Unboxed a) =>
m (Array a) -> Int -> Fold m a (Array a)
appendN initial n = FL.take n (appendNUnsafe initial n)
@ -1715,7 +1715,7 @@ appendN initial n = FL.take n (appendNUnsafe initial n)
--
-- /Pre-release/
{-# INLINE appendWith #-}
appendWith :: forall m a. (MonadIO m, Storable a) =>
appendWith :: forall m a. (MonadIO m, Unboxed a) =>
(Int -> Int) -> m (Array a) -> Fold m a (Array a)
appendWith sizer = FL.foldlM' (snocWith sizer)
@ -1729,7 +1729,7 @@ appendWith sizer = FL.foldlM' (snocWith sizer)
--
-- /Pre-release/
{-# INLINE append #-}
append :: forall m a. (MonadIO m, Storable a) =>
append :: forall m a. (MonadIO m, Unboxed a) =>
m (Array a) -> Fold m a (Array a)
append = appendWith (* 2)
@ -1743,7 +1743,7 @@ append = appendWith (* 2)
--
-- /Pre-release/
{-# INLINE_NORMAL writeNWithUnsafe #-}
writeNWithUnsafe :: forall m a. (MonadIO m, Storable a)
writeNWithUnsafe :: forall m a. (MonadIO m, Unboxed a)
=> (Int -> m (Array a)) -> Int -> Fold m a (Array a)
writeNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
@ -1766,7 +1766,7 @@ writeNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
--
-- @since 0.7.0
{-# INLINE_NORMAL writeNUnsafe #-}
writeNUnsafe :: forall m a. (MonadIO m, Storable a)
writeNUnsafe :: forall m a. (MonadIO m, Unboxed a)
=> Int -> Fold m a (Array a)
writeNUnsafe = writeNWithUnsafe newArray
@ -1777,7 +1777,7 @@ writeNUnsafe = writeNWithUnsafe newArray
-- >>> writeNWith alloc n = Array.appendN (alloc n) n
--
{-# INLINE_NORMAL writeNWith #-}
writeNWith :: forall m a. (MonadIO m, Storable a)
writeNWith :: forall m a. (MonadIO m, Unboxed a)
=> (Int -> m (Array a)) -> Int -> Fold m a (Array a)
writeNWith alloc n = FL.take n (writeNWithUnsafe alloc n)
@ -1790,14 +1790,14 @@ writeNWith alloc n = FL.take n (writeNWithUnsafe alloc n)
--
-- @since 0.7.0
{-# INLINE_NORMAL writeN #-}
writeN :: forall m a. (MonadIO m, Storable a) => Int -> Fold m a (Array a)
writeN :: forall m a. (MonadIO m, Unboxed a) => Int -> Fold m a (Array a)
writeN = writeNWith newArray
-- | Like writeNWithUnsafe but writes the array in reverse order.
--
-- /Internal/
{-# INLINE_NORMAL writeRevNWithUnsafe #-}
writeRevNWithUnsafe :: forall m a. (MonadIO m, Storable a)
writeRevNWithUnsafe :: forall m a. (MonadIO m, Unboxed a)
=> (Int -> m (Array a)) -> Int -> Fold m a (Array a)
writeRevNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
@ -1818,7 +1818,7 @@ writeRevNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
--
-- /Internal/
{-# INLINE_NORMAL writeRevNWith #-}
writeRevNWith :: forall m a. (MonadIO m, Storable a)
writeRevNWith :: forall m a. (MonadIO m, Unboxed a)
=> (Int -> m (Array a)) -> Int -> Fold m a (Array a)
writeRevNWith alloc n = FL.take n (writeRevNWithUnsafe alloc n)
@ -1826,7 +1826,7 @@ writeRevNWith alloc n = FL.take n (writeRevNWithUnsafe alloc n)
--
-- /Pre-release/
{-# INLINE_NORMAL writeRevN #-}
writeRevN :: forall m a. (MonadIO m, Storable a) => Int -> Fold m a (Array a)
writeRevN :: forall m a. (MonadIO m, Unboxed a) => Int -> Fold m a (Array a)
writeRevN = writeRevNWith newArray
-- | @writeNAligned align n@ folds a maximum of @n@ elements from the input
@ -1838,7 +1838,7 @@ writeRevN = writeRevNWith newArray
-- /Pre-release/
--
{-# INLINE_NORMAL writeNAligned #-}
writeNAligned :: forall m a. (MonadIO m, Storable a)
writeNAligned :: forall m a. (MonadIO m, Unboxed a)
=> Int -> Int -> Fold m a (Array a)
writeNAligned align = writeNWith (newArrayAligned align)
@ -1856,7 +1856,7 @@ writeNAligned align = writeNWith (newArrayAligned align)
-- /Unimplemented/
--
{-# INLINE_NORMAL writeChunks #-}
writeChunks :: (MonadIO m, Storable a) =>
writeChunks :: (MonadIO m, Unboxed a) =>
Int -> Fold m a (K.Stream n (Array a))
writeChunks n = FL.many (writeN n) FL.toStreamK
@ -1889,7 +1889,7 @@ writeChunks n = FL.many (writeN n) FL.toStreamK
--
-- /Pre-release/
{-# INLINE_NORMAL writeWith #-}
writeWith :: forall m a. (MonadIO m, Storable a)
writeWith :: forall m a. (MonadIO m, Unboxed a)
=> Int -> Fold m a (Array a)
-- writeWith n = FL.rmapM rightSize $ appendWith (* 2) (newArray n)
writeWith elemCount =
@ -1928,7 +1928,7 @@ writeWith elemCount =
--
-- @since 0.7.0
{-# INLINE write #-}
write :: forall m a. (MonadIO m, Storable a) => Fold m a (Array a)
write :: forall m a. (MonadIO m, Unboxed a) => Fold m a (Array a)
write = writeWith (allocBytesToElemCount (undefined :: a) arrayChunkBytes)
-------------------------------------------------------------------------------
@ -1940,7 +1940,7 @@ write = writeWith (allocBytesToElemCount (undefined :: a) arrayChunkBytes)
-- >>> fromStreamDN n = StreamD.fold (Array.writeN n)
--
{-# INLINE_NORMAL fromStreamDN #-}
fromStreamDN :: forall m a. (MonadIO m, Storable a)
fromStreamDN :: forall m a. (MonadIO m, Unboxed a)
=> Int -> D.Stream m a -> m (Array a)
-- fromStreamDN n = D.fold (writeN n)
fromStreamDN limit str = do
@ -1960,14 +1960,14 @@ fromStreamDN limit str = do
--
-- @since 0.7.0
{-# INLINABLE fromListN #-}
fromListN :: (MonadIO m, Storable a) => Int -> [a] -> m (Array a)
fromListN :: (MonadIO m, Unboxed a) => Int -> [a] -> m (Array a)
fromListN n xs = fromStreamDN n $ D.fromList xs
-- | Like fromListN but writes the array in reverse order.
--
-- /Pre-release/
{-# INLINE fromListRevN #-}
fromListRevN :: (MonadIO m, Storable a) => Int -> [a] -> m (Array a)
fromListRevN :: (MonadIO m, Unboxed a) => Int -> [a] -> m (Array a)
fromListRevN n xs = D.fold (writeRevN n) $ D.fromList xs
-------------------------------------------------------------------------------
@ -1975,14 +1975,14 @@ fromListRevN n xs = D.fold (writeRevN n) $ D.fromList xs
-------------------------------------------------------------------------------
{-# INLINE arrayStreamKLength #-}
arrayStreamKLength :: (Monad m, Storable a) => K.Stream m (Array a) -> m Int
arrayStreamKLength :: (Monad m, Unboxed a) => K.Stream m (Array a) -> m Int
arrayStreamKLength as = K.foldl' (+) 0 (K.map length as)
-- | Convert an array stream to an array. Note that this requires peak memory
-- that is double the size of the array stream.
--
{-# INLINE fromArrayStreamK #-}
fromArrayStreamK :: (Storable a, MonadIO m) =>
fromArrayStreamK :: (Unboxed a, MonadIO m) =>
K.Stream m (Array a) -> m (Array a)
fromArrayStreamK as = do
len <- arrayStreamKLength as
@ -2002,14 +2002,14 @@ fromArrayStreamK as = do
-- >>> fromStreamD = StreamD.fold Array.write
--
{-# INLINE fromStreamD #-}
fromStreamD :: (MonadIO m, Storable a) => D.Stream m a -> m (Array a)
fromStreamD :: (MonadIO m, Unboxed a) => D.Stream m a -> m (Array a)
fromStreamD m = arrayStreamKFromStreamD m >>= fromArrayStreamK
-- | Create an 'Array' from a list. The list must be of finite size.
--
-- @since 0.7.0
{-# INLINE fromList #-}
fromList :: (MonadIO m, Storable a) => [a] -> m (Array a)
fromList :: (MonadIO m, Unboxed a) => [a] -> m (Array a)
fromList xs = fromStreamD $ D.fromList xs
-- XXX We are materializing the whole list first for getting the length. Check
@ -2017,7 +2017,7 @@ fromList xs = fromStreamD $ D.fromList xs
-- | Like 'fromList' but writes the contents of the list in reverse order.
{-# INLINE fromListRev #-}
fromListRev :: (MonadIO m, Storable a) => [a] -> m (Array a)
fromListRev :: (MonadIO m, Unboxed a) => [a] -> m (Array a)
fromListRev xs = fromListRevN (Prelude.length xs) xs
-------------------------------------------------------------------------------
@ -2042,7 +2042,7 @@ putSliceUnsafe src srcStartBytes dst dstStartBytes lenBytes = liftIO $ do
-- | Copy two arrays into a newly allocated array.
{-# INLINE spliceCopy #-}
spliceCopy :: forall m a. (MonadIO m, Storable a) =>
spliceCopy :: forall m a. (MonadIO m, Unboxed a) =>
Array a -> Array a -> m (Array a)
spliceCopy arr1 arr2 = liftIO $ do
let start1 = arrStart arr1
@ -2084,7 +2084,7 @@ spliceUnsafe dst src =
--
-- /Pre-release/
{-# INLINE spliceWith #-}
spliceWith :: forall m a. (MonadIO m, Storable a) =>
spliceWith :: forall m a. (MonadIO m, Unboxed a) =>
(Int -> Int -> Int) -> Array a -> Array a -> m (Array a)
spliceWith sizer dst@(Array _ start end bound) src = do
{-
@ -2118,7 +2118,7 @@ spliceWith sizer dst@(Array _ start end bound) src = do
--
-- /Pre-release/
{-# INLINE splice #-}
splice :: (MonadIO m, Storable a) => Array a -> Array a -> m (Array a)
splice :: (MonadIO m, Unboxed a) => Array a -> Array a -> m (Array a)
splice = spliceWith (+)
-- | Like 'append' but the growth of the array is exponential. Whenever a new
@ -2132,7 +2132,7 @@ splice = spliceWith (+)
--
-- /Pre-release/
{-# INLINE spliceExp #-}
spliceExp :: (MonadIO m, Storable a) => Array a -> Array a -> m (Array a)
spliceExp :: (MonadIO m, Unboxed a) => Array a -> Array a -> m (Array a)
spliceExp = spliceWith (\l1 l2 -> max (l1 * 2) (l1 + l2))
-------------------------------------------------------------------------------
@ -2171,7 +2171,7 @@ breakOn sep arr@Array{..} = asPtrUnsafe arr $ \p -> liftIO $ do
-- specified index @i@ is the first index of the second slice.
--
-- @since 0.7.0
splitAt :: forall a. Storable a => Int -> Array a -> (Array a, Array a)
splitAt :: forall a. Unboxed a => Int -> Array a -> (Array a, Array a)
splitAt i arr@Array{..} =
let maxIndex = length arr - 1
in if i < 0
@ -2208,7 +2208,7 @@ splitAt i arr@Array{..} =
--
castUnsafe ::
#ifdef DEVBUILD
Storable b =>
Unboxed b =>
#endif
Array a -> Array b
castUnsafe (Array contents start end bound) =
@ -2227,7 +2227,7 @@ asBytes = castUnsafe
--
-- /Pre-release/
--
cast :: forall a b. Storable b => Array a -> Maybe (Array b)
cast :: forall a b. Unboxed b => Array a -> Maybe (Array b)
cast arr =
let len = byteLength arr
r = len `mod` SIZE_OF(b)
@ -2316,7 +2316,7 @@ cmp arr1 arr2 =
-- NFData
-------------------------------------------------------------------------------
-- This is a Storable array, we cannot have unevaluated data in it so this is
-- This is an Unboxed array, we cannot have unevaluated data in it so this is
-- just a no op.
instance NFData (Array a) where
{-# INLINE rnf #-}
@ -2330,7 +2330,7 @@ instance NFData1 Array where
--
-- /Pre-release/
{-# INLINE strip #-}
strip :: forall a m. (Storable a, MonadIO m) =>
strip :: forall a m. (Unboxed a, MonadIO m) =>
(a -> Bool) -> Array a -> m (Array a)
strip eq arr@Array{..} = liftIO $ do
st <- getStart arrStart
@ -2374,7 +2374,7 @@ strip eq arr@Array{..} = liftIO $ do
--
-- /Pre-release/
{-# INLINE bubble #-}
bubble :: (MonadIO m, Storable a) => (a -> a -> Ordering) -> Array a -> m ()
bubble :: (MonadIO m, Unboxed a) => (a -> a -> Ordering) -> Array a -> m ()
bubble cmp0 arr =
when (l > 1) $ do
x <- getIndexUnsafe (l - 1) arr

View File

@ -89,7 +89,7 @@ import GHC.Ptr (Ptr(..))
import Streamly.Internal.Data.Array.Unboxed.Mut.Type (ArrayContents)
import Streamly.Internal.Data.Fold.Type (Fold(..))
import Streamly.Internal.Data.Stream.Type (Stream)
import Streamly.Internal.Data.Unboxed (Storable, peekWith, sizeOf)
import Streamly.Internal.Data.Unboxed (Unboxed, peekWith, sizeOf)
import Streamly.Internal.Data.Unfold.Type (Unfold(..))
import Text.Read (readPrec, readListPrec, readListPrecDefault)
@ -125,7 +125,7 @@ import qualified Data.Foldable as F
-- $arrayNotes
--
-- We can use a 'Storable' constraint in the Array type and the constraint can
-- We can use an 'Unboxed' constraint in the Array type and the constraint can
-- be automatically provided to a function that pattern matches on the Array
-- type. However, it has huge performance cost, so we do not use it.
-- Investigate a GHC improvement possiblity.
@ -134,7 +134,7 @@ import qualified Data.Foldable as F
--
data Array a =
#ifdef DEVBUILD
Storable a =>
Unboxed a =>
#endif
-- All offsets are in terms of bytes from the start of arraycontents
Array
@ -182,7 +182,7 @@ unsafeFreeze (MA.Array ac as ae _) = Array ac as ae
-- | Similar to 'unsafeFreeze' but uses 'MA.rightSize' on the mutable array
-- first.
{-# INLINE unsafeFreezeWithShrink #-}
unsafeFreezeWithShrink :: Storable a => MA.Array a -> Array a
unsafeFreezeWithShrink :: Unboxed a => MA.Array a -> Array a
unsafeFreezeWithShrink arr = unsafePerformIO $ do
MA.Array ac as ae _ <- MA.rightSize arr
return $ Array ac as ae
@ -217,7 +217,7 @@ unpin = fmap unsafeFreeze . MA.unpin . unsafeThaw
-- Splice two immutable arrays creating a new array.
{-# INLINE splice #-}
splice :: (MonadIO m, Storable a) => Array a -> Array a -> m (Array a)
splice :: (MonadIO m, Unboxed a) => Array a -> Array a -> m (Array a)
splice arr1 arr2 =
unsafeFreeze <$> MA.splice (unsafeThaw arr1) (unsafeThaw arr2)
@ -229,7 +229,7 @@ splice arr1 arr2 =
--
-- @since 0.8.0
{-# INLINABLE fromListN #-}
fromListN :: Storable a => Int -> [a] -> Array a
fromListN :: Unboxed a => Int -> [a] -> Array a
fromListN n xs = unsafePerformIO $ unsafeFreeze <$> MA.fromListN n xs
-- | 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
--
-- /Pre-release/
{-# INLINABLE fromListRevN #-}
fromListRevN :: Storable a => Int -> [a] -> Array a
fromListRevN :: Unboxed a => Int -> [a] -> Array a
fromListRevN n xs = unsafePerformIO $ unsafeFreeze <$> MA.fromListRevN n xs
-- | 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
--
-- @since 0.8.0
{-# INLINE fromList #-}
fromList :: Storable a => [a] -> Array a
fromList :: Unboxed a => [a] -> Array a
fromList xs = unsafePerformIO $ unsafeFreeze <$> MA.fromList xs
-- | 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
--
-- /Pre-release/
{-# INLINABLE fromListRev #-}
fromListRev :: Storable a => [a] -> Array a
fromListRev :: Unboxed a => [a] -> Array a
fromListRev xs = unsafePerformIO $ unsafeFreeze <$> MA.fromListRev xs
{-# INLINE_NORMAL fromStreamDN #-}
fromStreamDN :: forall m a. (MonadIO m, Storable a)
fromStreamDN :: forall m a. (MonadIO m, Unboxed a)
=> Int -> D.Stream m a -> m (Array a)
fromStreamDN limit str = unsafeFreeze <$> MA.fromStreamDN limit str
{-# INLINE_NORMAL fromStreamD #-}
fromStreamD :: forall m a. (MonadIO m, Storable a)
fromStreamD :: forall m a. (MonadIO m, Unboxed a)
=> D.Stream m a -> m (Array a)
fromStreamD str = unsafeFreeze <$> MA.fromStreamD str
@ -273,14 +273,14 @@ fromStreamD str = unsafeFreeze <$> MA.fromStreamD str
-------------------------------------------------------------------------------
{-# INLINE bufferChunks #-}
bufferChunks :: (MonadIO m, Storable a) =>
bufferChunks :: (MonadIO m, Unboxed a) =>
D.Stream m a -> m (K.Stream m (Array a))
bufferChunks m = D.foldr K.cons K.nil $ arraysOf defaultChunkSize m
-- | @arraysOf n stream@ groups the input stream into a stream of
-- arrays of size n.
{-# INLINE_NORMAL arraysOf #-}
arraysOf :: forall m a. (MonadIO m, Storable a)
arraysOf :: forall m a. (MonadIO m, Unboxed a)
=> Int -> D.Stream m a -> D.Stream m (Array a)
arraysOf n str = D.map unsafeFreeze $ MA.arraysOf n str
@ -291,7 +291,7 @@ arraysOf n str = D.map unsafeFreeze $ MA.arraysOf n str
-- We can try this if there are any fusion issues in the unfold.
--
{-# INLINE_NORMAL flattenArrays #-}
flattenArrays :: forall m a. (MonadIO m, Storable a)
flattenArrays :: forall m a. (MonadIO m, Unboxed a)
=> D.Stream m (Array a) -> D.Stream m a
flattenArrays = MA.flattenArrays . D.map unsafeThaw
@ -302,7 +302,7 @@ flattenArrays = MA.flattenArrays . D.map unsafeThaw
-- We can try this if there are any fusion issues in the unfold.
--
{-# INLINE_NORMAL flattenArraysRev #-}
flattenArraysRev :: forall m a. (MonadIO m, Storable a)
flattenArraysRev :: forall m a. (MonadIO m, Unboxed a)
=> D.Stream m (Array a) -> D.Stream m a
flattenArraysRev = MA.flattenArraysRev . D.map unsafeThaw
@ -322,12 +322,12 @@ breakOn sep arr = do
--
-- Unsafe because it does not check the bounds of the array.
{-# INLINE_NORMAL unsafeIndexIO #-}
unsafeIndexIO :: forall a. Storable a => Int -> Array a -> IO a
unsafeIndexIO :: forall a. Unboxed a => Int -> Array a -> IO a
unsafeIndexIO i arr = MA.getIndexUnsafe i (unsafeThaw arr)
-- | Return element at the specified index without checking the bounds.
{-# INLINE_NORMAL unsafeIndex #-}
unsafeIndex :: forall a. Storable a => Int -> Array a -> a
unsafeIndex :: forall a. Unboxed a => Int -> Array a -> a
unsafeIndex i arr = let !r = unsafeInlineIO $ unsafeIndexIO i arr in r
-- | /O(1)/ Get the byte length of the array.
@ -344,31 +344,31 @@ byteLength = MA.byteLength . unsafeThaw
--
-- @since 0.8.0
{-# INLINE length #-}
length :: Storable a => Array a -> Int
length :: Unboxed a => Array a -> Int
length arr = MA.length (unsafeThaw arr)
-- | Unfold an array into a stream in reverse order.
--
-- @since 0.8.0
{-# INLINE_NORMAL readRev #-}
readRev :: forall m a. (Monad m, Storable a) => Unfold m (Array a) a
readRev :: forall m a. (Monad m, Unboxed a) => Unfold m (Array a) a
readRev = Unfold.lmap unsafeThaw $ MA.readRevWith (return . unsafeInlineIO)
{-# INLINE_NORMAL toStreamD #-}
toStreamD :: forall m a. (Monad m, Storable a) => Array a -> D.Stream m a
toStreamD :: forall m a. (Monad m, Unboxed a) => Array a -> D.Stream m a
toStreamD arr = MA.toStreamDWith (return . unsafeInlineIO) (unsafeThaw arr)
{-# INLINE toStreamK #-}
toStreamK :: forall m a. (Monad m, Storable a) => Array a -> K.Stream m a
toStreamK :: forall m a. (Monad m, Unboxed a) => Array a -> K.Stream m a
toStreamK arr = MA.toStreamKWith (return . unsafeInlineIO) (unsafeThaw arr)
{-# INLINE_NORMAL toStreamDRev #-}
toStreamDRev :: forall m a. (Monad m, Storable a) => Array a -> D.Stream m a
toStreamDRev :: forall m a. (Monad m, Unboxed a) => Array a -> D.Stream m a
toStreamDRev arr =
MA.toStreamDRevWith (return . unsafeInlineIO) (unsafeThaw arr)
{-# INLINE toStreamKRev #-}
toStreamKRev :: forall m a. (Monad m, Storable a) => Array a -> K.Stream m a
toStreamKRev :: forall m a. (Monad m, Unboxed a) => Array a -> K.Stream m a
toStreamKRev arr =
MA.toStreamKRevWith (return . unsafeInlineIO) (unsafeThaw arr)
@ -376,7 +376,7 @@ toStreamKRev arr =
--
-- /Pre-release/
{-# INLINE_EARLY toStream #-}
toStream :: (Monad m, Storable a) => Array a -> Stream m a
toStream :: (Monad m, Unboxed a) => Array a -> Stream m a
toStream = Stream.fromStreamD . toStreamD
-- XXX add fallback to StreamK rule
-- {-# RULES "Streamly.Array.read fallback to StreamK" [1]
@ -386,7 +386,7 @@ toStream = Stream.fromStreamD . toStreamD
--
-- /Pre-release/
{-# INLINE_EARLY toStreamRev #-}
toStreamRev :: (Monad m, Storable a) => Array a -> Stream m a
toStreamRev :: (Monad m, Unboxed a) => Array a -> Stream m a
toStreamRev = Stream.fromStreamD . toStreamDRev
-- XXX add fallback to StreamK rule
@ -394,18 +394,18 @@ toStreamRev = Stream.fromStreamD . toStreamDRev
-- forall a. S.toStreamK (readRev a) = K.revFromArray a #-}
{-# INLINE_NORMAL foldl' #-}
foldl' :: forall a b. Storable a => (b -> a -> b) -> b -> Array a -> b
foldl' :: forall a b. Unboxed a => (b -> a -> b) -> b -> Array a -> b
foldl' f z arr = runIdentity $ D.foldl' f z $ toStreamD arr
{-# INLINE_NORMAL foldr #-}
foldr :: Storable a => (a -> b -> b) -> b -> Array a -> b
foldr :: Unboxed a => (a -> b -> b) -> b -> Array a -> b
foldr f z arr = runIdentity $ D.foldr f z $ toStreamD arr
-- | Create two slices of an array without copying the original array. The
-- specified index @i@ is the first index of the second slice.
--
-- @since 0.7.0
splitAt :: Storable a => Int -> Array a -> (Array a, Array a)
splitAt :: Unboxed a => Int -> Array a -> (Array a, Array a)
splitAt i arr = (unsafeFreeze a, unsafeFreeze b)
where
(a, b) = MA.splitAt i (unsafeThaw arr)
@ -413,7 +413,7 @@ splitAt i arr = (unsafeFreeze a, unsafeFreeze b)
-- Use foldr/build fusion to fuse with list consumers
-- This can be useful when using the IsList instance
{-# INLINE_LATE toListFB #-}
toListFB :: forall a b. Storable a => (a -> b -> b) -> b -> Array a -> b
toListFB :: forall a b. Unboxed a => (a -> b -> b) -> b -> Array a -> b
toListFB c n Array{..} = go arrStart
where
@ -434,7 +434,7 @@ toListFB c n Array{..} = go arrStart
--
-- @since 0.8.0
{-# INLINE toList #-}
toList :: Storable a => Array a -> [a]
toList :: Unboxed a => Array a -> [a]
toList s = build (\c n -> toListFB c n s)
-------------------------------------------------------------------------------
@ -448,7 +448,7 @@ toList s = build (\c n -> toListFB c n s)
--
-- @since 0.8.0
{-# INLINE_NORMAL writeN #-}
writeN :: forall m a. (MonadIO m, Storable a) => Int -> Fold m a (Array a)
writeN :: forall m a. (MonadIO m, Unboxed a) => Int -> Fold m a (Array a)
writeN = fmap unsafeFreeze . MA.writeN
-- | @writeNAligned alignment n@ folds a maximum of @n@ elements from the input
@ -457,7 +457,7 @@ writeN = fmap unsafeFreeze . MA.writeN
-- /Pre-release/
--
{-# INLINE_NORMAL writeNAligned #-}
writeNAligned :: forall m a. (MonadIO m, Storable a)
writeNAligned :: forall m a. (MonadIO m, Unboxed a)
=> Int -> Int -> Fold m a (Array a)
writeNAligned alignSize = fmap unsafeFreeze . MA.writeNAligned alignSize
@ -469,12 +469,12 @@ writeNAligned alignSize = fmap unsafeFreeze . MA.writeNAligned alignSize
--
-- @since 0.7.0
{-# INLINE_NORMAL writeNUnsafe #-}
writeNUnsafe :: forall m a. (MonadIO m, Storable a)
writeNUnsafe :: forall m a. (MonadIO m, Unboxed a)
=> Int -> Fold m a (Array a)
writeNUnsafe n = unsafeFreeze <$> MA.writeNUnsafe n
{-# INLINE_NORMAL writeWith #-}
writeWith :: forall m a. (MonadIO m, Storable a)
writeWith :: forall m a. (MonadIO m, Unboxed a)
=> Int -> Fold m a (Array a)
-- writeWith n = FL.rmapM spliceArrays $ toArraysOf n
writeWith elemCount = unsafeFreeze <$> MA.writeWith elemCount
@ -487,18 +487,18 @@ writeWith elemCount = unsafeFreeze <$> MA.writeWith elemCount
--
-- @since 0.8.0
{-# INLINE write #-}
write :: forall m a. (MonadIO m, Storable a) => Fold m a (Array a)
write :: forall m a. (MonadIO m, Unboxed a) => Fold m a (Array a)
write = fmap unsafeFreeze MA.write
-------------------------------------------------------------------------------
-- Instances
-------------------------------------------------------------------------------
instance (Show a, Storable a) => Show (Array a) where
instance (Show a, Unboxed a) => Show (Array a) where
{-# INLINE showsPrec #-}
showsPrec _ = shows . toList
instance (Storable a, Read a, Show a) => Read (Array a) where
instance (Unboxed a, Read a, Show a) => Read (Array a) where
{-# INLINE readPrec #-}
readPrec = fromList <$> readPrec
readListPrec = readListPrecDefault
@ -508,7 +508,7 @@ instance (a ~ Char) => IsString (Array a) where
fromString = fromList
-- GHC versions 8.0 and below cannot derive IsList
instance Storable a => IsList (Array a) where
instance Unboxed a => IsList (Array a) where
type (Item (Array a)) = a
{-# INLINE fromList #-}
fromList = fromList
@ -517,14 +517,14 @@ instance Storable a => IsList (Array a) where
{-# INLINE toList #-}
toList = toList
-- XXX we are assuming that Storable equality means element equality. This may
-- XXX we are assuming that Unboxed equality means element equality. This may
-- or may not be correct? arrcmp is 40% faster compared to stream equality.
instance (Storable a, Eq a) => Eq (Array a) where
instance (Unboxed a, Eq a) => Eq (Array a) where
{-# INLINE (==) #-}
arr1 == arr2 =
(==) EQ $ unsafeInlineIO $! unsafeThaw arr1 `MA.cmp` unsafeThaw arr2
-- Since this is a Storable array we cannot have unevaluated data in it so
-- Since this is an Unboxed array we cannot have unevaluated data in it so
-- this is just a no op.
instance NFData (Array a) where
{-# INLINE rnf #-}
@ -533,7 +533,7 @@ instance NFData (Array a) where
instance NFData1 Array where
liftRnf _ Array{} = ()
instance (Storable a, Ord a) => Ord (Array a) where
instance (Unboxed a, Ord a) => Ord (Array a) where
{-# INLINE compare #-}
compare arr1 arr2 = runIdentity $
D.cmpBy compare (toStreamD arr1) (toStreamD arr2)
@ -561,7 +561,7 @@ instance (Storable a, Ord a) => Ord (Array a) where
min x y = if x <= y then x else y
#ifdef DEVBUILD
-- Definitions using the Storable constraint from the Array type. These are to
-- Definitions using the Unboxed constraint from the Array type. These are to
-- make the Foldable instance possible though it is much slower (7x slower).
--
{-# INLINE_NORMAL toStreamD_ #-}
@ -578,7 +578,7 @@ toStreamD_ size Array{..} = D.Stream step arrStart
{-
XXX Why isn't Storable implicit? This does not compile unless I use the Storable
XXX Why isn't Unboxed implicit? This does not compile unless I use the Unboxed
contraint.
{-# INLINE_NORMAL _foldr #-}
@ -599,16 +599,16 @@ instance Foldable Array where
-- Semigroup and Monoid
-------------------------------------------------------------------------------
instance Storable a => Semigroup (Array a) where
instance Unboxed a => Semigroup (Array a) where
arr1 <> arr2 = unsafePerformIO $ splice arr1 arr2
nil ::
#ifdef DEVBUILD
Storable a =>
Unboxed a =>
#endif
Array a
nil = Array MA.nilArrayContents 0 0
instance Storable a => Monoid (Array a) where
instance Unboxed a => Monoid (Array a) where
mempty = nil
mappend = (<>)

View File

@ -55,7 +55,7 @@ where
import Control.Monad.IO.Class (MonadIO(..))
import Streamly.Internal.Data.Fold.Type (Fold (..))
import Streamly.Internal.Data.Unboxed (Storable)
import Streamly.Internal.Data.Unboxed (Unboxed)
import Streamly.Internal.System.IO (defaultChunkSize)
import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
@ -312,7 +312,7 @@ reverse s = fromStreamD $ D.reverse $ toStreamD s
--
-- /Pre-release/
{-# INLINE reverse' #-}
reverse' :: (MonadIO m, Storable a) => Stream m a -> Stream m a
reverse' :: (MonadIO m, Unboxed a) => Stream m a -> Stream m a
-- reverse' s = fromStreamD $ D.reverse' $ toStreamD s
reverse' =
fromStreamD

View File

@ -58,7 +58,7 @@ import Streamly.Internal.Data.Parser (Parser (..))
import Streamly.Internal.Data.Refold.Type (Refold (..))
import Streamly.Internal.Data.Stream.Bottom (foldManyPost)
import Streamly.Internal.Data.Stream.Type (Stream, fromStreamD, toStreamD)
import Streamly.Internal.Data.Unboxed (Storable)
import Streamly.Internal.Data.Unboxed (Unboxed)
import qualified Streamly.Internal.Data.Array.Unboxed.Type as Array
import qualified Streamly.Internal.Data.Parser.ParserD as ParserD
@ -313,6 +313,6 @@ parseIterate f i m = fromStreamD $
--
-- /Pre-release/
{-# INLINE arraysOf #-}
arraysOf :: (MonadIO m, Storable a)
arraysOf :: (MonadIO m, Unboxed a)
=> Int -> Stream m a -> Stream m (Array a)
arraysOf n = fromStreamD . Array.arraysOf n . toStreamD

View File

@ -2,8 +2,7 @@
{-# LANGUAGE UnboxedTuples #-}
module Streamly.Internal.Data.Unboxed
( Storable
, Unboxed
( Unboxed
, alignment
, peekWith
, pokeWith
@ -380,8 +379,6 @@ instance forall a. Unboxed a => Unboxed (Complex a) where
-- Functions
--------------------------------------------------------------------------------
type Storable a = Unboxed a
{-# INLINE peekWith #-}
peekWith :: Unboxed a => ArrayContents a -> Int -> IO a
peekWith = readByteArray

View File

@ -58,7 +58,7 @@ import Control.Monad.IO.Class (MonadIO(..))
import Data.Semigroup (Semigroup(..))
#endif
import Data.Word (Word8)
import Streamly.Internal.Data.Unboxed (Storable, peekWith, sizeOf)
import Streamly.Internal.Data.Unboxed (Unboxed, peekWith, sizeOf)
import Fusion.Plugin.Types (Fuse(..))
import GHC.Exts (SpecConstrAnnotation(..))
import GHC.Types (SPEC(..))
@ -105,7 +105,7 @@ import qualified Streamly.Internal.Data.Stream.Type as Stream
--
-- /Pre-release/
{-# INLINE arraysOf #-}
arraysOf :: (IsStream t, MonadIO m, Storable a)
arraysOf :: (IsStream t, MonadIO m, Unboxed a)
=> Int -> t m a -> t m (Array a)
arraysOf n str = fromStreamD $ A.arraysOf n (toStreamD str)
@ -125,7 +125,7 @@ arraysOf n str = fromStreamD $ A.arraysOf n (toStreamD str)
--
-- @since 0.7.0
{-# INLINE concat #-}
concat :: (IsStream t, Monad m, Storable a) => t m (Array a) -> t m a
concat :: (IsStream t, Monad m, Unboxed a) => t m (Array a) -> t m a
-- concat m = fromStreamD $ A.flattenArrays (toStreamD m)
-- concat m = fromStreamD $ D.concatMap A.toStreamD (toStreamD m)
concat m = fromStreamD $ D.unfoldMany A.read (toStreamD m)
@ -137,7 +137,7 @@ concat m = fromStreamD $ D.unfoldMany A.read (toStreamD m)
--
-- @since 0.7.0
{-# INLINE concatRev #-}
concatRev :: (IsStream t, Monad m, Storable a) => t m (Array a) -> t m a
concatRev :: (IsStream t, Monad m, Unboxed a) => t m (Array a) -> t m a
-- concatRev m = fromStreamD $ A.flattenArraysRev (toStreamD m)
concatRev m = fromStreamD $ D.unfoldMany A.readRev (toStreamD m)
@ -150,11 +150,11 @@ concatRev m = fromStreamD $ D.unfoldMany A.readRev (toStreamD m)
--
-- /Pre-release/
{-# INLINE interpose #-}
interpose :: (Monad m, IsStream t, Storable a) => a -> t m (Array a) -> t m a
interpose :: (Monad m, IsStream t, Unboxed a) => a -> t m (Array a) -> t m a
interpose x = S.interpose x A.read
{-# INLINE intercalateSuffix #-}
intercalateSuffix :: (Monad m, IsStream t, Storable a)
intercalateSuffix :: (Monad m, IsStream t, Unboxed a)
=> Array a -> t m (Array a) -> t m a
intercalateSuffix = S.intercalateSuffix A.read
@ -163,7 +163,7 @@ intercalateSuffix = S.intercalateSuffix A.read
--
-- @since 0.7.0
{-# INLINE interposeSuffix #-}
interposeSuffix :: (Monad m, IsStream t, Storable a)
interposeSuffix :: (Monad m, IsStream t, Unboxed a)
=> a -> t m (Array a) -> t m a
-- interposeSuffix x = fromStreamD . A.unlines x . toStreamD
interposeSuffix x = S.interposeSuffix x A.read
@ -174,7 +174,7 @@ data FlattenState s a =
-- XXX Remove monadIO constraint
{-# INLINE_NORMAL unlines #-}
unlines :: forall m a. (MonadIO m, Storable a)
unlines :: forall m a. (MonadIO m, Unboxed a)
=> a -> D.Stream m (Array a) -> D.Stream m a
unlines sep (D.Stream step state) = D.Stream step' (OuterLoop state)
where
@ -202,7 +202,7 @@ unlines sep (D.Stream step state) = D.Stream step' (OuterLoop state)
-- module Streamly.Internal.Data.Array.Stream.Mut.Foreign
--
{-# INLINE_NORMAL packArraysChunksOf #-}
packArraysChunksOf :: (MonadIO m, Storable a)
packArraysChunksOf :: (MonadIO m, Unboxed a)
=> Int -> D.Stream m (Array a) -> D.Stream m (Array a)
packArraysChunksOf n str =
D.map A.unsafeFreeze $ AS.packArraysChunksOf n $ D.map A.unsafeThaw str
@ -210,7 +210,7 @@ packArraysChunksOf n str =
-- XXX instead of writing two different versions of this operation, we should
-- write it as a pipe.
{-# INLINE_NORMAL lpackArraysChunksOf #-}
lpackArraysChunksOf :: (MonadIO m, Storable a)
lpackArraysChunksOf :: (MonadIO m, Unboxed a)
=> Int -> Fold m (Array a) () -> Fold m (Array a) ()
lpackArraysChunksOf n fld =
FL.lmap A.unsafeThaw $ AS.lpackArraysChunksOf n (FL.lmap A.unsafeFreeze fld)
@ -220,7 +220,7 @@ lpackArraysChunksOf n fld =
--
-- @since 0.7.0
{-# INLINE compact #-}
compact :: (MonadIO m, Storable a)
compact :: (MonadIO m, Unboxed a)
=> Int -> SerialT m (Array a) -> SerialT m (Array a)
compact n xs = fromStreamD $ packArraysChunksOf n (toStreamD xs)
@ -317,7 +317,7 @@ splitOnSuffix byte s =
-- to the number of times it can be called on the same stream.
--
{-# INLINE_NORMAL foldBreakD #-}
foldBreakD :: forall m a b. (MonadIO m, Storable a) =>
foldBreakD :: forall m a b. (MonadIO m, Unboxed a) =>
Fold m a b -> D.Stream m (Array a) -> m (b, D.Stream m (Array a))
foldBreakD (Fold fstep initial extract) stream@(D.Stream step state) = do
res <- initial
@ -353,7 +353,7 @@ foldBreakD (Fold fstep initial extract) stream@(D.Stream step state) = do
FL.Partial fs1 -> goArray SPEC st fp next fs1
{-# INLINE_NORMAL foldBreakK #-}
foldBreakK :: forall m a b. (MonadIO m, Storable a) =>
foldBreakK :: forall m a b. (MonadIO m, Unboxed a) =>
Fold m a b -> K.Stream m (Array a) -> m (b, K.Stream m (Array a))
foldBreakK (Fold fstep initial extract) stream = do
res <- initial
@ -394,7 +394,7 @@ foldBreakK (Fold fstep initial extract) stream = do
--
{-# INLINE_NORMAL foldBreak #-}
foldBreak ::
(MonadIO m, Storable a)
(MonadIO m, Unboxed a)
=> FL.Fold m a b
-> SerialT m (A.Array a)
-> m (b, SerialT m (A.Array a))
@ -413,7 +413,7 @@ foldBreak f =
-- When we have to take an array partially, take the last part of the array.
{-# INLINE takeArrayListRev #-}
takeArrayListRev :: forall a. Storable a => Int -> [Array a] -> [Array a]
takeArrayListRev :: forall a. Unboxed a => Int -> [Array a] -> [Array a]
takeArrayListRev = go
where
@ -434,7 +434,7 @@ takeArrayListRev = go
-- the first split.
{-# INLINE splitAtArrayListRev #-}
splitAtArrayListRev ::
forall a. Storable a => Int -> [Array a] -> ([Array a],[Array a])
forall a. Unboxed a => Int -> [Array a] -> ([Array a],[Array a])
splitAtArrayListRev n ls
| n <= 0 = ([], ls)
| otherwise = go n ls
@ -464,14 +464,14 @@ splitAtArrayListRev n ls
-- CAUTION! length must more than equal to lengths of all the arrays in the
-- stream.
{-# INLINE spliceArraysLenUnsafe #-}
spliceArraysLenUnsafe :: (MonadIO m, Storable a)
spliceArraysLenUnsafe :: (MonadIO m, Unboxed a)
=> Int -> SerialT m (MA.Array a) -> m (MA.Array a)
spliceArraysLenUnsafe len buffered = do
arr <- liftIO $ MA.newArray len
S.foldlM' MA.spliceUnsafe (return arr) buffered
{-# INLINE _spliceArrays #-}
_spliceArrays :: (MonadIO m, Storable a)
_spliceArrays :: (MonadIO m, Unboxed a)
=> SerialT m (Array a) -> m (Array a)
_spliceArrays s = do
buffered <- S.foldr S.cons S.nil s
@ -485,7 +485,7 @@ _spliceArrays s = do
writeArr dst arr = MA.spliceUnsafe dst (A.unsafeThaw arr)
{-# INLINE _spliceArraysBuffered #-}
_spliceArraysBuffered :: (MonadIO m, Storable a)
_spliceArraysBuffered :: (MonadIO m, Unboxed a)
=> SerialT m (Array a) -> m (Array a)
_spliceArraysBuffered s = do
buffered <- S.foldr S.cons S.nil s
@ -493,7 +493,7 @@ _spliceArraysBuffered s = do
A.unsafeFreeze <$> spliceArraysLenUnsafe len (S.map A.unsafeThaw s)
{-# INLINE spliceArraysRealloced #-}
spliceArraysRealloced :: forall m a. (MonadIO m, Storable a)
spliceArraysRealloced :: forall m a. (MonadIO m, Unboxed a)
=> SerialT m (Array a) -> m (Array a)
spliceArraysRealloced s = do
let n = allocBytesToElemCount (undefined :: a) (4 * 1024)
@ -509,7 +509,7 @@ spliceArraysRealloced s = do
--
-- @since 0.7.0
{-# INLINE toArray #-}
toArray :: (MonadIO m, Storable a) => SerialT m (Array a) -> m (Array a)
toArray :: (MonadIO m, Unboxed a) => SerialT m (Array a) -> m (Array a)
toArray = spliceArraysRealloced
-- spliceArrays = _spliceArraysBuffered
@ -520,7 +520,7 @@ toArray = spliceArraysRealloced
--
{-
{-# INLINE toArraysInRange #-}
toArraysInRange :: (IsStream t, MonadIO m, Storable a)
toArraysInRange :: (IsStream t, MonadIO m, Unboxed a)
=> Int -> Int -> Fold m (Array a) b -> Fold m a b
toArraysInRange low high (Fold step initial extract) =
-}
@ -528,7 +528,7 @@ toArraysInRange low high (Fold step initial extract) =
{-
-- | Fold the input to a pure buffered stream (List) of arrays.
{-# INLINE _toArraysOf #-}
_toArraysOf :: (MonadIO m, Storable a)
_toArraysOf :: (MonadIO m, Unboxed a)
=> Int -> Fold m a (SerialT Identity (Array a))
_toArraysOf n = FL.chunksOf n (A.writeNF n) FL.toStream
-}
@ -549,7 +549,7 @@ newtype List a = List {getList :: [a]}
-- to the number of times it can be called on the same stream.
{-# INLINE_NORMAL parseBreakD #-}
parseBreakD ::
forall m a b. (MonadIO m, MonadThrow m, Storable a)
forall m a b. (MonadIO m, MonadThrow m, Unboxed a)
=> PRD.Parser m a b
-> D.Stream m (Array.Array a)
-> m (b, D.Stream m (Array.Array a))
@ -629,7 +629,7 @@ parseBreakD
{-# INLINE_NORMAL parseBreakK #-}
parseBreakK ::
forall m a b. (MonadIO m, MonadThrow m, Storable a)
forall m a b. (MonadIO m, MonadThrow m, Unboxed a)
=> PRD.Parser m a b
-> K.Stream m (Array.Array a)
-> m (b, K.Stream m (Array.Array a))
@ -708,7 +708,7 @@ parseBreakK (PRD.Parser pstep initial extract) stream = do
--
{-# INLINE_NORMAL parseBreak #-}
parseBreak ::
(MonadIO m, MonadThrow m, Storable a)
(MonadIO m, MonadThrow m, Unboxed a)
=> PR.Parser m a b
-> SerialT m (A.Array a)
-> m (b, SerialT m (A.Array a))
@ -734,7 +734,7 @@ parseBreak p =
--
{-# INLINE_NORMAL runArrayParserDBreak #-}
runArrayParserDBreak ::
forall m a b. (MonadIO m, MonadThrow m, Storable a)
forall m a b. (MonadIO m, MonadThrow m, Unboxed a)
=> PRD.Parser m (Array a) b
-> D.Stream m (Array.Array a)
-> m (b, D.Stream m (Array.Array a))
@ -806,7 +806,7 @@ runArrayParserDBreak
--
{-# INLINE parseArr #-}
parseArr ::
(MonadIO m, MonadThrow m, Storable a)
(MonadIO m, MonadThrow m, Unboxed a)
=> ASF.Parser m a b
-> SerialT m (A.Array a)
-> m (b, SerialT m (A.Array a))
@ -818,7 +818,7 @@ parseArr p s = fmap fromStreamD <$> parseBreakD p (toStreamD s)
-- /Pre-release/
--
{-# INLINE runArrayFold #-}
runArrayFold :: (MonadIO m, MonadThrow m, Storable a) =>
runArrayFold :: (MonadIO m, MonadThrow m, Unboxed a) =>
ArrayFold m a b -> SerialT m (A.Array a) -> m b
runArrayFold (ArrayFold p) s = fst <$> runArrayParserDBreak p (toStreamD s)
@ -827,7 +827,7 @@ runArrayFold (ArrayFold p) s = fst <$> runArrayParserDBreak p (toStreamD s)
-- /Pre-release/
--
{-# INLINE runArrayFoldBreak #-}
runArrayFoldBreak :: (MonadIO m, MonadThrow m, Storable a) =>
runArrayFoldBreak :: (MonadIO m, MonadThrow m, Unboxed a) =>
ArrayFold m a b -> SerialT m (A.Array a) -> m (b, SerialT m (A.Array a))
runArrayFoldBreak (ArrayFold p) s =
second fromStreamD <$> runArrayParserDBreak p (toStreamD s)
@ -842,7 +842,7 @@ data ParseChunksState x inpBuf st pst =
{-# INLINE_NORMAL runArrayFoldManyD #-}
runArrayFoldManyD
:: (MonadThrow m, Storable a)
:: (MonadThrow m, Unboxed a)
=> ArrayFold m a b
-> D.Stream m (Array a)
-> D.Stream m b
@ -970,7 +970,7 @@ runArrayFoldManyD
-- /Pre-release/
{-# INLINE runArrayFoldMany #-}
runArrayFoldMany
:: (IsStream t, MonadThrow m, Storable a)
:: (IsStream t, MonadThrow m, Unboxed a)
=> ArrayFold m a b
-> t m (Array a)
-> t m b

View File

@ -79,7 +79,7 @@ import Streamly.Internal.Data.Stream.IsStream.Type
import Streamly.Internal.Data.Stream.Serial (SerialT)
import Streamly.Internal.Data.Time.Units (AbsTime, RelTime64, addToAbsTime64)
import Streamly.Internal.System.IO (defaultChunkSize)
import Streamly.Internal.Data.Unboxed (Storable, Unboxed)
import Streamly.Internal.Data.Unboxed (Unboxed)
import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
import qualified Streamly.Internal.Data.Stream.Async as Async
@ -499,7 +499,7 @@ reverse s = fromStreamS $ S.reverse $ toStreamS s
--
-- /Pre-release/
{-# INLINE reverse' #-}
reverse' :: (IsStream t, MonadIO m, Storable a) => t m a -> t m a
reverse' :: (IsStream t, MonadIO m, Unboxed a) => t m a -> t m a
-- reverse' s = fromStreamD $ D.reverse' $ toStreamD s
reverse' =
fromStreamD

View File

@ -178,7 +178,7 @@ import Streamly.Internal.Data.Stream.IsStream.Type
import Streamly.Internal.Data.Time.Units
( AbsTime, MilliSecond64(..), addToAbsTime, toRelTime
, toAbsTime)
import Streamly.Internal.Data.Unboxed (Storable, Unboxed)
import Streamly.Internal.Data.Unboxed (Unboxed)
import qualified Data.Heap as H
import qualified Streamly.Data.Unfold as Unfold
@ -779,7 +779,7 @@ splitWithSuffix predicate f = foldMany (FL.takeEndBy predicate f)
-- /Unimplemented/
--
{-# INLINE splitOnAny #-}
splitOnAny :: -- (IsStream t, Monad m, Storable a, Integral a) =>
splitOnAny :: -- (IsStream t, Monad m, Unboxed a, Integral a) =>
[Array a] -> Fold m a b -> t m a -> t m b
splitOnAny _subseq _f _m =
undefined -- D.fromStreamD $ D.splitOnAny f subseq (D.toStreamD m)
@ -889,7 +889,7 @@ splitOnSuffixSeq patt f m =
--
-- /Unimplemented/
{-# INLINE wordsOn #-}
wordsOn :: -- (IsStream t, Monad m, Storable a, Eq a) =>
wordsOn :: -- (IsStream t, Monad m, Unboxed a, Eq a) =>
Array a -> Fold m a b -> t m a -> t m b
wordsOn _subseq _f _m =
undefined -- D.fromStreamD $ D.wordsOn f subseq (D.toStreamD m)
@ -939,7 +939,7 @@ splitWithSuffixSeq patt f m =
--
-- /Unimplemented/
{-# INLINE splitOnSuffixSeqAny #-}
splitOnSuffixSeqAny :: -- (IsStream t, Monad m, Storable a, Integral a) =>
splitOnSuffixSeqAny :: -- (IsStream t, Monad m, Unboxed a, Integral a) =>
[Array a] -> Fold m a b -> t m a -> t m b
splitOnSuffixSeqAny _subseq _f _m = undefined
-- D.fromStreamD $ D.splitPostAny f subseq (D.toStreamD m)
@ -975,7 +975,7 @@ chunksOf n f = fromStreamD . D.chunksOf n f . toStreamD
--
-- /Pre-release/
{-# INLINE arraysOf #-}
arraysOf :: (IsStream t, MonadIO m, Storable a)
arraysOf :: (IsStream t, MonadIO m, Unboxed a)
=> Int -> t m a -> t m (Array a)
arraysOf n = fromStreamD . A.arraysOf n . toStreamD
@ -1081,7 +1081,7 @@ classifySlidingSessions tick interval slide (Fold step initial extract) str
-- insert the new elements, and apply an incremental fold on the sliding
-- window, supplying the outgoing elements, the new ring buffer as arguments.
slidingChunkBuffer
:: (IsStream t, Monad m, Ord a, Storable a)
:: (IsStream t, Monad m, Ord a, Unboxed a)
=> Int -- window size
-> Int -- window slide
-> Fold m (Ring a, Array a) b
@ -1094,7 +1094,7 @@ slidingChunkBuffer = undefined
-- an incremental fold on the sliding window, supplying the outgoing elements,
-- and the new radix tree buffer as arguments.
slidingSessionBuffer
:: (IsStream t, Monad m, Ord a, Storable a)
:: (IsStream t, Monad m, Ord a, Unboxed a)
=> Int -- window size
-> Int -- tick size
-> Fold m (RTree a, Array a) b

View File

@ -120,7 +120,7 @@ import Control.Monad.IO.Class (MonadIO(..))
import Data.Word (Word8)
-- import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
import Foreign.Ptr (castPtr)
import Streamly.Internal.Data.Unboxed (Storable)
import Streamly.Internal.Data.Unboxed (Unboxed)
-- import System.IO (Handle, hGetBufSome, hPutBuf)
import System.IO (IOMode)
import Prelude hiding (read)
@ -237,7 +237,7 @@ readArrayUpto size (Handle fd) = do
--
-- @since 0.7.0
{-# INLINABLE writeArray #-}
writeArray :: Storable a => Handle -> Array a -> IO ()
writeArray :: Unboxed a => Handle -> Array a -> IO ()
writeArray _ arr | A.length arr == 0 = return ()
writeArray (Handle fd) arr =
asPtrUnsafe arr $ \p ->
@ -334,7 +334,7 @@ readInChunksOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
readInChunksOf chunkSize h = AS.concat $ readArraysOfUpto chunkSize h
-- TODO
-- read :: (IsStream t, MonadIO m, Storable a) => Handle -> t m a
-- read :: (IsStream t, MonadIO m, Unboxed a) => Handle -> t m a
--
-- > read = 'readByChunks' A.defaultChunkSize
-- | Generate a stream of elements of the given type from a file 'Handle'. The
@ -353,7 +353,7 @@ read = AS.concat . readArrays
--
-- @since 0.7.0
{-# INLINE writeArrays #-}
writeArrays :: (MonadIO m, Storable a) => Handle -> Stream m (Array a) -> m ()
writeArrays :: (MonadIO m, Unboxed a) => Handle -> Stream m (Array a) -> m ()
writeArrays h = S.mapM_ (liftIO . writeArray h)
-- | 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)
--
-- @since 0.7.0
{-# INLINE writeArraysPackedUpto #-}
writeArraysPackedUpto :: (MonadIO m, Storable a)
writeArraysPackedUpto :: (MonadIO m, Unboxed a)
=> Int -> Handle -> Stream m (Array a) -> m ()
writeArraysPackedUpto n h xs = writeArrays h $ AS.compact n xs
@ -422,7 +422,7 @@ write = writeInChunksOf defaultChunkSize
{-
{-# INLINE write #-}
write :: (MonadIO m, Storable a) => Handle -> Stream m a -> m ()
write :: (MonadIO m, Unboxed a) => Handle -> Stream m a -> m ()
write = toHandleWith A.defaultChunkSize
-}
@ -481,7 +481,7 @@ readLines h f = foldLines (readUtf8 h) f
--
-- @since 0.7.0
{-# INLINE readFrames #-}
readFrames :: (IsStream t, MonadIO m, Storable a)
readFrames :: (IsStream t, MonadIO m, Unboxed a)
=> Array a -> Handle -> Fold m a b -> t m b
readFrames = undefined -- foldFrames . read
@ -490,7 +490,7 @@ readFrames = undefined -- foldFrames . read
--
-- @since 0.7.0
{-# INLINE writeByFrames #-}
writeByFrames :: (IsStream t, MonadIO m, Storable a)
writeByFrames :: (IsStream t, MonadIO m, Unboxed a)
=> Array a -> Handle -> t m a -> m ()
writeByFrames = undefined
@ -508,7 +508,7 @@ writeByFrames = undefined
--
-- @since 0.7.0
{-# INLINE readIndex #-}
readIndex :: Storable a => Handle -> Int -> Maybe a
readIndex :: Unboxed a => Handle -> Int -> Maybe a
readIndex arr i = undefined
-- NOTE: To represent a range to read we have chosen (start, size) instead of
@ -528,7 +528,7 @@ readIndex arr i = undefined
-- chunk is aligned with @chunkSize@ from second chunk onwards.
--
{-# INLINE readSliceWith #-}
readSliceWith :: (IsStream t, MonadIO m, Storable a)
readSliceWith :: (IsStream t, MonadIO m, Unboxed a)
=> Int -> Handle -> Int -> Int -> t m a
readSliceWith chunkSize h pos len = undefined
@ -538,7 +538,7 @@ readSliceWith chunkSize h pos len = undefined
--
-- @since 0.7.0
{-# INLINE readSlice #-}
readSlice :: (IsStream t, MonadIO m, Storable a)
readSlice :: (IsStream t, MonadIO m, Unboxed a)
=> Handle -> Int -> Int -> t m a
readSlice = readSliceWith defaultChunkSize
@ -548,7 +548,7 @@ readSlice = readSliceWith defaultChunkSize
--
-- @since 0.7.0
{-# INLINE readSliceRev #-}
readSliceRev :: (IsStream t, MonadIO m, Storable a)
readSliceRev :: (IsStream t, MonadIO m, Unboxed a)
=> Handle -> Int -> Int -> t m a
readSliceRev h i count = undefined
@ -556,7 +556,7 @@ readSliceRev h i count = undefined
--
-- @since 0.7.0
{-# INLINE writeIndex #-}
writeIndex :: (MonadIO m, Storable a) => Handle -> Int -> a -> m ()
writeIndex :: (MonadIO m, Unboxed a) => Handle -> Int -> a -> m ()
writeIndex h i a = undefined
-- | @writeSlice h i count stream@ writes a stream to the file handle @h@
@ -565,7 +565,7 @@ writeIndex h i a = undefined
--
-- @since 0.7.0
{-# INLINE writeSlice #-}
writeSlice :: (IsStream t, Monad m, Storable a)
writeSlice :: (IsStream t, Monad m, Unboxed a)
=> Handle -> Int -> Int -> t m a -> m ()
writeSlice h i len s = undefined
@ -575,7 +575,7 @@ writeSlice h i len s = undefined
--
-- @since 0.7.0
{-# INLINE writeSliceRev #-}
writeSliceRev :: (IsStream t, Monad m, Storable a)
writeSliceRev :: (IsStream t, Monad m, Unboxed a)
=> Handle -> Int -> Int -> t m a -> m ()
writeSliceRev arr i len s = undefined
-}

View File

@ -114,7 +114,7 @@ import Control.Monad.IO.Class (MonadIO(..))
import Data.Function ((&))
import Data.Maybe (isNothing, fromJust)
import Data.Word (Word8)
import Streamly.Internal.Data.Unboxed (Storable)
import Streamly.Internal.Data.Unboxed (Unboxed)
import System.IO (Handle, SeekMode(..), hGetBufSome, hPutBuf, hSeek)
import Prelude hiding (read)
@ -365,7 +365,7 @@ getBytesWith size h = AS.concat $ getChunksWith size h
-- TODO
-- Generate a stream of elements of the given type from a file 'Handle'.
-- read :: (IsStream t, MonadIO m, Storable a) => Handle -> t m a
-- read :: (IsStream t, MonadIO m, Unboxed a) => Handle -> t m a
--
-- | Unfolds a file handle into a byte stream. IO requests to the device are
-- performed in sizes of
@ -438,7 +438,7 @@ putChunks h = S.mapM_ (putChunk h)
--
-- @since 0.9.0
{-# INLINE putChunksWith #-}
putChunksWith :: (MonadIO m, Storable a)
putChunksWith :: (MonadIO m, Unboxed a)
=> Int -> Handle -> Stream m (Array a) -> m ()
putChunksWith n h xs = putChunks h $ AS.compact n xs
@ -495,7 +495,7 @@ consumeChunks = Refold.drainBy putChunk
--
-- @since 0.9.0
{-# INLINE writeChunksWith #-}
writeChunksWith :: (MonadIO m, Storable a)
writeChunksWith :: (MonadIO m, Unboxed a)
=> Int -> Handle -> Fold m (Array a) ()
writeChunksWith n h = lpackArraysChunksOf n (writeChunks h)
@ -504,7 +504,7 @@ writeChunksWith n h = lpackArraysChunksOf n (writeChunks h)
-- @since 0.7.0
{-# DEPRECATED writeChunksWithBufferOf "Please use writeChunksWith instead." #-}
{-# INLINE writeChunksWithBufferOf #-}
writeChunksWithBufferOf :: (MonadIO m, Storable a)
writeChunksWithBufferOf :: (MonadIO m, Unboxed a)
=> Int -> Handle -> Fold m (Array a) ()
writeChunksWithBufferOf = writeChunksWith
@ -578,7 +578,7 @@ consumer = consumerWith defaultChunkSize
{-
{-# INLINE write #-}
write :: (MonadIO m, Storable a) => Handle -> Stream m a -> m ()
write :: (MonadIO m, Unboxed a) => Handle -> Stream m a -> m ()
write = toHandleWith A.defaultChunkSize
-}
@ -641,7 +641,7 @@ readLines h f = foldLines (readUtf8 h) f
--
-- @since 0.7.0
{-# INLINE readFrames #-}
readFrames :: (IsStream t, MonadIO m, Storable a)
readFrames :: (IsStream t, MonadIO m, Unboxed a)
=> Array a -> Handle -> Fold m a b -> t m b
readFrames = undefined -- foldFrames . read
@ -650,7 +650,7 @@ readFrames = undefined -- foldFrames . read
--
-- @since 0.7.0
{-# INLINE writeByFrames #-}
writeByFrames :: (IsStream t, MonadIO m, Storable a)
writeByFrames :: (IsStream t, MonadIO m, Unboxed a)
=> Array a -> Handle -> t m a -> m ()
writeByFrames = undefined
@ -685,7 +685,7 @@ writeBySessionsOf n = writeByChunksOrSessionsOf defaultChunkSize n
--
-- @since 0.7.0
{-# INLINE readIndex #-}
readIndex :: Storable a => Handle -> Int -> Maybe a
readIndex :: Unboxed a => Handle -> Int -> Maybe a
readIndex arr i = undefined
-- NOTE: To represent a range to read we have chosen (start, size) instead of
@ -705,7 +705,7 @@ readIndex arr i = undefined
-- chunk is aligned with @chunkSize@ from second chunk onwards.
--
{-# INLINE readSliceWith #-}
readSliceWith :: (IsStream t, MonadIO m, Storable a)
readSliceWith :: (IsStream t, MonadIO m, Unboxed a)
=> Int -> Handle -> Int -> Int -> t m a
readSliceWith chunkSize h pos len = undefined
@ -715,7 +715,7 @@ readSliceWith chunkSize h pos len = undefined
--
-- @since 0.7.0
{-# INLINE readSlice #-}
readSlice :: (IsStream t, MonadIO m, Storable a)
readSlice :: (IsStream t, MonadIO m, Unboxed a)
=> Handle -> Int -> Int -> t m a
readSlice = readSliceWith A.defaultChunkSize
@ -725,7 +725,7 @@ readSlice = readSliceWith A.defaultChunkSize
--
-- @since 0.7.0
{-# INLINE readSliceRev #-}
readSliceRev :: (IsStream t, MonadIO m, Storable a)
readSliceRev :: (IsStream t, MonadIO m, Unboxed a)
=> Handle -> Int -> Int -> t m a
readSliceRev h i count = undefined
@ -733,7 +733,7 @@ readSliceRev h i count = undefined
--
-- @since 0.7.0
{-# INLINE writeIndex #-}
writeIndex :: (MonadIO m, Storable a) => Handle -> Int -> a -> m ()
writeIndex :: (MonadIO m, Unboxed a) => Handle -> Int -> a -> m ()
writeIndex h i a = undefined
-- | @writeSlice h i count stream@ writes a stream to the file handle @h@
@ -742,7 +742,7 @@ writeIndex h i a = undefined
--
-- @since 0.7.0
{-# INLINE writeSlice #-}
writeSlice :: (IsStream t, Monad m, Storable a)
writeSlice :: (IsStream t, Monad m, Unboxed a)
=> Handle -> Int -> Int -> t m a -> m ()
writeSlice h i len s = undefined
@ -752,7 +752,7 @@ writeSlice h i len s = undefined
--
-- @since 0.7.0
{-# INLINE writeSliceRev #-}
writeSliceRev :: (IsStream t, Monad m, Storable a)
writeSliceRev :: (IsStream t, Monad m, Unboxed a)
=> Handle -> Int -> Int -> t m a -> m ()
writeSliceRev arr i len s = undefined
-}

View File

@ -76,7 +76,7 @@ import Control.Monad (forM_, when)
import Data.Maybe (isNothing, fromJust)
import Data.Word (Word8)
import Foreign.Ptr (plusPtr, Ptr, castPtr)
import Streamly.Internal.Data.Unboxed (Storable)
import Streamly.Internal.Data.Unboxed (Unboxed)
import Network.Socket
(Socket, SocketOption(..), Family(..), SockAddr(..),
ProtocolNumber, withSocketsDo, SocketType(..), socket, bind,
@ -303,7 +303,7 @@ sendAll s p len = do
when (sent >= 0) $ sendAll s (p `plusPtr` sent) (len - sent)
{-# INLINABLE writeArrayWith #-}
writeArrayWith :: Storable a
writeArrayWith :: Unboxed a
=> (h -> Ptr Word8 -> Int -> IO ())
-> h
-> Array a
@ -319,7 +319,7 @@ writeArrayWith f h arr = A.asPtrUnsafe arr $ \ptr -> f h (castPtr ptr) aLen
--
-- @since 0.8.0
{-# INLINABLE writeChunk #-}
writeChunk :: Storable a => Socket -> Array a -> IO ()
writeChunk :: Unboxed a => Socket -> Array a -> IO ()
writeChunk = writeArrayWith sendAll
-------------------------------------------------------------------------------
@ -423,7 +423,7 @@ readWith chunkSize h = A.flattenArrays $ readChunksUpto chunkSize h
-}
-- TODO
-- read :: (IsStream t, MonadIO m, Storable a) => Handle -> t m a
-- read :: (IsStream t, MonadIO m, Unboxed a) => Handle -> t m a
--
-- > read = 'readByChunks' defaultChunkSize
-- | Generate a stream of elements of the given type from a socket. The
@ -467,7 +467,7 @@ read = UF.first defaultChunkSize readWith
--
-- @since 0.7.0
{-# INLINE putChunks #-}
putChunks :: (MonadIO m, Storable a)
putChunks :: (MonadIO m, Unboxed a)
=> Socket -> Stream m (Array a) -> m ()
putChunks h = S.mapM_ (liftIO . writeChunk h)
@ -476,7 +476,7 @@ putChunks h = S.mapM_ (liftIO . writeChunk h)
--
-- @since 0.7.0
{-# INLINE writeChunks #-}
writeChunks :: (MonadIO m, Storable a) => Socket -> Fold m (Array a) ()
writeChunks :: (MonadIO m, Unboxed a) => Socket -> Fold m (Array a) ()
writeChunks h = FL.drainBy (liftIO . writeChunk h)
-- | @writeChunksWith bufsize socket@ writes a stream of arrays to
@ -487,7 +487,7 @@ writeChunks h = FL.drainBy (liftIO . writeChunk h)
--
-- @since 0.9.0
{-# INLINE writeChunksWith #-}
writeChunksWith :: (MonadIO m, Storable a)
writeChunksWith :: (MonadIO m, Unboxed a)
=> Int -> Socket -> Fold m (Array a) ()
writeChunksWith n h = lpackArraysChunksOf n (writeChunks h)
@ -496,7 +496,7 @@ writeChunksWith n h = lpackArraysChunksOf n (writeChunks h)
-- @since 0.7.0
{-# DEPRECATED writeChunksWithBufferOf "Please use 'writeChunksWith' instead" #-}
{-# INLINE writeChunksWithBufferOf #-}
writeChunksWithBufferOf :: (MonadIO m, Storable a)
writeChunksWithBufferOf :: (MonadIO m, Unboxed a)
=> Int -> Socket -> Fold m (Array a) ()
writeChunksWithBufferOf = writeChunksWith
@ -571,7 +571,7 @@ write = writeWith defaultChunkSize
{-
{-# INLINE write #-}
write :: (MonadIO m, Storable a) => Handle -> Stream m a -> m ()
write :: (MonadIO m, Unboxed a) => Handle -> Stream m a -> m ()
write = toHandleWith defaultChunkSize
-}
@ -630,7 +630,7 @@ readLines h f = foldLines (readUtf8 h) f
--
-- @since 0.7.0
{-# INLINE readFrames #-}
readFrames :: (IsStream t, MonadIO m, Storable a)
readFrames :: (IsStream t, MonadIO m, Unboxed a)
=> Array a -> Handle -> Fold m a b -> t m b
readFrames = undefined -- foldFrames . read
@ -639,7 +639,7 @@ readFrames = undefined -- foldFrames . read
--
-- @since 0.7.0
{-# INLINE writeByFrames #-}
writeByFrames :: (IsStream t, MonadIO m, Storable a)
writeByFrames :: (IsStream t, MonadIO m, Unboxed a)
=> Array a -> Handle -> t m a -> m ()
writeByFrames = undefined
-}