Safe Haskell | None |
---|---|

Language | Haskell2010 |

This provides an interface to working with boxed arrays
with elements of type `Maybe a`

. That is:

MaybeArray a ≅ Array (Maybe a)

However, this type provided by this module is more efficient
than its naive `Array`

counterpart. It consumes less
memory and has fewer heap indirections.

## Synopsis

- data MaybeArray a
- data MutableMaybeArray s a
- indexMaybeArray :: MaybeArray a -> Int -> Maybe a
- newMaybeArray :: PrimMonad m => Int -> Maybe a -> m (MutableMaybeArray (PrimState m) a)
- readMaybeArray :: PrimMonad m => MutableMaybeArray (PrimState m) a -> Int -> m (Maybe a)
- writeMaybeArray :: PrimMonad m => MutableMaybeArray (PrimState m) a -> Int -> Maybe a -> m ()
- sequenceMaybeArray :: MaybeArray a -> Maybe (Array a)
- unsafeFreezeMaybeArray :: PrimMonad m => MutableMaybeArray (PrimState m) a -> m (MaybeArray a)
- thawMaybeArray :: PrimMonad m => MaybeArray a -> Int -> Int -> m (MutableMaybeArray (PrimState m) a)
- maybeArrayFromList :: [a] -> MaybeArray a
- maybeArrayFromListN :: Int -> [a] -> MaybeArray a
- sizeofMaybeArray :: MaybeArray a -> Int

# Documentation

data MaybeArray a Source #

An immutable array of boxed values of type

.`Maybe`

a

## Instances

data MutableMaybeArray s a Source #

A mutable array of boxed values of type

.`Maybe`

a

## Instances

PrimUnlifted (MutableMaybeArray s a) Source # | |

Defined in Data.Primitive.Array.Maybe toArrayArray# :: MutableMaybeArray s a -> ArrayArray# # fromArrayArray# :: ArrayArray# -> MutableMaybeArray s a # |

indexMaybeArray :: MaybeArray a -> Int -> Maybe a Source #

Get the `Maybe`

value at the given index out of a `MaybeArray`

.

newMaybeArray :: PrimMonad m => Int -> Maybe a -> m (MutableMaybeArray (PrimState m) a) Source #

Create a new `MutableMaybeArray`

of the given size and initialize all elements
with the given `Maybe`

value.

readMaybeArray :: PrimMonad m => MutableMaybeArray (PrimState m) a -> Int -> m (Maybe a) Source #

Get the `Maybe`

value at the given index out of a `MutableMaybeArray`

.

writeMaybeArray :: PrimMonad m => MutableMaybeArray (PrimState m) a -> Int -> Maybe a -> m () Source #

Write a `Maybe`

value to the given index of a `MutableMaybeArray`

.

sequenceMaybeArray :: MaybeArray a -> Maybe (Array a) Source #

This is like calling `sequence`

on an `Array`

. However, in
the event that all the values are `Just`

, it does not need
to allocate a new array since the array backing the `MaybeArray`

can be reused.

unsafeFreezeMaybeArray :: PrimMonad m => MutableMaybeArray (PrimState m) a -> m (MaybeArray a) Source #

Convert a `MutableMaybeArray`

to an immutable one without copying.
The array should not be modified after the conversion.

:: PrimMonad m | |

=> MaybeArray a | source |

-> Int | offset |

-> Int | length |

-> m (MutableMaybeArray (PrimState m) a) |

Create a `MutablePrimArray`

from a slice of an immutable array.
This operation makes a copy of the specified slice, so it is safe
to use the immutable array afterward.

maybeArrayFromList :: [a] -> MaybeArray a Source #

Given a list of `a`

, build a `MaybeArray`

from
the values in the list.

maybeArrayFromListN :: Int -> [a] -> MaybeArray a Source #

Given the length of a list and a list of `a`

,
build a `MaybeArray`

from the values in the list.
If the given `Int`

does not match the length of
the list, this function calls `error`

.
You should prefer this to `maybeArrayFromList`

if
the length of the list has already been computed.

sizeofMaybeArray :: MaybeArray a -> Int Source #

Yield the size of the `MaybeArray`

.