License | BSD-style |
---|---|
Maintainer | Vincent Hanquez <vincent@snarc.org> |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Foundation.Primitive
Description
Different collections (list, vector, string, ..) unified under 1 API. an API to rules them all, and in the darkness bind them.
- class Eq ty => PrimType ty where
- primSizeInBytes :: Proxy ty -> Size8
- primShiftToBytes :: Proxy ty -> Int
- primBaUIndex :: ByteArray# -> Offset ty -> ty
- primMbaURead :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset ty -> prim ty
- primMbaUWrite :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset ty -> ty -> prim ()
- primAddrIndex :: Addr# -> Offset ty -> ty
- primAddrRead :: PrimMonad prim => Addr# -> Offset ty -> prim ty
- primAddrWrite :: PrimMonad prim => Addr# -> Offset ty -> ty -> prim ()
- class (Functor m, Applicative m, Monad m) => PrimMonad m where
- type PrimState m
- type PrimVar m :: * -> *
- primitive :: (State# (PrimState m) -> (#State# (PrimState m), a#)) -> m a
- primThrow :: Exception e => e -> m a
- unPrimMonad :: m a -> State# (PrimState m) -> (#State# (PrimState m), a#)
- primVarNew :: a -> m (PrimVar m a)
- primVarRead :: PrimVar m a -> m a
- primVarWrite :: PrimVar m a -> a -> m ()
- class ByteSwap a
- newtype LE a = LE {
- unLE :: a
- toLE :: ByteSwap a => a -> LE a
- fromLE :: ByteSwap a => LE a -> a
- newtype BE a = BE {
- unBE :: a
- toBE :: ByteSwap a => a -> BE a
- fromBE :: ByteSwap a => BE a -> a
- class IntegralUpsize a b where
- integralUpsize :: a -> b
- class IntegralDownsize a b where
- integralDownsize :: a -> b
- integralDownsizeCheck :: a -> Maybe b
- class IntegralCast a b where
- integralCast :: a -> b
- class NormalForm a where
- toNormalForm :: a -> ()
- force :: NormalForm a => a -> a
- deepseq :: NormalForm a => a -> b -> b
- data These a b
- data Block ty
- data MutableBlock ty st
Documentation
class Eq ty => PrimType ty where
Represent the accessor for types that can be stored in the UArray and MUArray.
Types need to be a instance of storable and have fixed sized.
Methods
primSizeInBytes :: Proxy ty -> Size8
get the size in bytes of a ty element
primShiftToBytes :: Proxy ty -> Int
get the shift size
primBaUIndex :: ByteArray# -> Offset ty -> ty
return the element stored at a specific index
Arguments
:: PrimMonad prim | |
=> MutableByteArray# (PrimState prim) | mutable array to read from |
-> Offset ty | index of the element to retrieve |
-> prim ty | the element returned |
Read an element at an index in a mutable array
Arguments
:: PrimMonad prim | |
=> MutableByteArray# (PrimState prim) | mutable array to modify |
-> Offset ty | index of the element to modify |
-> ty | the new value to store |
-> prim () |
Write an element to a specific cell in a mutable array.
primAddrIndex :: Addr# -> Offset ty -> ty
Read from Address, without a state. the value read should be considered a constant for all pratical purpose, otherwise bad thing will happens.
primAddrRead :: PrimMonad prim => Addr# -> Offset ty -> prim ty
Read a value from Addr in a specific primitive monad
primAddrWrite :: PrimMonad prim => Addr# -> Offset ty -> ty -> prim ()
Write a value to Addr in a specific primitive monad
Instances
class (Functor m, Applicative m, Monad m) => PrimMonad m where
Primitive monad that can handle mutation.
For example: IO and ST.
Associated Types
type PrimState m
type of state token associated with the PrimMonad m
type PrimVar m :: * -> *
type of variable associated with the PrimMonad m
Methods
primitive :: (State# (PrimState m) -> (#State# (PrimState m), a#)) -> m a
Unwrap the State# token to pass to a function a primitive function that returns an unboxed state and a value.
primThrow :: Exception e => e -> m a
Throw Exception in the primitive monad
unPrimMonad :: m a -> State# (PrimState m) -> (#State# (PrimState m), a#)
Run a Prim monad from a dedicated state#
primVarNew :: a -> m (PrimVar m a)
Build a new variable in the Prim Monad
primVarRead :: PrimVar m a -> m a
Read the variable in the Prim Monad
primVarWrite :: PrimVar m a -> a -> m ()
Write the variable in the Prim Monad
endianess
class ByteSwap a
Class of types that can be byte-swapped.
e.g. Word16, Word32, Word64
Minimal complete definition
byteSwap
newtype LE a
Little Endian value
Instances
Eq a => Eq (LE a) | |
(ByteSwap a, Ord a) => Ord (LE a) | |
Show a => Show (LE a) | |
Bits a => Bits (LE a) | |
PrimType a => PrimType (LE a) | |
NormalForm a => NormalForm (LE a) | |
StorableFixed (LE Word16) | |
StorableFixed (LE Word32) | |
StorableFixed (LE Word64) | |
Storable (LE Word16) | |
Storable (LE Word32) | |
Storable (LE Word64) |
newtype BE a
Big Endian value
Instances
Eq a => Eq (BE a) | |
(ByteSwap a, Ord a) => Ord (BE a) | |
Show a => Show (BE a) | |
Bits a => Bits (BE a) | |
PrimType a => PrimType (BE a) | |
NormalForm a => NormalForm (BE a) | |
StorableFixed (BE Word16) | |
StorableFixed (BE Word32) | |
StorableFixed (BE Word64) | |
Storable (BE Word16) | |
Storable (BE Word32) | |
Storable (BE Word64) |
Integral convertion
class IntegralUpsize a b where
Upsize an integral value
The destination type b
size need to be greater or equal
than the size type of a
Methods
integralUpsize :: a -> b
Instances
class IntegralDownsize a b where
Downsize an integral value
Minimal complete definition
Instances
class IntegralCast a b where
Cast an integral value to another value that have the same representional size
Minimal complete definition
Nothing
Methods
integralCast :: a -> b
Instances
IntegralCast Int Word | |
IntegralCast Int64 Word64 | |
IntegralCast Word Int | |
IntegralCast Word64 Int64 | |
IntegralCast Int (CountOf ty) | |
IntegralCast Int (Offset ty) | |
IntegralCast Word (CountOf ty) | |
IntegralCast Word (Offset ty) |
Evaluation
class NormalForm a where
Data that can be fully evaluated in Normal Form
Methods
toNormalForm :: a -> ()
Instances
force :: NormalForm a => a -> a
deepseq :: NormalForm a => a -> b -> b
These
data These a b
Either a or b or both.
Block of memory
data Block ty
A block of memory containing unpacked bytes representing values of type ty
Instances
PrimType ty => IsList (Block ty) | |
(PrimType ty, Eq ty) => Eq (Block ty) | |
Data ty => Data (Block ty) | |
(PrimType ty, Ord ty) => Ord (Block ty) | |
(PrimType ty, Show ty) => Show (Block ty) | |
PrimType ty => Monoid (Block ty) | |
NormalForm (Block ty) | |
PrimType ty => Fold1able (Block ty) | |
PrimType ty => Foldable (Block ty) | |
PrimType ty => IndexedCollection (Block ty) | |
PrimType ty => Collection (Block ty) | |
PrimType ty => Sequential (Block ty) | |
PrimType ty => Copy (Block ty) | |
type Item (Block ty) = ty | |
type Element (Block ty) = ty |
data MutableBlock ty st
A Mutable block of memory containing unpacked bytes representing values of type ty
Instances
PrimType ty => MutableCollection (MutableBlock ty) | |
type MutableFreezed (MutableBlock ty) = Block ty | |
type MutableKey (MutableBlock ty) = Offset ty | |
type MutableValue (MutableBlock ty) = ty |