The Contiguous typeclass as an interface to a multitude of contiguous structures.
Some functions do not make sense on slices; for those, see ContiguousU.
Associated types
type family Mutable (arr :: Type -> Type) :: Type -> Type -> TypeThe Mutable counterpart to the array.
type family Element (arr :: Type -> Type) :: Type -> ConstraintThe constraint needed to store elements in the array.
type family Sliced (arr :: Type -> Type) :: Type -> TypeThe slice type of this array. The slice of a raw array type
tshould be 'Slice t', whereas the slice of a slice should be the same slice type.type family MutableSliced (arr :: Type -> Type) :: Type -> Type -> TypeThe mutable slice type of this array. The mutable slice of a raw array type
tshould be 'MutableSlice t', whereas the mutable slice of a mutable slice should be the same slice type.
Methods
new :: (PrimMonad m, Element arr b) => Int -> m (Mutable arr (PrimState m) b)Allocate a new mutable array of the given size.
replicateMut :: (PrimMonad m, Element arr b) => Int -> b -> m (Mutable arr (PrimState m) b)replicateMut n xis a mutable array of lengthnwithxthe value of every element.shrink :: (PrimMonad m, Element arr a) => Mutable arr (PrimState m) a -> Int -> m (Mutable arr (PrimState m) a)Resize an array without growing it.
empty :: arr aThe empty array.
singleton :: Element arr a => a -> arr aCreate a singleton array.
doubleton :: Element arr a => a -> a -> arr aCreate a doubleton array.
tripleton :: Element arr a => a -> a -> a -> arr aCreate a tripleton array.
quadrupleton :: Element arr a => a -> a -> a -> a -> arr aCreate a quadrupleton array.
quintupleton :: Element arr a => a -> a -> a -> a -> a -> arr aCreate a quintupleton array.
sextupleton :: Element arr a => a -> a -> a -> a -> a -> a -> arr aCreate a sextupleton array.
index :: Element arr b => arr b -> Int -> bIndex into an array at the given index.
index# :: Element arr b => arr b -> Int -> (# b #)Index into an array at the given index, yielding an unboxed one-tuple of the element.
indexM :: (Element arr b, Monad m) => arr b -> Int -> m bIndexing in a monad.
The monad allows operations to be strict in the array when necessary. Suppose array copying is implemented like this:
copy mv v = ... write mv i (v ! i) ...For lazy arrays,
v ! iwould not be not be evaluated, which means thatmvwould unnecessarily retain a reference tovin each element written.With indexM, copying can be implemented like this instead:
copy mv v = ... do x <- indexM v i write mv i xHere, no references to
vare retained because indexing (but not the elements) is evaluated eagerly.read :: (PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> m bRead a mutable array at the given index.
write :: (PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> b -> m ()Write to a mutable array at the given index.
null :: arr b -> BoolTest whether the array is empty.
size :: Element arr b => arr b -> IntThe size of the array
sizeMut :: (PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> m IntThe size of the mutable array
equals :: (Element arr b, Eq b) => arr b -> arr b -> BoolTest the two arrays for equality.
equalsMut :: Mutable arr s a -> Mutable arr s a -> BoolTest the two mutable arrays for pointer equality. Does not check equality of elements.
slice :: Element arr a => arr a -> Int -> Int -> Sliced arr aCreate a Slice of an array.
O(1).sliceMut :: Element arr a => Mutable arr s a -> Int -> Int -> MutableSliced arr s aCreate a MutableSlice of a mutable array.
O(1).toSlice :: Element arr a => arr a -> Sliced arr aCreate a Slice that covers the entire array.
toSliceMut :: (PrimMonad m, Element arr a) => Mutable arr (PrimState m) a -> m (MutableSliced arr (PrimState m) a)Create a MutableSlice that covers the entire array.
clone :: Element arr b => Sliced arr b -> arr bClone a slice of an array.
clone_ :: Element arr a => arr a -> Int -> Int -> arr aClone a slice of an array without using the Slice type. These methods are required to implement 'Contiguous (Slice arr)' for any `Contiguous arr`; they are not really meant for direct use.
cloneMut :: (PrimMonad m, Element arr b) => MutableSliced arr (PrimState m) b -> m (Mutable arr (PrimState m) b)Clone a slice of a mutable array.
cloneMut_ :: (PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Int -> m (Mutable arr (PrimState m) b)Clone a slice of a mutable array without using the MutableSlice type. These methods are required to implement 'Contiguous (Slice arr)' for any `Contiguous arr`; they are not really meant for direct use.
freeze :: (PrimMonad m, Element arr a) => MutableSliced arr (PrimState m) a -> m (arr a)Turn a mutable array slice an immutable array by copying.
freeze_ :: (PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Int -> m (arr b)Turn a slice of a mutable array into an immutable one with copying, without using the MutableSlice type. These methods are required to implement 'Contiguous (Slice arr)' for any `Contiguous arr`; they are not really meant for direct use.
unsafeFreeze :: (PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> m (arr b)Turn a mutable array into an immutable one without copying. The mutable array should not be used after this conversion.
unsafeShrinkAndFreeze :: (PrimMonad m, Element arr a) => Mutable arr (PrimState m) a -> Int -> m (arr a)thaw :: (PrimMonad m, Element arr b) => Sliced arr b -> m (Mutable arr (PrimState m) b)Copy a slice of an immutable array into a new mutable array.
thaw_ :: (PrimMonad m, Element arr b) => arr b -> Int -> Int -> m (Mutable arr (PrimState m) b)Copy a slice of an immutable array into a new mutable array without using the Slice type. These methods are required to implement 'Contiguous (Slice arr)' for any `Contiguous arr`; they are not really meant for direct use.
copy :: (PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Sliced arr b -> m ()Copy a slice of an array into a mutable array.
copy_ :: (PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> arr b -> Int -> Int -> m ()Copy a slice of an array into a mutable array without using the Slice type. These methods are required to implement 'Contiguous (Slice arr)' for any `Contiguous arr`; they are not really meant for direct use.
copyMut :: (PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> MutableSliced arr (PrimState m) b -> m ()Copy a slice of a mutable array into another mutable array. In the case that the destination and source arrays are the same, the regions may overlap.
copyMut_ :: (PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Mutable arr (PrimState m) b -> Int -> Int -> m ()Copy a slice of a mutable array into another mutable array without using the Slice type. These methods are required to implement 'Contiguous (Slice arr)' for any `Contiguous arr`; they are not really meant for direct use.
insertAt :: Element arr b => arr b -> Int -> b -> arr bCopy a slice of an array and then insert an element into that array.
The default implementation performs a memset which would be unnecessary except that the garbage collector might trace the uninitialized array.
Was previously
insertSlicing@since 0.6.0rnf :: (NFData a, Element arr a) => arr a -> ()Reduce the array and all of its elements to WHNF.
run :: (forall s. ST s (arr a)) -> arr aRun an effectful computation that produces an array.
Instances5Contiguous
Contiguous ArrayDefined in contiguous-0.6.4.2 · Data.Primitive.Contiguous.ClassContiguous PrimArrayDefined in contiguous-0.6.4.2 · Data.Primitive.Contiguous.ClassContiguous SmallArrayDefined in contiguous-0.6.4.2 · Data.Primitive.Contiguous.ClassContiguous (UnliftedArray_ unlifted_a)Defined in contiguous-0.6.4.2 · Data.Primitive.Contiguous.ClassContiguousU arr => Contiguous (Slice arr)Defined in contiguous-0.6.4.2 · Data.Primitive.Contiguous.Class