Data.Array.Vanilla.Unsafe
Description
Two flavours of array: mutable and immutable. All are boxed, lazy, and use zero-origin integers as indicies.
- data IArray x
- data MArray s x
- marray_new :: Int -> x -> ST s (MArray s x)
- marray_read :: MArray s x -> Int -> ST s x
- marray_write :: MArray s x -> Int -> x -> ST s ()
- marray_freeze :: MArray s x -> ST s (IArray x)
- iarray_thaw :: IArray x -> ST s (MArray s x)
- iarray_read :: IArray x -> Int -> x
Documentation
The type of mutable arrays, with elements of type x
.
These arrays live in the ST
monad, but you can use
stToIO
to convert this to IO
if required.
Two MArray
s are equal as per (==)
if they are both
the exact same array (i.e., the same block of RAM).
Two seperate arrays which merely hold the same data are
not considered equal. (This fact could change at any
second, after all.)
marray_new :: Int -> x -> ST s (MArray s x)Source
Create a brand new MArray
, of the specified size, with
all elements set to the value provided. If the array
size is n
, valid indicies are from 0
to n-1
.
marray_read :: MArray s x -> Int -> ST s xSource
Read from an MArray
.
Unsafe: No bounds checks. Indicies below 0
or
above n-1
will likely result in a program crash.
marray_write :: MArray s x -> Int -> x -> ST s ()Source
Write to an MArray
, replacing the element at the
specified index.
Unsafe: No bounds checks. Indicies below 0
or
above n-1
will likely result in a program crash
(if you're lucky), or weird data corruption
(if you're unlucky).
marray_freeze :: MArray s x -> ST s (IArray x)Source
Create a new IArray
which refers to the same memory
block as an existing MArray
.
Unsafe: Mutating the MArray
will cause the contents
of the IArray
to mutate also, violating referential
transparency. (Avoid this by explicitly copying the data
before freezing.)
iarray_thaw :: IArray x -> ST s (MArray s x)Source
Create a new MArray
which refers to the same memory
block as an existing IArray
.
Unsafe: Mutating the MArray
will cause the contents
of the IArray
to mutate also, violating referential
transparency. (Avoid this by explicitly copying the data
after thawing and before mutating it.)
iarray_read :: IArray x -> Int -> xSource
Read from an IArray
. (Since IArrays
are immutable,
this is a pure operation.)
Unsafe: No bounds checks. Indicies below 0
or
above n-1
will likely result in a program crash.