Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
GHC contains three general classes of value types:
- Unboxed types: values are machine values made up of fixed numbers of bytes.
These include types like
Int#
,Char#
andAddr#
. - Unlifted types: values are pointers, but strictly evaluated. These include
types like
MutVar# s a
,Array# a
, andMVar# s a
. - Lifted types: values are pointers, lazily evaluated.
Certain lifted types are really just thin wrappers around unboxed types (we can call
these category 3a) or unlifted pointer types (we can call these category 3b)
Category 3a includes Int
, Char
, and `Ptr a`, while category 3b includes
IORef a
, Data.Primitive.Array.Array a
, and MVar a
.
Types in category 3a can be stored efficiently in a Data.Primitive.PrimArray.PrimArray
,
removing and applying wrappers as required. This module provides the same facility for
types in category 3b.
Synopsis
- data SmallUnliftedArray_ a unlifted_a = SmallUnliftedArray (SmallUnliftedArray# unlifted_a)
- type SmallUnliftedArray a = SmallUnliftedArray_ a (Unlifted a)
- data SmallMutableUnliftedArray_ s a unlifted_a = SmallMutableUnliftedArray (SmallMutableUnliftedArray# s unlifted_a)
- type SmallMutableUnliftedArray s a = SmallMutableUnliftedArray_ s a (Unlifted a)
- newSmallUnliftedArray :: (PrimMonad m, PrimUnlifted a) => Int -> a -> m (SmallMutableUnliftedArray (PrimState m) a)
- unsafeNewSmallUnliftedArray :: PrimMonad m => Int -> m (SmallMutableUnliftedArray (PrimState m) a)
- sizeofSmallUnliftedArray :: SmallUnliftedArray e -> Int
- getSizeofSmallMutableUnliftedArray :: PrimMonad m => SmallMutableUnliftedArray (PrimState m) a -> m Int
- sameSmallMutableUnliftedArray :: SmallMutableUnliftedArray s a -> SmallMutableUnliftedArray s a -> Bool
- shrinkSmallMutableUnliftedArray :: PrimMonad m => SmallMutableUnliftedArray (PrimState m) a -> Int -> m ()
- writeSmallUnliftedArray :: (PrimMonad m, PrimUnlifted a) => SmallMutableUnliftedArray (PrimState m) a -> Int -> a -> m ()
- readSmallUnliftedArray :: (PrimMonad m, PrimUnlifted a) => SmallMutableUnliftedArray (PrimState m) a -> Int -> m a
- indexSmallUnliftedArray :: PrimUnlifted a => SmallUnliftedArray a -> Int -> a
- unsafeFreezeSmallUnliftedArray :: PrimMonad m => SmallMutableUnliftedArray (PrimState m) a -> m (SmallUnliftedArray a)
- freezeSmallUnliftedArray :: PrimMonad m => SmallMutableUnliftedArray (PrimState m) a -> Int -> Int -> m (SmallUnliftedArray a)
- thawSmallUnliftedArray :: PrimMonad m => SmallUnliftedArray a -> Int -> Int -> m (SmallMutableUnliftedArray (PrimState m) a)
- unsafeThawSmallUnliftedArray :: PrimMonad m => SmallUnliftedArray a -> m (SmallMutableUnliftedArray (PrimState m) a)
- setSmallUnliftedArray :: (PrimMonad m, PrimUnlifted a) => SmallMutableUnliftedArray (PrimState m) a -> a -> Int -> Int -> m ()
- copySmallUnliftedArray :: PrimMonad m => SmallMutableUnliftedArray (PrimState m) a -> Int -> SmallUnliftedArray a -> Int -> Int -> m ()
- copySmallMutableUnliftedArray :: PrimMonad m => SmallMutableUnliftedArray (PrimState m) a -> Int -> SmallMutableUnliftedArray (PrimState m) a -> Int -> Int -> m ()
- cloneSmallUnliftedArray :: SmallUnliftedArray a -> Int -> Int -> SmallUnliftedArray a
- cloneSmallMutableUnliftedArray :: PrimMonad m => SmallMutableUnliftedArray (PrimState m) a -> Int -> Int -> m (SmallMutableUnliftedArray (PrimState m) a)
- emptySmallUnliftedArray :: SmallUnliftedArray a
- singletonSmallUnliftedArray :: PrimUnlifted a => a -> SmallUnliftedArray a
- runSmallUnliftedArray :: (forall s. ST s (SmallMutableUnliftedArray s a)) -> SmallUnliftedArray a
- dupableRunSmallUnliftedArray :: (forall s. ST s (SmallMutableUnliftedArray s a)) -> SmallUnliftedArray a
- smallUnliftedArrayToList :: PrimUnlifted a => SmallUnliftedArray a -> [a]
- smallUnliftedArrayFromList :: PrimUnlifted a => [a] -> SmallUnliftedArray a
- smallUnliftedArrayFromListN :: forall a. PrimUnlifted a => Int -> [a] -> SmallUnliftedArray a
- foldrSmallUnliftedArray :: forall a b. PrimUnlifted a => (a -> b -> b) -> b -> SmallUnliftedArray a -> b
- foldrSmallUnliftedArray' :: forall a b. PrimUnlifted a => (a -> b -> b) -> b -> SmallUnliftedArray a -> b
- foldlSmallUnliftedArray :: forall a b. PrimUnlifted a => (b -> a -> b) -> b -> SmallUnliftedArray a -> b
- foldlSmallUnliftedArray' :: forall a b. PrimUnlifted a => (b -> a -> b) -> b -> SmallUnliftedArray a -> b
- foldlSmallUnliftedArrayM' :: (PrimUnlifted a, Monad m) => (b -> a -> m b) -> b -> SmallUnliftedArray a -> m b
- traverseSmallUnliftedArray_ :: (PrimUnlifted a, Applicative m) => (a -> m b) -> SmallUnliftedArray a -> m ()
- itraverseSmallUnliftedArray_ :: (PrimUnlifted a, Applicative m) => (Int -> a -> m b) -> SmallUnliftedArray a -> m ()
- mapSmallUnliftedArray :: (PrimUnlifted a, PrimUnlifted b) => (a -> b) -> SmallUnliftedArray a -> SmallUnliftedArray b
Types
data SmallUnliftedArray_ a unlifted_a Source #
A SmallUnliftedArray_ a unlifted_a
represents an array of values of a
lifted type a
that wrap values of an unlifted type unlifted_a
.
It is expected that unlifted_a ~ Unlifted a
, but imposing that constraint
here would force the type roles to nominal
, which is often undesirable
when arrays are used as components of larger datatypes.
SmallUnliftedArray (SmallUnliftedArray# unlifted_a) |
Instances
type SmallUnliftedArray a = SmallUnliftedArray_ a (Unlifted a) Source #
A type synonym for a SmallUnliftedArray_
containing lifted values of
a particular type. As a general rule, this type synonym should not be used in
class instances—use SmallUnliftedArray_
with an equality constraint instead.
It also should not be used when defining newtypes or datatypes, unless those
will have restrictive type roles regardless—use SmallUnliftedArray_
instead.
data SmallMutableUnliftedArray_ s a unlifted_a Source #
SmallMutableUnliftedArray (SmallMutableUnliftedArray# s unlifted_a) |
Instances
unlifted_a ~ Unlifted a => Eq (SmallMutableUnliftedArray_ s a unlifted_a) Source # | |
Defined in Data.Primitive.Unlifted.SmallArray.ST (==) :: SmallMutableUnliftedArray_ s a unlifted_a -> SmallMutableUnliftedArray_ s a unlifted_a -> Bool # (/=) :: SmallMutableUnliftedArray_ s a unlifted_a -> SmallMutableUnliftedArray_ s a unlifted_a -> Bool # | |
unlifted_a ~ Unlifted a => PrimUnlifted (SmallMutableUnliftedArray_ s a unlifted_a) Source # | |
Defined in Data.Primitive.Unlifted.SmallArray.ST type Unlifted (SmallMutableUnliftedArray_ s a unlifted_a) :: UnliftedType Source # toUnlifted# :: SmallMutableUnliftedArray_ s a unlifted_a -> Unlifted (SmallMutableUnliftedArray_ s a unlifted_a) Source # fromUnlifted# :: Unlifted (SmallMutableUnliftedArray_ s a unlifted_a) -> SmallMutableUnliftedArray_ s a unlifted_a Source # | |
type Unlifted (SmallMutableUnliftedArray_ s a unlifted_a) Source # | |
Defined in Data.Primitive.Unlifted.SmallArray.ST |
type SmallMutableUnliftedArray s a = SmallMutableUnliftedArray_ s a (Unlifted a) Source #
Operations
newSmallUnliftedArray Source #
:: (PrimMonad m, PrimUnlifted a) | |
=> Int | size |
-> a | initial value |
-> m (SmallMutableUnliftedArray (PrimState m) a) |
Creates a new MutableUnliftedArray
with the specified value as initial
contents.
unsafeNewSmallUnliftedArray Source #
:: PrimMonad m | |
=> Int | size |
-> m (SmallMutableUnliftedArray (PrimState m) a) |
Creates a new MutableUnliftedArray
. This function is unsafe because it
initializes all elements of the array as pointers to the empty array. Attempting
to read one of these elements before writing to it is in effect an unsafe
coercion from
to the element type.UnliftedArray
a
sizeofSmallUnliftedArray :: SmallUnliftedArray e -> Int Source #
Yields the length of an UnliftedArray
.
getSizeofSmallMutableUnliftedArray :: PrimMonad m => SmallMutableUnliftedArray (PrimState m) a -> m Int Source #
Yields the length of a MutableUnliftedArray
.
sameSmallMutableUnliftedArray :: SmallMutableUnliftedArray s a -> SmallMutableUnliftedArray s a -> Bool Source #
Determines whether two MutableUnliftedArray
values are the same. This is
object/pointer identity, not based on the contents.
shrinkSmallMutableUnliftedArray :: PrimMonad m => SmallMutableUnliftedArray (PrimState m) a -> Int -> m () Source #
writeSmallUnliftedArray :: (PrimMonad m, PrimUnlifted a) => SmallMutableUnliftedArray (PrimState m) a -> Int -> a -> m () Source #
readSmallUnliftedArray :: (PrimMonad m, PrimUnlifted a) => SmallMutableUnliftedArray (PrimState m) a -> Int -> m a Source #
indexSmallUnliftedArray :: PrimUnlifted a => SmallUnliftedArray a -> Int -> a Source #
unsafeFreezeSmallUnliftedArray :: PrimMonad m => SmallMutableUnliftedArray (PrimState m) a -> m (SmallUnliftedArray a) Source #
Freezes a MutableUnliftedArray
, yielding an UnliftedArray
. This simply
marks the array as frozen in place, so it should only be used when no further
modifications to the mutable array will be performed.
freezeSmallUnliftedArray Source #
:: PrimMonad m | |
=> SmallMutableUnliftedArray (PrimState m) a | source |
-> Int | offset |
-> Int | length |
-> m (SmallUnliftedArray a) |
Freezes a portion of a SmallMutableUnliftedArray
, yielding a SmallUnliftedArray
.
This operation is safe, in that it copies the frozen portion, and the
existing mutable array may still be used afterward.
thawSmallUnliftedArray Source #
:: PrimMonad m | |
=> SmallUnliftedArray a | source |
-> Int | offset |
-> Int | length |
-> m (SmallMutableUnliftedArray (PrimState m) a) |
Thaws a portion of a SmallUnliftedArray
, yielding a SmallMutableUnliftedArray
.
This copies the thawed portion, so mutations will not affect the original
array.
unsafeThawSmallUnliftedArray Source #
:: PrimMonad m | |
=> SmallUnliftedArray a | source |
-> m (SmallMutableUnliftedArray (PrimState m) a) |
Thaw a SmallUnliftedArray
, yielding a SmallMutableUnliftedArray
.
This does not make a copy.
setSmallUnliftedArray Source #
:: (PrimMonad m, PrimUnlifted a) | |
=> SmallMutableUnliftedArray (PrimState m) a | destination |
-> a | value to fill with |
-> Int | offset |
-> Int | length |
-> m () |
copySmallUnliftedArray Source #
:: PrimMonad m | |
=> SmallMutableUnliftedArray (PrimState m) a | destination |
-> Int | offset into destination |
-> SmallUnliftedArray a | source |
-> Int | offset into source |
-> Int | number of elements to copy |
-> m () |
Copies the contents of an immutable array into a mutable array.
copySmallMutableUnliftedArray Source #
:: PrimMonad m | |
=> SmallMutableUnliftedArray (PrimState m) a | destination |
-> Int | offset into destination |
-> SmallMutableUnliftedArray (PrimState m) a | source |
-> Int | offset into source |
-> Int | number of elements to copy |
-> m () |
Copies the contents of one mutable array into another.
cloneSmallUnliftedArray Source #
:: SmallUnliftedArray a | source |
-> Int | offset |
-> Int | length |
-> SmallUnliftedArray a |
Creates a copy of a portion of a SmallUnliftedArray_
cloneSmallMutableUnliftedArray Source #
:: PrimMonad m | |
=> SmallMutableUnliftedArray (PrimState m) a | source |
-> Int | offset |
-> Int | length |
-> m (SmallMutableUnliftedArray (PrimState m) a) |
Creates a new MutableUnliftedArray
containing a copy of a portion of
another mutable array.
singletonSmallUnliftedArray :: PrimUnlifted a => a -> SmallUnliftedArray a Source #
runSmallUnliftedArray :: (forall s. ST s (SmallMutableUnliftedArray s a)) -> SmallUnliftedArray a Source #
Execute a stateful computation and freeze the resulting array.
dupableRunSmallUnliftedArray :: (forall s. ST s (SmallMutableUnliftedArray s a)) -> SmallUnliftedArray a Source #
Execute a stateful computation and freeze the resulting array. It is possible, but unlikely, that the computation will be run multiple times in multiple threads.
List Conversion
smallUnliftedArrayToList :: PrimUnlifted a => SmallUnliftedArray a -> [a] Source #
Convert the unlifted array to a list.
smallUnliftedArrayFromList :: PrimUnlifted a => [a] -> SmallUnliftedArray a Source #
smallUnliftedArrayFromListN :: forall a. PrimUnlifted a => Int -> [a] -> SmallUnliftedArray a Source #
Folding
foldrSmallUnliftedArray :: forall a b. PrimUnlifted a => (a -> b -> b) -> b -> SmallUnliftedArray a -> b Source #
foldrSmallUnliftedArray' :: forall a b. PrimUnlifted a => (a -> b -> b) -> b -> SmallUnliftedArray a -> b Source #
Strict right-associated fold over the elements of an 'SmallUnliftedArray.
foldlSmallUnliftedArray :: forall a b. PrimUnlifted a => (b -> a -> b) -> b -> SmallUnliftedArray a -> b Source #
Lazy left-associated fold over the elements of an SmallUnliftedArray_
.
foldlSmallUnliftedArray' :: forall a b. PrimUnlifted a => (b -> a -> b) -> b -> SmallUnliftedArray a -> b Source #
Strict left-associated fold over the elements of an SmallUnliftedArray_
.
foldlSmallUnliftedArrayM' :: (PrimUnlifted a, Monad m) => (b -> a -> m b) -> b -> SmallUnliftedArray a -> m b Source #
Strict effectful left-associated fold over the elements of an SmallUnliftedArray_
.
Traversals
traverseSmallUnliftedArray_ :: (PrimUnlifted a, Applicative m) => (a -> m b) -> SmallUnliftedArray a -> m () Source #
Effectfully traverse the elements of an SmallUnliftedArray_
, discarding
the resulting values.
itraverseSmallUnliftedArray_ :: (PrimUnlifted a, Applicative m) => (Int -> a -> m b) -> SmallUnliftedArray a -> m () Source #
Effectful indexed traversal of the elements of an SmallUnliftedArray_
,
discarding the resulting values.
Mapping
mapSmallUnliftedArray :: (PrimUnlifted a, PrimUnlifted b) => (a -> b) -> SmallUnliftedArray a -> SmallUnliftedArray b Source #
Map over the elements of an SmallUnliftedArray_
.