-- 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.4.1.0
-- | This module defines StaticArray, a simple wrapper around
-- instances of IArray with its dimensions encoded in the type.
-- StaticArray provides a Storable instance that uses the
-- type-level dimensions, and significantly 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 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.
data StaticArray backing dimensions (elements :: *)
-- | The 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
-- peek in StaticArray 's Storable instance.
--
-- If you're using an instance of IArray other than Array
-- or UArray, you'll need to add a type instance for your type. If
-- it supports non-copying unsafeFreeze, the type instance should
-- return the type constructor for the appropriate MArray
-- instance. Otherwise, just have it return IOArray
-- | Returns the backing Array of this StaticArray.
toArray :: StaticArray backing dimensions elements -> backing (Bound dimensions) elements
-- | 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 StaticSize
-- instance.
staticArray :: (Ix (Bound d), IArray b e, StaticSize d) => [(Bound d, e)] -> StaticArray b d e
-- | Create a new StaticArray from a list of elements in index
-- order. Implemented in terms of listArray.
listStaticArray :: (StaticSize d, Ix (Bound d), IArray b e) => [e] -> StaticArray b d e
-- | This class connects dimension description types with IArray
-- 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.
class StaticSize d where type family Bound d :: *
extent :: StaticSize d => StaticArray b d e -> (Bound d, Bound d)
-- | A conversion function for converting type-level naturals to
-- value-level. This is being exposed to aid in the creation of
-- additional StaticSize 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
instance Eq (backing (Bound k dimensions) elements) => Eq (StaticArray k backing dimensions elements)
instance (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) => StaticSize ((,,,,,,,,,,,,) Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat) ('(,,,,,,,,,,,,) Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat a b c d e f g h i j k l m)
instance (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) => StaticSize ((,,,,,,,,,,,) Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat) ('(,,,,,,,,,,,) Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat a b c d e f g h i j k l)
instance (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) => StaticSize ((,,,,,,,,,,) Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat) ('(,,,,,,,,,,) Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat a b c d e f g h i j k)
instance (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) => StaticSize ((,,,,,,,,,) Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat) ('(,,,,,,,,,) Nat Nat Nat Nat Nat Nat Nat Nat Nat Nat a b c d e f g h i j)
instance (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) => StaticSize ((,,,,,,,,) Nat Nat Nat Nat Nat Nat Nat Nat Nat) ('(,,,,,,,,) Nat Nat Nat Nat Nat Nat Nat Nat Nat a b c d e f g h i)
instance (SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e, SingI Nat f, SingI Nat g, SingI Nat h) => StaticSize ((,,,,,,,) Nat Nat Nat Nat Nat Nat Nat Nat) ('(,,,,,,,) Nat Nat Nat Nat Nat Nat Nat Nat a b c d e f g h)
instance (SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e, SingI Nat f, SingI Nat g) => StaticSize ((,,,,,,) Nat Nat Nat Nat Nat Nat Nat) ('(,,,,,,) Nat Nat Nat Nat Nat Nat Nat a b c d e f g)
instance (SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e, SingI Nat f) => StaticSize ((,,,,,) Nat Nat Nat Nat Nat Nat) ('(,,,,,) Nat Nat Nat Nat Nat Nat a b c d e f)
instance (SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e) => StaticSize ((,,,,) 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) => StaticSize ((,,,) Nat Nat Nat Nat) ('(,,,) Nat Nat Nat Nat a b c d)
instance (SingI Nat a, SingI Nat b, SingI Nat c) => StaticSize ((,,) Nat Nat Nat) ('(,,) Nat Nat Nat a b c)
instance (SingI Nat a, SingI Nat b) => StaticSize ((,) Nat Nat) ('(,) Nat Nat a b)
instance SingI Nat a => StaticSize Nat a
instance (SingI Nat n, StaticSize [Nat] ((':) Nat n2 ns)) => StaticSize [Nat] ((':) Nat n ((':) Nat n2 ns))
instance SingI Nat n => StaticSize [Nat] ((':) Nat n ('[] Nat))
instance (StaticSize k d, Ix (Bound k d), Storable e, IArray b e, MArray (Mutable b) e IO) => Storable (StaticArray k b d e)
instance (IArray b e, Ix (Bound k d), Show e) => Show (StaticArray k b d e)
-- | This module contains a collection of data types for describing
-- dimensions of StaticArray that do not depend on promoted lists
-- and tuples.
--
-- For convenience, it re-exports all of
-- Foreign.Marshal.StaticArray.
module Foreign.Marshal.StaticArray.Unpromoted
-- | :. 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)
-- | An alternative dimension type to promoted 6-tuples, provided for
-- syntactic compatibility with CPP.
data D6 (a :: Nat) (b :: Nat) (c :: Nat) (d :: Nat) (e :: Nat) (f :: Nat)
-- | An alternative dimension type to promoted 7-tuples, provided for
-- syntactic compatibility with CPP.
data D7 (a :: Nat) (b :: Nat) (c :: Nat) (d :: Nat) (e :: Nat) (f :: Nat) (g :: Nat)
-- | An alternative dimension type to promoted 8-tuples, provided for
-- syntactic compatibility with CPP.
data D8 (a :: Nat) (b :: Nat) (c :: Nat) (d :: Nat) (e :: Nat) (f :: Nat) (g :: Nat) (h :: Nat)
-- | An alternative dimension type to promoted 9-tuples, provided for
-- syntactic compatibility with CPP.
data D9 (a :: Nat) (b :: Nat) (c :: Nat) (d :: Nat) (e :: Nat) (f :: Nat) (g :: Nat) (h :: Nat) (i :: Nat)
-- | An alternative dimension type to promoted 10-tuples, provided for
-- syntactic compatibility with CPP.
data D10 (a :: Nat) (b :: Nat) (c :: Nat) (d :: Nat) (e :: Nat) (f :: Nat) (g :: Nat) (h :: Nat) (i :: Nat) (j :: Nat)
-- | An alternative dimension type to promoted 11-tuples, provided for
-- syntactic compatibility with CPP.
data D11 (a :: Nat) (b :: Nat) (c :: Nat) (d :: Nat) (e :: Nat) (f :: Nat) (g :: Nat) (h :: Nat) (i :: Nat) (j :: Nat) (k :: Nat)
-- | An alternative dimension type to promoted 12-tuples, provided for
-- syntactic compatibility with CPP.
data D12 (a :: Nat) (b :: Nat) (c :: Nat) (d :: Nat) (e :: Nat) (f :: Nat) (g :: Nat) (h :: Nat) (i :: Nat) (j :: Nat) (k :: Nat) (l :: Nat)
-- | An alternative dimension type to promoted 13-tuples, provided for
-- syntactic compatibility with CPP.
data D13 (a :: Nat) (b :: Nat) (c :: Nat) (d :: Nat) (e :: Nat) (f :: Nat) (g :: Nat) (h :: Nat) (i :: Nat) (j :: Nat) (k :: Nat) (l :: Nat) (m :: Nat)
instance (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) => StaticSize * (D13 a b c d e f g h i j k l m)
instance (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) => StaticSize * (D12 a b c d e f g h i j k l)
instance (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) => StaticSize * (D11 a b c d e f g h i j k)
instance (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) => StaticSize * (D10 a b c d e f g h i j)
instance (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) => StaticSize * (D9 a b c d e f g h i)
instance (SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e, SingI Nat f, SingI Nat g, SingI Nat h) => StaticSize * (D8 a b c d e f g h)
instance (SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e, SingI Nat f, SingI Nat g) => StaticSize * (D7 a b c d e f g)
instance (SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e, SingI Nat f) => StaticSize * (D6 a b c d e f)
instance (SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d, SingI Nat e) => StaticSize * (D5 a b c d e)
instance (SingI Nat a, SingI Nat b, SingI Nat c, SingI Nat d) => StaticSize * (D4 a b c d)
instance (SingI Nat a, SingI Nat b, SingI Nat c) => StaticSize * (D3 a b c)
instance (SingI Nat a, SingI Nat b) => StaticSize * (D2 a b)
instance (SingI Nat n, StaticSize * ((:.) k k1 n2 ns)) => StaticSize * ((:.) Nat * n ((:.) k k1 n2 ns))
instance SingI Nat n => StaticSize * ((:.) Nat * n Nil)