fixed-vector-0.7.0.2: Generic vectors with statically known size.

Safe HaskellNone
LanguageHaskell98

Data.Vector.Fixed.Storable

Contents

Description

Storable-based unboxed vectors.

Synopsis

Immutable

data Vec n a Source

Storable-based vector with fixed length

Instances

(Arity n, Storable a) => VectorN Vec n a 
(Arity n, Storable a) => Vector (Vec n) a 
(Arity n, Storable a) => IVector (Vec n) a 
(Arity n, Storable a, Eq a) => Eq (Vec n a) 
(Typeable * n, Arity n, Storable a, Data a) => Data (Vec n a) 
(Arity n, Storable a, Ord a) => Ord (Vec n a) 
(Arity n, Storable a, Show a) => Show (Vec n a) 
(Arity n, Storable a) => Storable (Vec n a) 
(Arity n, Storable a, Monoid a) => Monoid (Vec n a) 
Typeable (* -> * -> *) Vec 
type Dim (Vec n) = n 
type Mutable (Vec n) = MVec n 

type Vec1 = Vec (S Z) Source

type Vec2 = Vec (S (S Z)) Source

type Vec3 = Vec (S (S (S Z))) Source

type Vec4 = Vec (S (S (S (S Z)))) Source

type Vec5 = Vec (S (S (S (S (S Z))))) Source

Raw pointers

unsafeFromForeignPtr :: Storable a => ForeignPtr a -> Vec n a Source

Construct vector from foreign pointer.

unsafeToForeignPtr :: Storable a => Vec n a -> ForeignPtr a Source

Get underlying pointer. Data may not be modified through pointer.

unsafeWith :: Storable a => (Ptr a -> IO b) -> Vec n a -> IO b Source

Mutable

newtype MVec n s a Source

Storable-based mutable vector with fixed length

Constructors

MVec (ForeignPtr a) 

Instances

(Arity n, Storable a) => MVector (MVec n) a 
Typeable (* -> * -> * -> *) MVec 
type DimM (MVec n) = n 

Type classes

class Storable a

The member functions of this class facilitate writing values of primitive types to raw memory (which may have been allocated with the above mentioned routines) and reading values from blocks of raw memory. The class, furthermore, includes support for computing the storage requirements and alignment restrictions of storable types.

Memory addresses are represented as values of type Ptr a, for some a which is an instance of class Storable. The type argument to Ptr helps provide some valuable type safety in FFI code (you can't mix pointers of different types without an explicit cast), while helping the Haskell type system figure out which marshalling method is needed for a given pointer.

All marshalling between Haskell and a foreign language ultimately boils down to translating Haskell data structures into the binary representation of a corresponding data structure of the foreign language and vice versa. To code this marshalling in Haskell, it is necessary to manipulate primitive data types stored in unstructured memory blocks. The class Storable facilitates this manipulation on all types for which it is instantiated, which are the standard basic types of Haskell, the fixed size Int types (Int8, Int16, Int32, Int64), the fixed size Word types (Word8, Word16, Word32, Word64), StablePtr, all types from Foreign.C.Types, as well as Ptr.

Minimal complete definition: sizeOf, alignment, one of peek, peekElemOff and peekByteOff, and one of poke, pokeElemOff and pokeByteOff.

Minimal complete definition

sizeOf, alignment, (peek | peekElemOff | peekByteOff), (poke | pokeElemOff | pokeByteOff)