| Safe Haskell | None |
|---|
Foreign.Marshal.StaticArray
Contents
Description
This module defines StaticArray, a simple wrapper around arrays with
their dimensions in the type. StaticArray provides Storable
instances using the type-level dimensions. This eases writing FFI
bindings to fixed-size native arrays. For example, has a StaticArray
UArray 10 CIntStorable instance that is directly
compatible with int foo[10] in native code.
Multidimensional native arrays are also supported. is compatible with StaticArray
UArray '(10,20,100) CUCharunsigned char
foo[10][20][100]. Note the leading ' before the tuple containing
the dimensions. It marks it as a DataKinds promoted tuple, necessary
to store the dimensions.
To operate on the contents of a StaticArray, use
toArray. toArray returns the backing array with the correct type
and index values already in place. For example, the result of
toArray on a is a
StaticArray UArray '(10,20,100) CUChar with its bounds set to
UArray (Int, Int, Int) CUChar((0,0,0),(9,19,99)).
- data StaticArray backing dimensions elements
- toArray :: StaticArray backing dimensions elements -> backing (Index dimensions) elements
- staticBounds :: forall b d e. IxStatic d => StaticArray b d e -> (Index d, Index d)
- staticArray :: (IArray b e, IxStatic d) => [(Index d, e)] -> StaticArray b d e
- listStaticArray :: (IxStatic d, IArray b e) => [e] -> StaticArray b d e
Basic interface
data StaticArray backing dimensions elements Source
A minimal array wrapper that encodes the full dimensions of the array in the type. Intended for interfacing with (possibly-)multidimensional arrays of fixed size in native code.
The constructor is not exported to prevent creating a StaticArray
with a size that doesn't match its dimensions.
Instances
| Eq (backing (Index k dimensions) elements) => Eq (StaticArray k backing dimensions elements) | |
| (IArray b e, IxStatic k d, Show e) => Show (StaticArray k b d e) | |
| (IxStatic k d, Storable e, IArray UArray e, MArray IOUArray e IO) => Storable (StaticArray k UArray d e) | |
| (IxStatic k d, Storable e, IArray b e) => Storable (StaticArray k b d e) |
toArray :: StaticArray backing dimensions elements -> backing (Index dimensions) elementsSource
Returns the backing value of this StaticArray.
staticBounds :: forall b d e. IxStatic d => StaticArray b d e -> (Index d, Index d)Source
Get the compile-time bounds from a StaticArray. Does not examine its
argument.
staticArray :: (IArray b e, IxStatic d) => [(Index d, e)] -> StaticArray b d eSource
Create a new StaticArray from a list of indices and
elements. This has all the semantic caveats of array, except that
the bounds are as good as those provided by the IxStatic
instance.
listStaticArray :: (IxStatic d, IArray b e) => [e] -> StaticArray b d eSource
Create a new StaticArray from a list of elements in index
order. Implemented in terms of listArray, with the same caveats.