Safe Haskell | None |
---|
This module defines StaticVector
, a simple wrapper around
Vector
with the dimensions in the type. StaticVector
provides a
Storable
instance using the type-level dimensions. This eases
writing FFI bindings to fixed-size native arrays.
Support for interop with multi-dimensional native arrays is provided
via the IxStatic
class. This results in the slightly unnatural case
where you might need to convert Ix
coordinates to Vector
indices, but it felt like an acceptable tradeoff when interfacing with
multi-dimensional native arrays.
- data StaticVector backing dimensions elements
- toVector :: StaticVector backing dimensions elements -> backing elements
- staticBounds :: forall b d e. IxStatic d => StaticVector b d e -> (Index d, Index d)
- staticSize :: IxStatic d => StaticVector b d e -> Int
- fromList :: (Vector b e, IxStatic d) => [e] -> StaticVector b d e
Documentation
data StaticVector backing dimensions elements Source
A minimal Vector
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.
If this is used with multidimensional arrays, it will be up to
users to deal with converting Ix
coordinates to internal
Vector
indices.
The constructor is not exported to prevent creating a
StaticVector
with a size that doesn't match its dimensions.
Eq (backing elements) => Eq (StaticVector k backing dimensions elements) | |
(Vector b e, Show e) => Show (StaticVector k b d e) | |
(IxStatic k d, Storable e) => Storable (StaticVector k Vector d e) | |
(IxStatic k d, Storable e, Vector b e) => Storable (StaticVector k b d e) |
toVector :: StaticVector backing dimensions elements -> backing elementsSource
Returns the backing value of this StaticVector
.
staticBounds :: forall b d e. IxStatic d => StaticVector b d e -> (Index d, Index d)Source
Get the compile-time bounds from a StaticVector
. Does not
examine its argument.
staticSize :: IxStatic d => StaticVector b d e -> IntSource
Get the compile-time size from a StaticVector
. Does not examine
its argument.
fromList :: (Vector b e, IxStatic d) => [e] -> StaticVector b d eSource
Create a new StaticVector
with the contents of the list. If the
list passed in contains too many elements, the result will be
truncated. If it contains too few elements, they will be cycled to
pad out the remaining space. If it contains 0 elements, this will
result in an error.