linear-base-0.1.0: Standard library for linear types.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Array.Mutable.Unlifted.Linear

Description

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

Documentation

data Array# a Source #

A mutable array holding as

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 Source #

Consume an Array#.

Note that we can not implement a Consumable instance because Array# is unlifted.

size :: Array# a %1 -> (# Ur Int, Array# a #) Source #

get :: Int -> Array# a %1 -> (# Ur a, Array# a #) Source #

set :: Int -> a -> Array# a %1 -> Array# a Source #

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

map :: (a -> b) -> Array# a %1 -> Array# b Source #

toList :: Array# a %1 -> Ur [a] Source #

Return the array elements as a lazy list.

freeze :: (Array# a -> b) -> Array# a %1 -> Ur b Source #

O(1) Convert an Array# to an immutable Array#.

dup2 :: Array# a %1 -> (# Array# a, Array# a #) Source #

Clone an array.