Unboxed, primitive, multidimensional tables. In instance for Ix
-type
keys comes with the package. This package trades safety for speed. The index
operator (!) is basically the only function that does bounds-checking and
only with an assertion. This, however, is by design. The only way to get an
immutable table from a mutable one is by the unsafeFreezeM
operation.
Again, it is by design that both data structures share the same memory
pointer internally.
TODO We kind-of lost all but the ST monad for monadic operations.
- class PrimArrayOps a b where
- class PrimMonad s => PrimArrayOpsM a b s where
- data PrimArrayM a b s :: *
- readM :: PrimArrayM a b s -> a -> s b
- writeM :: PrimArrayM a b s -> a -> b -> s ()
- boundsM :: PrimArrayM a b s -> s (a, a)
- fromAssocsM :: a -> a -> b -> [(a, b)] -> s (PrimArrayM a b s)
- unsafeFreezeM :: PrimArrayM a b s -> s (PrimArray a b)
- fromListM :: a -> a -> [b] -> s (PrimArrayM a b s)
- toListM :: PrimArrayM a b s -> s [b]
- (!) :: PrimArrayOps a b => PrimArray a b -> a -> b
- amap :: (PrimArrayOps a b, PrimArrayOps a c) => (b -> c) -> PrimArray a b -> PrimArray a c
The PrimArray class.
class PrimArrayOps a b whereSource
:: PrimArray a b | |
-> a | |
-> b | Index an array without bounds-checking |
:: PrimArray a b | |
-> [(a, b)] | All associations of (key,value) |
:: a | |
-> a | |
-> b | |
-> [(a, b)] | |
-> PrimArray a b | Pure build function |
:: PrimArray a b | |
-> (a, a) | Min- and maxbound of all dimensions |
:: a | |
-> a | |
-> [b] | |
-> PrimArray a b | Build the complete table from a list |
:: PrimArray a b | |
-> [b] | Read the complete table as a list |
(Bounded a, Ix a, Prim b) => PrimArrayOps a b |
class PrimMonad s => PrimArrayOpsM a b s whereSource
data PrimArrayM a b s :: *Source
Monadic data type
:: PrimArrayM a b s | |
-> a | |
-> s b | Monadic read |
:: PrimArrayM a b s | |
-> a | |
-> b | |
-> s () | Monadic write |
:: PrimArrayM a b s | |
-> s (a, a) | Monadic bounds |
:: a | |
-> a | |
-> b | |
-> [(a, b)] | |
-> s (PrimArrayM a b s) | Build monadic array from assocs |
:: PrimArrayM a b s | |
-> s (PrimArray a b) | UNSAFE freezing of array. |
:: a | |
-> a | |
-> [b] | |
-> s (PrimArrayM a b s) | Build the complete monadic table from a list |
:: PrimArrayM a b s | |
-> s [b] | Read the complete monadic table as a list |
(Bounded a, Ix a, Prim b) => PrimArrayOpsM a b (ST s) |
Helper functions.
(!) :: PrimArrayOps a b => PrimArray a b -> a -> bSource
Asserting unsafeIndex
. Debug-code is checked for out-of-bounds
occurances while production code uses unsafeIndex directly.
amap :: (PrimArrayOps a b, PrimArrayOps a c) => (b -> c) -> PrimArray a b -> PrimArray a cSource
Create a new array from an old one, mapping a function over all values.