Copyright | (c) Dong Han 2017 |
---|---|
License | BSD |
Maintainer | winterland1989@gmail.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Unified unboxed and boxed array operations using functional dependencies.
All operations are NOT bound checked, if you need checked operations please use Std.Data.Array.Checked. It exports exactly same APIs so that you can switch between without pain.
Some mnemonics:
newArr
,newArrWith
return mutable array,readArr
,writeArr
works on them,setArr
fill elements with offset and length.indexArr
works on immutable one, useindexArr'
to avoid indexing thunk.- The order of arguements of
copyArr
,copyMutableArr
andmoveArr
are always target and its offset come first, and source and source offset follow, copying length comes last.
Synopsis
- class Arr (marr :: * -> * -> *) (arr :: * -> *) a | arr -> marr, marr -> arr where
- type IArr marr = (ar :: * -> *) | ar -> marr
- type MArr arr = (mar :: * -> * -> *) | mar -> arr
- newArr :: (PrimMonad m, PrimState m ~ s) => Int -> m (marr s a)
- newArrWith :: (PrimMonad m, PrimState m ~ s) => Int -> a -> m (marr s a)
- readArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> m a
- writeArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> a -> m ()
- setArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> Int -> a -> m ()
- indexArr :: arr a -> Int -> a
- indexArr' :: arr a -> Int -> (#a#)
- indexArrM :: Monad m => arr a -> Int -> m a
- freezeArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> Int -> m (arr a)
- thawArr :: (PrimMonad m, PrimState m ~ s) => arr a -> Int -> Int -> m (marr s a)
- unsafeFreezeArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> m (arr a)
- unsafeThawArr :: (PrimMonad m, PrimState m ~ s) => arr a -> m (marr s a)
- copyArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> arr a -> Int -> Int -> m ()
- copyMutableArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> marr s a -> Int -> Int -> m ()
- moveArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> marr s a -> Int -> Int -> m ()
- cloneArr :: arr a -> Int -> Int -> arr a
- cloneMutableArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> Int -> m (marr s a)
- resizeMutableArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> m (marr s a)
- shrinkMutableArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> m ()
- sameMutableArr :: marr s a -> marr s a -> Bool
- sizeofArr :: arr a -> Int
- sizeofMutableArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> m Int
- sameArr :: arr a -> arr a -> Bool
- data RealWorld :: Type
- data Array a = Array {}
- data MutableArray s a = MutableArray {
- marray# :: MutableArray# s a
- data SmallArray a = SmallArray (SmallArray# a)
- data SmallMutableArray s a = SmallMutableArray (SmallMutableArray# s a)
- uninitialized :: a
- data PrimArray a = PrimArray ByteArray#
- data MutablePrimArray s a = MutablePrimArray (MutableByteArray# s)
- class Prim a where
- sizeOf# :: a -> Int#
- alignment# :: a -> Int#
- indexByteArray# :: ByteArray# -> Int# -> a
- readByteArray# :: MutableByteArray# s -> Int# -> State# s -> (#State# s, a#)
- writeByteArray# :: MutableByteArray# s -> Int# -> a -> State# s -> State# s
- setByteArray# :: MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s
- indexOffAddr# :: Addr# -> Int# -> a
- readOffAddr# :: Addr# -> Int# -> State# s -> (#State# s, a#)
- writeOffAddr# :: Addr# -> Int# -> a -> State# s -> State# s
- setOffAddr# :: Addr# -> Int# -> Int# -> a -> State# s -> State# s
- newPinnedPrimArray :: forall m a. (PrimMonad m, Prim a) => Int -> m (MutablePrimArray (PrimState m) a)
- newAlignedPinnedPrimArray :: forall m a. (PrimMonad m, Prim a) => Int -> m (MutablePrimArray (PrimState m) a)
- copyPrimArrayToPtr :: (PrimMonad m, Prim a) => Ptr a -> PrimArray a -> Int -> Int -> m ()
- copyMutablePrimArrayToPtr :: (PrimMonad m, Prim a) => Ptr a -> MutablePrimArray (PrimState m) a -> Int -> Int -> m ()
- copyPtrToMutablePrimArray :: (PrimMonad m, Prim a) => MutablePrimArray (PrimState m) a -> Int -> Ptr a -> Int -> m ()
- primArrayContents :: PrimArray a -> Ptr a
- mutablePrimArrayContents :: MutablePrimArray s a -> Ptr a
- withPrimArrayContents :: PrimArray a -> (Ptr a -> IO b) -> IO b
- withMutablePrimArrayContents :: MutablePrimArray RealWorld a -> (Ptr a -> IO b) -> IO b
- isPrimArrayPinned :: PrimArray a -> Bool
- isMutablePrimArrayPinned :: MutablePrimArray s a -> Bool
- data UnliftedArray e = UnliftedArray ArrayArray#
- data MutableUnliftedArray s e = MutableUnliftedArray (MutableArrayArray# s)
- class PrimUnlifted a where
- toArrayArray# :: a -> ArrayArray#
- fromArrayArray# :: ArrayArray# -> a
- data ArrayException
- castArray :: (Arr marr arr a, Cast a b) => arr a -> arr b
- castMutableArray :: (Arr marr arr a, Cast a b) => marr s a -> marr s b
Arr typeclass
class Arr (marr :: * -> * -> *) (arr :: * -> *) a | arr -> marr, marr -> arr where Source #
A typeclass to unify box & unboxed, mutable & immutable array operations.
Most of these functions simply wrap their primitive counterpart, if there's no primitive ones, we polyfilled using other operations to get the same semantics.
One exception is that shrinkMutableArr
only perform closure resizing on PrimArray
because
current RTS support only that, shrinkMutableArr
will do nothing on other array type.
It's reasonable to trust GHC with specializing & inlining these polymorphric functions. They are used across this package and perform identical to their monomophric counterpart.
newArr :: (PrimMonad m, PrimState m ~ s) => Int -> m (marr s a) Source #
Make a new array with given size.
For boxed array, all elements are uninitialized
which shall not be accessed.
For primitive array, elements are just random garbage.
newArrWith :: (PrimMonad m, PrimState m ~ s) => Int -> a -> m (marr s a) Source #
Make a new array and fill it with an initial value.
readArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> m a Source #
Index mutable array in a primitive monad.
writeArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> a -> m () Source #
Write mutable array in a primitive monad.
setArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> Int -> a -> m () Source #
Fill mutable array with a given value.
indexArr :: arr a -> Int -> a Source #
Index immutable array, which is a pure operation. This operation often
result in an indexing thunk for lifted arrays, use 'indexArr\'' or indexArrM
if that's not desired.
indexArr' :: arr a -> Int -> (#a#) Source #
Index immutable array, pattern match on the unboxed unit tuple to force indexing (without forcing the element).
indexArrM :: Monad m => arr a -> Int -> m a Source #
Index immutable array in a primitive monad, this helps in situations that you want your indexing result is not a thunk referencing whole array.
freezeArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> Int -> m (arr a) Source #
Safely freeze mutable array by make a immutable copy of its slice.
thawArr :: (PrimMonad m, PrimState m ~ s) => arr a -> Int -> Int -> m (marr s a) Source #
Safely thaw immutable array by make a mutable copy of its slice.
unsafeFreezeArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> m (arr a) Source #
In place freeze a mutable array, the original mutable array can not be used anymore.
unsafeThawArr :: (PrimMonad m, PrimState m ~ s) => arr a -> m (marr s a) Source #
In place thaw a immutable array, the original immutable array can not be used anymore.
copyArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> arr a -> Int -> Int -> m () Source #
Copy a slice of immutable array to mutable array at given offset.
copyMutableArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> marr s a -> Int -> Int -> m () Source #
Copy a slice of mutable array to mutable array at given offset. The two mutable arrays shall no be the same one.
moveArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> marr s a -> Int -> Int -> m () Source #
Copy a slice of mutable array to mutable array at given offset. The two mutable arrays may be the same one.
cloneArr :: arr a -> Int -> Int -> arr a Source #
Create immutable copy.
cloneMutableArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> Int -> m (marr s a) Source #
Create mutable copy.
resizeMutableArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> m (marr s a) Source #
Resize mutable array to given size.
shrinkMutableArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> Int -> m () Source #
Shrink mutable array to given size. This operation only works on primitive arrays.
For boxed array, this is a no-op, e.g. sizeOfMutableArr
will not change.
sameMutableArr :: marr s a -> marr s a -> Bool Source #
Is two mutable array are reference equal.
sizeofArr :: arr a -> Int Source #
Size of immutable array.
sizeofMutableArr :: (PrimMonad m, PrimState m ~ s) => marr s a -> m Int Source #
Size of mutable array.
sameArr :: arr a -> arr a -> Bool Source #
Is two immutable array are referencing the same one.
Note that sameArr
's result may change depending on compiler's optimizations, for example
let arr = runST ... in arr
may return false if compiler decides to
inline it.sameArr
arr
See https://ghc.haskell.org/trac/ghc/ticket/13908 for more background.
Instances
Prim a => Arr MutablePrimArray PrimArray a Source # | |
Defined in Std.Data.Array type IArr MutablePrimArray = (ar :: Type -> Type) Source # type MArr PrimArray = (mar :: Type -> Type -> Type) Source # newArr :: (PrimMonad m, PrimState m ~ s) => Int -> m (MutablePrimArray s a) Source # newArrWith :: (PrimMonad m, PrimState m ~ s) => Int -> a -> m (MutablePrimArray s a) Source # readArr :: (PrimMonad m, PrimState m ~ s) => MutablePrimArray s a -> Int -> m a Source # writeArr :: (PrimMonad m, PrimState m ~ s) => MutablePrimArray s a -> Int -> a -> m () Source # setArr :: (PrimMonad m, PrimState m ~ s) => MutablePrimArray s a -> Int -> Int -> a -> m () Source # indexArr :: PrimArray a -> Int -> a Source # indexArr' :: PrimArray a -> Int -> (#a#) Source # indexArrM :: Monad m => PrimArray a -> Int -> m a Source # freezeArr :: (PrimMonad m, PrimState m ~ s) => MutablePrimArray s a -> Int -> Int -> m (PrimArray a) Source # thawArr :: (PrimMonad m, PrimState m ~ s) => PrimArray a -> Int -> Int -> m (MutablePrimArray s a) Source # unsafeFreezeArr :: (PrimMonad m, PrimState m ~ s) => MutablePrimArray s a -> m (PrimArray a) Source # unsafeThawArr :: (PrimMonad m, PrimState m ~ s) => PrimArray a -> m (MutablePrimArray s a) Source # copyArr :: (PrimMonad m, PrimState m ~ s) => MutablePrimArray s a -> Int -> PrimArray a -> Int -> Int -> m () Source # copyMutableArr :: (PrimMonad m, PrimState m ~ s) => MutablePrimArray s a -> Int -> MutablePrimArray s a -> Int -> Int -> m () Source # moveArr :: (PrimMonad m, PrimState m ~ s) => MutablePrimArray s a -> Int -> MutablePrimArray s a -> Int -> Int -> m () Source # cloneArr :: PrimArray a -> Int -> Int -> PrimArray a Source # cloneMutableArr :: (PrimMonad m, PrimState m ~ s) => MutablePrimArray s a -> Int -> Int -> m (MutablePrimArray s a) Source # resizeMutableArr :: (PrimMonad m, PrimState m ~ s) => MutablePrimArray s a -> Int -> m (MutablePrimArray s a) Source # shrinkMutableArr :: (PrimMonad m, PrimState m ~ s) => MutablePrimArray s a -> Int -> m () Source # sameMutableArr :: MutablePrimArray s a -> MutablePrimArray s a -> Bool Source # sizeofArr :: PrimArray a -> Int Source # sizeofMutableArr :: (PrimMonad m, PrimState m ~ s) => MutablePrimArray s a -> m Int Source # | |
Arr MutableArray Array a Source # | |
Defined in Std.Data.Array newArr :: (PrimMonad m, PrimState m ~ s) => Int -> m (MutableArray s a) Source # newArrWith :: (PrimMonad m, PrimState m ~ s) => Int -> a -> m (MutableArray s a) Source # readArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> m a Source # writeArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> a -> m () Source # setArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> Int -> a -> m () Source # indexArr :: Array a -> Int -> a Source # indexArr' :: Array a -> Int -> (#a#) Source # indexArrM :: Monad m => Array a -> Int -> m a Source # freezeArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> Int -> m (Array a) Source # thawArr :: (PrimMonad m, PrimState m ~ s) => Array a -> Int -> Int -> m (MutableArray s a) Source # unsafeFreezeArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> m (Array a) Source # unsafeThawArr :: (PrimMonad m, PrimState m ~ s) => Array a -> m (MutableArray s a) Source # copyArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> Array a -> Int -> Int -> m () Source # copyMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> MutableArray s a -> Int -> Int -> m () Source # moveArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> MutableArray s a -> Int -> Int -> m () Source # cloneArr :: Array a -> Int -> Int -> Array a Source # cloneMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> Int -> m (MutableArray s a) Source # resizeMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> m (MutableArray s a) Source # shrinkMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> m () Source # sameMutableArr :: MutableArray s a -> MutableArray s a -> Bool Source # sizeofArr :: Array a -> Int Source # sizeofMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> m Int Source # | |
Arr SmallMutableArray SmallArray a Source # | |
Defined in Std.Data.Array type IArr SmallMutableArray = (ar :: Type -> Type) Source # type MArr SmallArray = (mar :: Type -> Type -> Type) Source # newArr :: (PrimMonad m, PrimState m ~ s) => Int -> m (SmallMutableArray s a) Source # newArrWith :: (PrimMonad m, PrimState m ~ s) => Int -> a -> m (SmallMutableArray s a) Source # readArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> m a Source # writeArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> a -> m () Source # setArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> Int -> a -> m () Source # indexArr :: SmallArray a -> Int -> a Source # indexArr' :: SmallArray a -> Int -> (#a#) Source # indexArrM :: Monad m => SmallArray a -> Int -> m a Source # freezeArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> Int -> m (SmallArray a) Source # thawArr :: (PrimMonad m, PrimState m ~ s) => SmallArray a -> Int -> Int -> m (SmallMutableArray s a) Source # unsafeFreezeArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> m (SmallArray a) Source # unsafeThawArr :: (PrimMonad m, PrimState m ~ s) => SmallArray a -> m (SmallMutableArray s a) Source # copyArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> SmallArray a -> Int -> Int -> m () Source # copyMutableArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> SmallMutableArray s a -> Int -> Int -> m () Source # moveArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> SmallMutableArray s a -> Int -> Int -> m () Source # cloneArr :: SmallArray a -> Int -> Int -> SmallArray a Source # cloneMutableArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> Int -> m (SmallMutableArray s a) Source # resizeMutableArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> m (SmallMutableArray s a) Source # shrinkMutableArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> m () Source # sameMutableArr :: SmallMutableArray s a -> SmallMutableArray s a -> Bool Source # sizeofArr :: SmallArray a -> Int Source # sizeofMutableArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> m Int Source # sameArr :: SmallArray a -> SmallArray a -> Bool Source # | |
PrimUnlifted a => Arr MutableUnliftedArray UnliftedArray a Source # | |
Defined in Std.Data.Array type IArr MutableUnliftedArray = (ar :: Type -> Type) Source # type MArr UnliftedArray = (mar :: Type -> Type -> Type) Source # newArr :: (PrimMonad m, PrimState m ~ s) => Int -> m (MutableUnliftedArray s a) Source # newArrWith :: (PrimMonad m, PrimState m ~ s) => Int -> a -> m (MutableUnliftedArray s a) Source # readArr :: (PrimMonad m, PrimState m ~ s) => MutableUnliftedArray s a -> Int -> m a Source # writeArr :: (PrimMonad m, PrimState m ~ s) => MutableUnliftedArray s a -> Int -> a -> m () Source # setArr :: (PrimMonad m, PrimState m ~ s) => MutableUnliftedArray s a -> Int -> Int -> a -> m () Source # indexArr :: UnliftedArray a -> Int -> a Source # indexArr' :: UnliftedArray a -> Int -> (#a#) Source # indexArrM :: Monad m => UnliftedArray a -> Int -> m a Source # freezeArr :: (PrimMonad m, PrimState m ~ s) => MutableUnliftedArray s a -> Int -> Int -> m (UnliftedArray a) Source # thawArr :: (PrimMonad m, PrimState m ~ s) => UnliftedArray a -> Int -> Int -> m (MutableUnliftedArray s a) Source # unsafeFreezeArr :: (PrimMonad m, PrimState m ~ s) => MutableUnliftedArray s a -> m (UnliftedArray a) Source # unsafeThawArr :: (PrimMonad m, PrimState m ~ s) => UnliftedArray a -> m (MutableUnliftedArray s a) Source # copyArr :: (PrimMonad m, PrimState m ~ s) => MutableUnliftedArray s a -> Int -> UnliftedArray a -> Int -> Int -> m () Source # copyMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableUnliftedArray s a -> Int -> MutableUnliftedArray s a -> Int -> Int -> m () Source # moveArr :: (PrimMonad m, PrimState m ~ s) => MutableUnliftedArray s a -> Int -> MutableUnliftedArray s a -> Int -> Int -> m () Source # cloneArr :: UnliftedArray a -> Int -> Int -> UnliftedArray a Source # cloneMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableUnliftedArray s a -> Int -> Int -> m (MutableUnliftedArray s a) Source # resizeMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableUnliftedArray s a -> Int -> m (MutableUnliftedArray s a) Source # shrinkMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableUnliftedArray s a -> Int -> m () Source # sameMutableArr :: MutableUnliftedArray s a -> MutableUnliftedArray s a -> Bool Source # sizeofArr :: UnliftedArray a -> Int Source # sizeofMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableUnliftedArray s a -> m Int Source # sameArr :: UnliftedArray a -> UnliftedArray a -> Bool Source # |
RealWorld
is deeply magical. It is primitive, but it is not
unlifted (hence ptrArg
). We never manipulate values of type
RealWorld
; it's only used in the type system, to parameterise State#
.
Boxed array type
Instances
Monad Array | |
Functor Array | |
MonadFix Array | |
Defined in Data.Primitive.Array | |
Applicative Array | |
Foldable Array | |
Defined in Data.Primitive.Array fold :: Monoid m => Array m -> m # foldMap :: Monoid m => (a -> m) -> Array a -> m # foldr :: (a -> b -> b) -> b -> Array a -> b # foldr' :: (a -> b -> b) -> b -> Array a -> b # foldl :: (b -> a -> b) -> b -> Array a -> b # foldl' :: (b -> a -> b) -> b -> Array a -> b # foldr1 :: (a -> a -> a) -> Array a -> a # foldl1 :: (a -> a -> a) -> Array a -> a # elem :: Eq a => a -> Array a -> Bool # maximum :: Ord a => Array a -> a # minimum :: Ord a => Array a -> a # | |
Traversable Array | |
Eq1 Array | |
Ord1 Array | |
Defined in Data.Primitive.Array | |
Read1 Array | |
Defined in Data.Primitive.Array | |
Show1 Array | |
MonadZip Array | |
Alternative Array | |
MonadPlus Array | |
Arr MutableArray Array a Source # | |
Defined in Std.Data.Array newArr :: (PrimMonad m, PrimState m ~ s) => Int -> m (MutableArray s a) Source # newArrWith :: (PrimMonad m, PrimState m ~ s) => Int -> a -> m (MutableArray s a) Source # readArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> m a Source # writeArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> a -> m () Source # setArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> Int -> a -> m () Source # indexArr :: Array a -> Int -> a Source # indexArr' :: Array a -> Int -> (#a#) Source # indexArrM :: Monad m => Array a -> Int -> m a Source # freezeArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> Int -> m (Array a) Source # thawArr :: (PrimMonad m, PrimState m ~ s) => Array a -> Int -> Int -> m (MutableArray s a) Source # unsafeFreezeArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> m (Array a) Source # unsafeThawArr :: (PrimMonad m, PrimState m ~ s) => Array a -> m (MutableArray s a) Source # copyArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> Array a -> Int -> Int -> m () Source # copyMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> MutableArray s a -> Int -> Int -> m () Source # moveArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> MutableArray s a -> Int -> Int -> m () Source # cloneArr :: Array a -> Int -> Int -> Array a Source # cloneMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> Int -> m (MutableArray s a) Source # resizeMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> m (MutableArray s a) Source # shrinkMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> m () Source # sameMutableArr :: MutableArray s a -> MutableArray s a -> Bool Source # sizeofArr :: Array a -> Int Source # sizeofMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> m Int Source # | |
IsList (Array a) | |
Eq a => Eq (Array a) | |
Data a => Data (Array a) | |
Defined in Data.Primitive.Array gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Array a -> c (Array a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Array a) # toConstr :: Array a -> Constr # dataTypeOf :: Array a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Array a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Array a)) # gmapT :: (forall b. Data b => b -> b) -> Array a -> Array a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Array a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Array a -> r # gmapQ :: (forall d. Data d => d -> u) -> Array a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Array a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Array a -> m (Array a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Array a -> m (Array a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Array a -> m (Array a) # | |
Ord a => Ord (Array a) | |
Read a => Read (Array a) | |
Show a => Show (Array a) | |
Semigroup (Array a) | |
Monoid (Array a) | |
PrimUnlifted (Array a) | |
Defined in Data.Primitive.UnliftedArray toArrayArray# :: Array a -> ArrayArray# # fromArrayArray# :: ArrayArray# -> Array a # | |
type MArr Array Source # | |
Defined in Std.Data.Array | |
type Item (Array a) | |
Defined in Data.Primitive.Array |
data MutableArray s a #
MutableArray | |
|
Instances
Arr MutableArray Array a Source # | |
Defined in Std.Data.Array newArr :: (PrimMonad m, PrimState m ~ s) => Int -> m (MutableArray s a) Source # newArrWith :: (PrimMonad m, PrimState m ~ s) => Int -> a -> m (MutableArray s a) Source # readArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> m a Source # writeArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> a -> m () Source # setArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> Int -> a -> m () Source # indexArr :: Array a -> Int -> a Source # indexArr' :: Array a -> Int -> (#a#) Source # indexArrM :: Monad m => Array a -> Int -> m a Source # freezeArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> Int -> m (Array a) Source # thawArr :: (PrimMonad m, PrimState m ~ s) => Array a -> Int -> Int -> m (MutableArray s a) Source # unsafeFreezeArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> m (Array a) Source # unsafeThawArr :: (PrimMonad m, PrimState m ~ s) => Array a -> m (MutableArray s a) Source # copyArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> Array a -> Int -> Int -> m () Source # copyMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> MutableArray s a -> Int -> Int -> m () Source # moveArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> MutableArray s a -> Int -> Int -> m () Source # cloneArr :: Array a -> Int -> Int -> Array a Source # cloneMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> Int -> m (MutableArray s a) Source # resizeMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> m (MutableArray s a) Source # shrinkMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> Int -> m () Source # sameMutableArr :: MutableArray s a -> MutableArray s a -> Bool Source # sizeofArr :: Array a -> Int Source # sizeofMutableArr :: (PrimMonad m, PrimState m ~ s) => MutableArray s a -> m Int Source # | |
Eq (MutableArray s a) | |
Defined in Data.Primitive.Array (==) :: MutableArray s a -> MutableArray s a -> Bool # (/=) :: MutableArray s a -> MutableArray s a -> Bool # | |
(Typeable s, Typeable a) => Data (MutableArray s a) | |
Defined in Data.Primitive.Array gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> MutableArray s a -> c (MutableArray s a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (MutableArray s a) # toConstr :: MutableArray s a -> Constr # dataTypeOf :: MutableArray s a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (MutableArray s a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (MutableArray s a)) # gmapT :: (forall b. Data b => b -> b) -> MutableArray s a -> MutableArray s a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> MutableArray s a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> MutableArray s a -> r # gmapQ :: (forall d. Data d => d -> u) -> MutableArray s a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> MutableArray s a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> MutableArray s a -> m (MutableArray s a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> MutableArray s a -> m (MutableArray s a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> MutableArray s a -> m (MutableArray s a) # | |
PrimUnlifted (MutableArray s a) | |
Defined in Data.Primitive.UnliftedArray toArrayArray# :: MutableArray s a -> ArrayArray# # fromArrayArray# :: ArrayArray# -> MutableArray s a # | |
type IArr MutableArray Source # | |
Defined in Std.Data.Array |
data SmallArray a #
Instances
data SmallMutableArray s a #
Instances
Arr SmallMutableArray SmallArray a Source # | |
Defined in Std.Data.Array type IArr SmallMutableArray = (ar :: Type -> Type) Source # type MArr SmallArray = (mar :: Type -> Type -> Type) Source # newArr :: (PrimMonad m, PrimState m ~ s) => Int -> m (SmallMutableArray s a) Source # newArrWith :: (PrimMonad m, PrimState m ~ s) => Int -> a -> m (SmallMutableArray s a) Source # readArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> m a Source # writeArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> a -> m () Source # setArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> Int -> a -> m () Source # indexArr :: SmallArray a -> Int -> a Source # indexArr' :: SmallArray a -> Int -> (#a#) Source # indexArrM :: Monad m => SmallArray a -> Int -> m a Source # freezeArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> Int -> m (SmallArray a) Source # thawArr :: (PrimMonad m, PrimState m ~ s) => SmallArray a -> Int -> Int -> m (SmallMutableArray s a) Source # unsafeFreezeArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> m (SmallArray a) Source # unsafeThawArr :: (PrimMonad m, PrimState m ~ s) => SmallArray a -> m (SmallMutableArray s a) Source # copyArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> SmallArray a -> Int -> Int -> m () Source # copyMutableArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> SmallMutableArray s a -> Int -> Int -> m () Source # moveArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> SmallMutableArray s a -> Int -> Int -> m () Source # cloneArr :: SmallArray a -> Int -> Int -> SmallArray a Source # cloneMutableArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> Int -> m (SmallMutableArray s a) Source # resizeMutableArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> m (SmallMutableArray s a) Source # shrinkMutableArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> Int -> m () Source # sameMutableArr :: SmallMutableArray s a -> SmallMutableArray s a -> Bool Source # sizeofArr :: SmallArray a -> Int Source # sizeofMutableArr :: (PrimMonad m, PrimState m ~ s) => SmallMutableArray s a -> m Int Source # sameArr :: SmallArray a -> SmallArray a -> Bool Source # | |
Eq (SmallMutableArray s a) | |
Defined in Data.Primitive.SmallArray (==) :: SmallMutableArray s a -> SmallMutableArray s a -> Bool # (/=) :: SmallMutableArray s a -> SmallMutableArray s a -> Bool # | |
(Typeable s, Typeable a) => Data (SmallMutableArray s a) | |
Defined in Data.Primitive.SmallArray gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SmallMutableArray s a -> c (SmallMutableArray s a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (SmallMutableArray s a) # toConstr :: SmallMutableArray s a -> Constr # dataTypeOf :: SmallMutableArray s a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (SmallMutableArray s a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (SmallMutableArray s a)) # gmapT :: (forall b. Data b => b -> b) -> SmallMutableArray s a -> SmallMutableArray s a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SmallMutableArray s a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SmallMutableArray s a -> r # gmapQ :: (forall d. Data d => d -> u) -> SmallMutableArray s a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> SmallMutableArray s a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> SmallMutableArray s a -> m (SmallMutableArray s a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SmallMutableArray s a -> m (SmallMutableArray s a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SmallMutableArray s a -> m (SmallMutableArray s a) # | |
PrimUnlifted (SmallMutableArray s a) | |
Defined in Data.Primitive.UnliftedArray toArrayArray# :: SmallMutableArray s a -> ArrayArray# # fromArrayArray# :: ArrayArray# -> SmallMutableArray s a # | |
type IArr SmallMutableArray Source # | |
Defined in Std.Data.Array |
uninitialized :: a Source #
Bottom value (throw (
)
for initialize new boxed array(UndefinedElement
"Data.Array.uninitialized")Array
, SmallArray
..).
NOTE: These functions may segfault when used with indices which are out of bounds.
Primitive array type
Instances
data MutablePrimArray s a #
Instances
alignment# :: a -> Int# #
indexByteArray# :: ByteArray# -> Int# -> a #
readByteArray# :: MutableByteArray# s -> Int# -> State# s -> (#State# s, a#) #
writeByteArray# :: MutableByteArray# s -> Int# -> a -> State# s -> State# s #
setByteArray# :: MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s #
indexOffAddr# :: Addr# -> Int# -> a #
readOffAddr# :: Addr# -> Int# -> State# s -> (#State# s, a#) #
writeOffAddr# :: Addr# -> Int# -> a -> State# s -> State# s #
setOffAddr# :: Addr# -> Int# -> Int# -> a -> State# s -> State# s #
Instances
newPinnedPrimArray :: forall m a. (PrimMonad m, Prim a) => Int -> m (MutablePrimArray (PrimState m) a) Source #
Create a pinned byte array of the specified size, The garbage collector is guaranteed not to move it.
newAlignedPinnedPrimArray :: forall m a. (PrimMonad m, Prim a) => Int -> m (MutablePrimArray (PrimState m) a) Source #
Create a pinned primitive array of the specified size and respect given primitive type's alignment. The garbage collector is guaranteed not to move it.
copyMutablePrimArrayToPtr :: (PrimMonad m, Prim a) => Ptr a -> MutablePrimArray (PrimState m) a -> Int -> Int -> m () #
copyPtrToMutablePrimArray :: (PrimMonad m, Prim a) => MutablePrimArray (PrimState m) a -> Int -> Ptr a -> Int -> m () #
primArrayContents :: PrimArray a -> Ptr a Source #
Yield a pointer to the array's data.
This operation is only safe on pinned primitive arrays allocated by newPinnedPrimArray
or
newAlignedPinnedPrimArray
, and you have to make sure the PrimArray
can outlive the Ptr
.
mutablePrimArrayContents :: MutablePrimArray s a -> Ptr a Source #
Yield a pointer to the array's data.
This operation is only safe on pinned primitive arrays allocated by newPinnedPrimArray
or
newAlignedPinnedPrimArray
. and you have to make sure the PrimArray
can outlive the Ptr
.
withPrimArrayContents :: PrimArray a -> (Ptr a -> IO b) -> IO b Source #
Yield a pointer to the array's data and do computation with it.
This operation is only safe on pinned primitive arrays allocated by newPinnedPrimArray
or
newAlignedPinnedPrimArray
.
Don't pass a forever loop to this function, see #14346.
withMutablePrimArrayContents :: MutablePrimArray RealWorld a -> (Ptr a -> IO b) -> IO b Source #
Yield a pointer to the array's data and do computation with it.
This operation is only safe on pinned primitive arrays allocated by newPinnedPrimArray
or
newAlignedPinnedPrimArray
.
Don't pass a forever loop to this function, see #14346.
isPrimArrayPinned :: PrimArray a -> Bool Source #
Check if a primitive array is pinned.
isMutablePrimArrayPinned :: MutablePrimArray s a -> Bool Source #
Check if a mutable primitive array is pinned.
Unlifted array type
data UnliftedArray e #
Instances
data MutableUnliftedArray s e #
Instances
class PrimUnlifted a where #
toArrayArray# :: a -> ArrayArray# #
fromArrayArray# :: ArrayArray# -> a #
Instances
The ArrayException
type
data ArrayException #
Exceptions generated by array operations
IndexOutOfBounds String | An attempt was made to index an array outside its declared bounds. |
UndefinedElement String | An attempt was made to evaluate an element of an array that had not been initialized. |
Instances
Eq ArrayException | Since: base-4.2.0.0 |
Defined in GHC.IO.Exception (==) :: ArrayException -> ArrayException -> Bool # (/=) :: ArrayException -> ArrayException -> Bool # | |
Ord ArrayException | Since: base-4.2.0.0 |
Defined in GHC.IO.Exception compare :: ArrayException -> ArrayException -> Ordering # (<) :: ArrayException -> ArrayException -> Bool # (<=) :: ArrayException -> ArrayException -> Bool # (>) :: ArrayException -> ArrayException -> Bool # (>=) :: ArrayException -> ArrayException -> Bool # max :: ArrayException -> ArrayException -> ArrayException # min :: ArrayException -> ArrayException -> ArrayException # | |
Show ArrayException | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception showsPrec :: Int -> ArrayException -> ShowS # show :: ArrayException -> String # showList :: [ArrayException] -> ShowS # | |
Exception ArrayException | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception |
Cast between primitive arrays
castMutableArray :: (Arr marr arr a, Cast a b) => marr s a -> marr s b Source #