-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Statically-sized array wrappers with Storable instances
for FFI marshaling
--
-- Uses type-level numeric literals to wrap arrays in a type that
-- statically fixes their size. The wrapper has a Storable
-- instance, for easy integration with fixed-size native arrays.
@package storable-static-array
@version 0.6.0.0
-- | IxStatic is a class that uses type-level constraints to
-- generate the values used by an Ix instance.
--
-- This module contains instances of IxStatic for types of kind
-- Nat, types of the promoted kind '[Nat], and promoted
-- tuples of Nat up to 5 elements. This is the largest size of
-- tuple that has an Ix instance.
--
-- There are also data types provided to simulate promoted tuples and
-- lists. These are less syntactically pleasant to use, but are sometimes
-- helpful. In particular, the single ' used by promoted types
-- can interfere with CPP operation, so alternate means of
-- specifying multiple dimensions are provided.
module Data.Ix.Static
-- | This class connects dimension description types with IArray
-- index types and values.
class Ix (Index d) => IxStatic d where type family Index d :: *
taggedBounds :: IxStatic d => Tagged d (Index d, Index d)
-- | A conversion function for converting type-level naturals to
-- value-level. This is being exposed to aid in the creation of
-- additional IxStatic instances for those who might desire to do
-- so.
--
-- Haddock is currently eating the important qualification that the type
-- variable n must have the kind Nat. The 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.
fromNat :: SingI n => proxy n -> Int
-- | :. is provided as an alternative means of constructing a
-- type-level list of dimensions. DataKinds-promoted lists are
-- also supported and easier to use in almost all cases. The exception is
-- when CPP is involved, when a single ' on a line
-- causes CPP to fail.
--
-- With TypeOperators and DataKinds enabled,
-- StaticArray UArray (2:.10:.25:.Nil)
-- Int is equivalent to StaticArray
-- UArray '[2,10,25] Int and both wrap a
-- UArray (Int,(Int,Int))
-- Int with bounds ((0,(0,0)),(1,(9,24))).
--
-- Neither promoted lists nor this approach support creating
-- 0-dimensional arrays, because they make no sense with Storable.
data (:.) a b
-- | Nil is the terminator for type-level lists created with
-- :.
data Nil
-- | An alternative dimension type to promoted pairs, provided for
-- syntactic compatibility with CPP.
data D2 (a :: Nat) (b :: Nat)
-- | An alternative dimension type to promoted triples, provided for
-- syntactic compatibility with CPP.
data D3 (a :: Nat) (b :: Nat) (c :: Nat)
-- | An alternative dimension type to promoted 4-tuples, provided for
-- syntactic compatibility with CPP.
data D4 (a :: Nat) (b :: Nat) (c :: Nat) (d :: Nat)
-- | An alternative dimension type to promoted 5-tuples, provided for
-- syntactic compatibility with CPP.
data D5 (a :: Nat) (b :: Nat) (c :: Nat) (d :: Nat) (e :: Nat)
instance (SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e) => IxStatic * (D5 a b c d e)
instance (SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d) => IxStatic * (D4 a b c d)
instance (SingI Nat a, SingI Nat b, SingI Nat c) => IxStatic * (D3 a b c)
instance (SingI Nat a, SingI Nat b) => IxStatic * (D2 a b)
instance (SingI Nat n, IxStatic * ((:.) k k1 n2 ns)) => IxStatic * ((:.) Nat * n ((:.) k k1 n2 ns))
instance SingI Nat n => IxStatic * ((:.) Nat * n Nil)
instance (SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e) => IxStatic ((,,,,) Nat Nat Nat Nat Nat) ('(,,,,) Nat Nat Nat Nat Nat a b c d e)
instance (SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d) => IxStatic ((,,,) Nat Nat Nat Nat) ('(,,,) Nat Nat Nat Nat a b c d)
instance (SingI Nat a, SingI Nat b, SingI Nat c) => IxStatic ((,,) Nat Nat Nat) ('(,,) Nat Nat Nat a b c)
instance (SingI Nat a, SingI Nat b) => IxStatic ((,) Nat Nat) ('(,) Nat Nat a b)
instance SingI Nat a => IxStatic Nat a
instance (SingI Nat n, IxStatic [Nat] ((':) Nat n2 ns)) => IxStatic [Nat] ((':) Nat n ((':) Nat n2 ns))
instance SingI Nat n => IxStatic [Nat] ((':) Nat n ('[] Nat))
-- | 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,
-- StaticArray UArray 10 CInt has a
-- Storable instance that is directly compatible with int
-- foo[10] in native code.
--
-- Multidimensional native arrays are also supported.
-- StaticArray UArray '(10,20,100) CUChar is
-- compatible with unsigned 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 StaticArray UArray
-- '(10,20,100) CUChar is a UArray (Int, Int, Int)
-- CUChar with its bounds set to ((0,0,0),(9,19,99)).
module Foreign.Marshal.StaticArray
-- | 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.
data StaticArray backing dimensions (elements :: *)
-- | Returns the backing value of this StaticArray.
toArray :: StaticArray backing dimensions elements -> backing (Index dimensions) elements
-- | Get the compile-time bounds from a StaticArray. Does not
-- examine its argument.
staticBounds :: IxStatic d => StaticArray b d e -> (Index d, Index d)
-- | 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.
staticArray :: (IArray b e, IxStatic d) => [(Index d, e)] -> StaticArray b d e
-- | Create a new StaticArray from a list of elements in index
-- order. Implemented in terms of listArray, with the same
-- caveats.
listStaticArray :: (IxStatic d, IArray b e) => [e] -> StaticArray b d e
-- | Get the size, in bytes, of the native representation of this
-- StaticArray.
sizeOf' :: (IxStatic d, Storable e) => StaticArray b d e -> Int
-- | Get the alignment, in bytes, of the native representation of this
-- StaticArray
alignment' :: Storable e => StaticArray b d e -> Int
-- | Write the contents of this StaticArray to the given location in
-- memory.
poke' :: (IxStatic d, IArray b e, Storable e) => Ptr (StaticArray b d e) -> StaticArray b d e -> IO ()
-- | Create a new StaticArray from the contents of the given
-- location in memory. Uses a temporary mutable array to build up the
-- result, then freezes it. The first argument is the freezing function.
-- Non-copying implementations of unsafeFreeze are safe as this
-- argument, and preferred.
peek' :: (IxStatic d, Storable e, IArray b e, MArray m e IO) => (m (Index d) e -> IO (b (Index d) e)) -> Ptr (StaticArray b d e) -> IO (StaticArray b d e)
instance Eq (backing (Index k dimensions) elements) => Eq (StaticArray k backing dimensions elements)
instance (IxStatic k d, Storable e) => Storable (StaticArray k Array d e)
instance (IxStatic k d, Storable e, IArray UArray e, MArray IOUArray e IO) => Storable (StaticArray k UArray d e)
instance (IArray b e, IxStatic k d, Show e) => Show (StaticArray k b d e)
-- | 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.
module Foreign.Marshal.StaticVector
-- | 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.
data StaticVector backing dimensions (elements :: *)
-- | Returns the backing value of this StaticVector.
toVector :: StaticVector backing dimensions elements -> backing elements
-- | Get the compile-time bounds from a StaticVector. Does not
-- examine its argument.
staticBounds :: IxStatic d => StaticVector b d e -> (Index d, Index d)
-- | Get the compile-time size from a StaticVector. Does not examine
-- its argument.
staticSize :: IxStatic d => StaticVector b d e -> Int
-- | 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.
fromList :: (Vector b e, IxStatic d) => [e] -> StaticVector b d e
instance Eq (backing elements) => Eq (StaticVector k backing dimensions elements)
instance (IxStatic k d, Storable e, Vector b e) => Storable (StaticVector k b d e)
instance (Vector b e, Show e) => Show (StaticVector k b d e)