Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module provides an unlifted mutable array with a pure interface. Though the array itself is unlifted, it's elements are lifted types. This is made possible by using linear types to make sure array references are single threaded through reads and writes.
Accessing out-of-bounds indices causes undefined behaviour.
This module is meant to be imported qualified.
Synopsis
- data Array# a
- unArray# :: (MutableArray# RealWorld a -> b) -> Array# a %1 -> Ur b
- alloc :: Int -> a -> (Array# a %1 -> Ur b) %1 -> Ur b
- allocBeside :: Int -> a -> Array# b %1 -> (# Array# a, Array# b #)
- lseq :: Array# a %1 -> b %1 -> b
- size :: Array# a %1 -> (# Ur Int, Array# a #)
- get :: Int -> Array# a %1 -> (# Ur a, Array# a #)
- set :: Int -> a -> Array# a %1 -> Array# a
- copyInto :: Int -> Array# a %1 -> Array# a %1 -> (# Array# a, Array# a #)
- map :: (a -> b) -> Array# a %1 -> Array# b
- toList :: Array# a %1 -> Ur [a]
- freeze :: (Array# a -> b) -> Array# a %1 -> Ur b
- dup2 :: Array# a %1 -> (# Array# a, Array# a #)
Documentation
unArray# :: (MutableArray# RealWorld a -> b) -> Array# a %1 -> Ur b Source #
Extract the underlying MutableArray#
, consuming the Array#
in process.
alloc :: Int -> a -> (Array# a %1 -> Ur b) %1 -> Ur b Source #
Allocate a mutable array of given size using a default value.
The size should be non-negative.
allocBeside :: Int -> a -> Array# b %1 -> (# Array# a, Array# b #) Source #
Allocate a mutable array of given size using a default value,
using another Array#
as a uniqueness proof.
The size should be non-negative.
lseq :: Array# a %1 -> b %1 -> b infixr 0 Source #
Consume an Array#
.
Note that we can not implement a Consumable
instance because Array#
is unlifted.
copyInto :: Int -> Array# a %1 -> Array# a %1 -> (# Array# a, Array# a #) Source #
Copy the first mutable array into the second mutable array, starting from the given index of the source array.
It copies fewer elements if the second array is smaller than the
first. n
should be within [0..size src).
copyInto n src dest: dest[i] = src[n+i] for i < size dest, i < size src + n