Safe Haskell | None |
---|
This module exposes FixedStorableArray
, a simple wrapper around
StorableArray
that uses the DataKinds
extension to get type-level
numeric literals. These allow dimensions to be fully set by the type
at compile time. This has the added benefit of providing a Storable
instance that significantly eases writing FFI bindings to fixed-size
native arrays.
For example,
has
a FixedStorableArray
(N
10) CIntStorable
instance that is directly compatible with int foo[10]
in native code.
Multidimensional native arrays are also
supported.
is compatible with FixedStorableArray
(N
10, N
20, N
100) CUCharunsigned char foo[10][20][100]
.
Other than the Storable
instance, newFixedStorableArray
, and
newFixedStorableArray_
, the only way to work with a
FixedStorableArray
is to use toStorableArray
and operate on the
underlying StorableArray
. toStorableArray
generates a
StorableArray
with the correct type and index values already in
place. For instance, the result of toStorableArray
on a
is a
FixedStorableArray
(N
10, N
20, N
100) CUChar
with its bounds set
to StorableArray
(Int, Int, Int) CUChar((0,0,0),(9,19,99))
.
- data FixedStorableArray dimensions e
- newFixedStorableArray :: (Bounds d, Ix (Bound d), Storable e) => e -> IO (FixedStorableArray d e)
- newFixedStorableArray_ :: (Bounds d, Ix (Bound d), Storable e) => IO (FixedStorableArray d e)
- toStorableArray :: FixedStorableArray dimensions e -> StorableArray (Bound dimensions) e
- data N n = N
- fromNat :: forall proxy n. SingI n => proxy n -> Int
- class Bounds d where
- type Bound d :: *
- bounds :: FixedStorableArray d e -> (Bound d, Bound d)
Documentation
data FixedStorableArray dimensions e Source
A minimal wrapper for StorableArray
that encodes the full
dimensions of the array in the type. Intended for interfacing with
(possibly-)multidimensional arrays of fixed size in native code. To
get most functionality, use toStorableArray
.
newFixedStorableArray :: (Bounds d, Ix (Bound d), Storable e) => e -> IO (FixedStorableArray d e)Source
Create a FixedStorableArray
and populate it with copies of the
element passed in. Dimensions will be determined from the return
type.
newFixedStorableArray_ :: (Bounds d, Ix (Bound d), Storable e) => IO (FixedStorableArray d e)Source
Create a FixedStorableArray
and don't populate it with anything
in particular. Contents may or may not be initialized to anything
at all. Dimensions will be determined from the return type.
toStorableArray :: FixedStorableArray dimensions e -> StorableArray (Bound dimensions) eSource
Returns the backing StorableArray
of this
FixedStorableArray
. The backing array is shared across
all invocations of this. Modifications to it will be seen
across all uses of this FixedStorableArray
.
This is a simple proxy type for type-level naturals. All dimension types use this type to store the size along that dimension.
Enum (N n) | |
Eq (N n) | |
Ord (N n) | |
SingI Nat n => Show (N n) | |
SingI Nat a => Bounds (N a) | |
(SingI Nat a, SingI Nat b) => Bounds (N a, N b) | |
(SingI Nat a, SingI Nat b, SingI Nat c) => Bounds (N a, N b, N c) | |
(SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d) => Bounds (N a, N b, N c, N d) | |
(SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e) => Bounds (N a, N b, N c, N d, N e) | |
(SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e, SingI Nat f) => Bounds (N a, N b, N c, N d, N e, N f) | |
(SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e, SingI Nat f, SingI Nat g) => Bounds (N a, N b, N c, N d, N e, N f, N g) | |
(SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e, SingI Nat f, SingI Nat g, SingI Nat h) => Bounds (N a, N b, N c, N d, N e, N f, N g, N h) | |
(SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e, SingI Nat f, SingI Nat g, SingI Nat h, SingI Nat i) => Bounds (N a, N b, N c, N d, N e, N f, N g, N h, N i) | |
(SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e, SingI Nat f, SingI Nat g, SingI Nat h, SingI Nat i, SingI Nat j) => Bounds (N a, N b, N c, N d, N e, N f, N g, N h, N i, N j) | |
(SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e, SingI Nat f, SingI Nat g, SingI Nat h, SingI Nat i, SingI Nat j, SingI Nat k) => Bounds (N a, N b, N c, N d, N e, N f, N g, N h, N i, N j, N k) | |
(SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e, SingI Nat f, SingI Nat g, SingI Nat h, SingI Nat i, SingI Nat j, SingI Nat k, SingI Nat l) => Bounds (N a, N b, N c, N d, N e, N f, N g, N h, N i, N j, N k, N l) | |
(SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e, SingI Nat f, SingI Nat g, SingI Nat h, SingI Nat i, SingI Nat j, SingI Nat k, SingI Nat l, SingI Nat m) => Bounds (N a, N b, N c, N d, N e, N f, N g, N h, N i, N j, N k, N l, N m) |
This class connects dimension descriptions with StorableArray
index types and values.
bounds :: FixedStorableArray d e -> (Bound d, Bound d)Source
The concrete bounds for this dimension