This module defines
StaticArray, a simple wrapper around instances
IArray with its dimensions encoded in the type.
Storable instance that uses the type-level dimensions,
and significantly eases writing FFI bindings to fixed-size native
arrays. For example,
UArray 10 CInt
instance that is directly compatible with
int foo in native
Multidimensional native arrays are also supported.
is compatible with
UArray '(10,20,100) CUChar
foo. 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
toArray returns the backing array with the correct type
and index values already in place. For example, the result of
toArray on a
UArray '(10,20,100) CUChar
with its bounds set to
UArray (Int, Int, Int) CUChar
- data StaticArray backing dimensions elements
- type family Mutable a :: * -> * -> *
- toArray :: StaticArray backing dimensions elements -> backing (Bound dimensions) elements
- staticArray :: (Ix (Bound d), IArray b e, StaticSize d) => [(Bound d, e)] -> StaticArray b d e
- listStaticArray :: (StaticSize d, Ix (Bound d), IArray b e) => [e] -> StaticArray b d e
- class StaticSize d where
- fromNat :: forall proxy n. SingI n => proxy n -> Int
A minimal wrapper for instances of
IArray 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.
Mutable type family is used to associate instances of
IArray with instances of
MArray that give non-copying
unsafeFreeze. This is used to increase the efficiency of
If you're using an instance of
IArray other than
UArray, you'll need to add a type instance for your type. If it
unsafeFreeze, the type instance should
return the type constructor for the appropriate
instance. Otherwise, just have it return
This class connects dimension description types with
index types and values.
This module contains instances for types of kind
Nat, types of
the promoted kind '[
Nat], and promoted tuples of
Nat values up
to 13 elements. For instances not relying on promoted data types,
see the Foreign.Marshal.StaticArray.Unpromoted module.
The concrete bounds for an array of this dimensionality. Implementations of this function should not examine their argument in any way.
A conversion function for converting type-level naturals to
value-level. This is being exposed to aid in the creation of
StaticSize instances for those who might desire to do
Haddock is currently eating the important qualification that the
n must have the kind
SingI instance is
automatically fulfilled for all types of kind
Nat. Its explicit
presence in the signature is an artifact of how GHC implements
dictionary passing and type erasure.