Safe Haskell | None |
---|---|
Language | Haskell2010 |
Use case:
- You've got a block of data you want to work with in C or C++ or some other foreign language
- It represents a 2D grid
- Before disposing of it, it would be convenient to treat
it as a
Vector
of vectors (perhaps for inspecting contents). - Also, I just wanted to see what's involved in creating a Vector instance.
The resulting Grid
isn't an especially _good_ instance
of a Vector -- many operations on the 'top-level' vector
are disallowed --
and there's no mutable equivalent, but it seems to
work.
Synopsis
- type Grid a = InternalGrid a (Vector a)
- type InternalGrid = Grid
- length :: Grid el (v el) -> Int
- (!) :: Grid el (v el) -> Int -> v el
- (!?) :: Grid el (v el) -> Int -> Maybe (v el)
- head :: Grid el (v el) -> v el
- last :: Grid el (v el) -> v el
- unsafeIndex :: Grid el (v el) -> Int -> v el
- unsafeHead :: Grid el (v el) -> v el
- unsafeLast :: Grid el (v el) -> v el
- slice :: Int -> Int -> Grid el (v el) -> Grid el (v el)
- init :: Grid el (v el) -> Grid el (v el)
- tail :: Grid el (v el) -> Grid el (v el)
- take :: Int -> Grid el (v el) -> Grid el (v el)
- drop :: Int -> Grid el (v el) -> Grid el (v el)
- fromVector :: Storable el => Int -> Int -> Vector el -> Grid el
- toList :: (Storable a, NFData a) => Grid a -> IO [Vector a]
- reverse :: [a] -> [a]
- unsafeToForeignPtr0 :: Grid el -> ForeignPtr el
Vec-of-vec view of storable
type Grid a = InternalGrid a (Vector a) Source #
A vector-of-vector view of a block foreign contiguous data
plus helpful types
type InternalGrid = Grid Source #
Accessors
Length information
Indexing
unsafeIndex :: Grid el (v el) -> Int -> v el Source #
O(1) Unsafe indexing without bounds checking
unsafeHead :: Grid el (v el) -> v el Source #
O(1) First element without checking if the vector is empty
unsafeLast :: Grid el (v el) -> v el Source #
O(1) Last element without checking if the vector is empty
Extracting subvectors (slicing)
O(1) Yield a slice of the vector without copying it. The vector must
contain at least i+n
elements.
init :: Grid el (v el) -> Grid el (v el) Source #
O(1) Yield all but the last element without copying. The vector may not be empty.
tail :: Grid el (v el) -> Grid el (v el) Source #
O(1) Yield all but the first element without copying. The vector may not be empty.
take :: Int -> Grid el (v el) -> Grid el (v el) Source #
O(1) Yield at the first n
elements without copying. The vector may
contain less than n
elements in which case it is returned unchanged.
drop :: Int -> Grid el (v el) -> Grid el (v el) Source #
O(1) Yield all but the first n
elements without copying. The vector may
contain less than n
elements in which case an empty vector is returned.
Construction
Initialisation
Destruction
Permutations
Raw pointers
unsafeToForeignPtr0 :: Grid el -> ForeignPtr el Source #
O(1) Yield the underlying ForeignPtr
.
You can assume the pointer points directly to the data (no offset).
The data may not be modified through the ForeignPtr
.