Portability | non-portable |
---|---|
Stability | experimental |
Maintainer | Roman Leshchinskiy <rl@cse.unsw.edu.au> |
Storable
-based vectors.
- data Vector a
- data MVector a = MVector !Int !Int !(ForeignPtr a)
- class Storable a
- length :: Storable a => Vector a -> Int
- null :: Storable a => Vector a -> Bool
- empty :: Storable a => Vector a
- singleton :: Storable a => a -> Vector a
- cons :: Storable a => a -> Vector a -> Vector a
- snoc :: Storable a => Vector a -> a -> Vector a
- replicate :: Storable a => Int -> a -> Vector a
- (++) :: Storable a => Vector a -> Vector a -> Vector a
- copy :: Storable a => Vector a -> Vector a
- (!) :: Storable a => Vector a -> Int -> a
- head :: Storable a => Vector a -> a
- last :: Storable a => Vector a -> a
- slice :: Storable a => Vector a -> Int -> Int -> Vector a
- init :: Storable a => Vector a -> Vector a
- tail :: Storable a => Vector a -> Vector a
- take :: Storable a => Int -> Vector a -> Vector a
- drop :: Storable a => Int -> Vector a -> Vector a
- accum :: Storable a => (a -> b -> a) -> Vector a -> [(Int, b)] -> Vector a
- (//) :: Storable a => Vector a -> [(Int, a)] -> Vector a
- backpermute :: Storable a => Vector a -> Vector Int -> Vector a
- reverse :: Storable a => Vector a -> Vector a
- map :: (Storable a, Storable b) => (a -> b) -> Vector a -> Vector b
- concatMap :: (Storable a, Storable b) => (a -> Vector b) -> Vector a -> Vector b
- zipWith :: (Storable a, Storable b, Storable c) => (a -> b -> c) -> Vector a -> Vector b -> Vector c
- zipWith3 :: (Storable a, Storable b, Storable c, Storable d) => (a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector d
- filter :: Storable a => (a -> Bool) -> Vector a -> Vector a
- takeWhile :: Storable a => (a -> Bool) -> Vector a -> Vector a
- dropWhile :: Storable a => (a -> Bool) -> Vector a -> Vector a
- elem :: (Storable a, Eq a) => a -> Vector a -> Bool
- notElem :: (Storable a, Eq a) => a -> Vector a -> Bool
- find :: Storable a => (a -> Bool) -> Vector a -> Maybe a
- findIndex :: Storable a => (a -> Bool) -> Vector a -> Maybe Int
- foldl :: Storable b => (a -> b -> a) -> a -> Vector b -> a
- foldl1 :: Storable a => (a -> a -> a) -> Vector a -> a
- foldl' :: Storable b => (a -> b -> a) -> a -> Vector b -> a
- foldl1' :: Storable a => (a -> a -> a) -> Vector a -> a
- foldr :: Storable a => (a -> b -> b) -> b -> Vector a -> b
- foldr1 :: Storable a => (a -> a -> a) -> Vector a -> a
- and :: Vector Bool -> Bool
- or :: Vector Bool -> Bool
- sum :: (Storable a, Num a) => Vector a -> a
- product :: (Storable a, Num a) => Vector a -> a
- maximum :: (Storable a, Ord a) => Vector a -> a
- minimum :: (Storable a, Ord a) => Vector a -> a
- unfoldr :: Storable a => (b -> Maybe (a, b)) -> b -> Vector a
- prescanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a
- prescanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a
- postscanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a
- postscanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a
- scanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a
- scanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector a
- scanl1 :: Storable a => (a -> a -> a) -> Vector a -> Vector a
- scanl1' :: Storable a => (a -> a -> a) -> Vector a -> Vector a
- enumFromTo :: (Storable a, Enum a) => a -> a -> Vector a
- enumFromThenTo :: (Storable a, Enum a) => a -> a -> a -> Vector a
- toList :: Storable a => Vector a -> [a]
- fromList :: Storable a => [a] -> Vector a
Documentation
Storable
-based vectors
MVector !Int !Int !(ForeignPtr a) |
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
, for some
Ptr
aa
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
.
Length information
Construction
replicate :: Storable a => Int -> a -> Vector aSource
Vector of the given length with the given value in each position
copy :: Storable a => Vector a -> Vector aSource
Create a copy of a vector. Useful when dealing with slices.
Accessing individual elements
Subvectors
Yield a part of the vector without copying it. Safer version of
unsafeSlice
.
drop :: Storable a => Int -> Vector a -> Vector aSource
Yield all but the first n
elements without copying.
Permutations
Mapping
map :: (Storable a, Storable b) => (a -> b) -> Vector a -> Vector bSource
Map a function over a vector
Zipping and unzipping
zipWith :: (Storable a, Storable b, Storable c) => (a -> b -> c) -> Vector a -> Vector b -> Vector cSource
Zip two vectors with the given function.
zipWith3 :: (Storable a, Storable b, Storable c, Storable d) => (a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector dSource
Zip three vectors with the given function.
Filtering
filter :: Storable a => (a -> Bool) -> Vector a -> Vector aSource
Drop elements which do not satisfy the predicate
takeWhile :: Storable a => (a -> Bool) -> Vector a -> Vector aSource
Yield the longest prefix of elements satisfying the predicate.
dropWhile :: Storable a => (a -> Bool) -> Vector a -> Vector aSource
Drop the longest prefix of elements that satisfy the predicate.
Searching
elem :: (Storable a, Eq a) => a -> Vector a -> BoolSource
Check whether the vector contains an element
Folding
foldl1' :: Storable a => (a -> a -> a) -> Vector a -> aSource
Left fold on non-empty vectors with strict accumulator
Specialised folds
Unfolding
Scans
prescanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector aSource
Prefix scan with strict accumulator
postscanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector aSource
Suffix scan
postscanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector aSource
Suffix scan with strict accumulator
scanl :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector aSource
Haskell-style scan
scanl' :: (Storable a, Storable b) => (a -> b -> a) -> a -> Vector b -> Vector aSource
Haskell-style scan with strict accumulator
scanl1' :: Storable a => (a -> a -> a) -> Vector a -> Vector aSource
Scan over a non-empty Vector
with a strict accumulator
Enumeration
enumFromTo :: (Storable a, Enum a) => a -> a -> Vector aSource
enumFromThenTo :: (Storable a, Enum a) => a -> a -> a -> Vector aSource