foundation-0.0.6: Alternative prelude with batteries and no dependencies

LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Foundation.Primitive

Contents

Description

Different collections (list, vector, string, ..) unified under 1 API. an API to rules them all, and in the darkness bind them.

Synopsis

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

primBaUIndex :: ByteArray# -> Offset ty -> ty #

return the element stored at a specific index

primMbaURead :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset ty -> prim ty #

Read an element at an index in a mutable array

primMbaUWrite :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset ty -> ty -> 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

PrimType Char # 
PrimType Double # 
PrimType Float # 
PrimType Int # 
PrimType Int8 # 
PrimType Int16 # 
PrimType Int32 # 
PrimType Int64 # 
PrimType Word # 
PrimType Word8 # 
PrimType Word16 # 
PrimType Word32 # 
PrimType Word64 # 
PrimType CChar # 
PrimType CUChar # 
PrimType a => PrimType (BE a) # 

Methods

primSizeInBytes :: Proxy * (BE a) -> Size8 #

primBaUIndex :: ByteArray# -> Offset (BE a) -> BE a #

primMbaURead :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset (BE a) -> prim (BE a) #

primMbaUWrite :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset (BE a) -> BE a -> prim () #

primAddrIndex :: Addr# -> Offset (BE a) -> BE a #

primAddrRead :: PrimMonad prim => Addr# -> Offset (BE a) -> prim (BE a) #

primAddrWrite :: PrimMonad prim => Addr# -> Offset (BE a) -> BE a -> prim () #

PrimType a => PrimType (LE a) # 

Methods

primSizeInBytes :: Proxy * (LE a) -> Size8 #

primBaUIndex :: ByteArray# -> Offset (LE a) -> LE a #

primMbaURead :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset (LE a) -> prim (LE a) #

primMbaUWrite :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset (LE a) -> LE a -> prim () #

primAddrIndex :: Addr# -> Offset (LE a) -> LE a #

primAddrRead :: PrimMonad prim => Addr# -> Offset (LE a) -> prim (LE a) #

primAddrWrite :: PrimMonad prim => Addr# -> Offset (LE a) -> LE a -> prim () #

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

Instances

PrimMonad IO # 

Associated Types

type PrimState (IO :: * -> *) :: * #

type PrimVar (IO :: * -> *) :: * -> * #

PrimMonad (ST s) # 

Associated Types

type PrimState (ST s :: * -> *) :: * #

type PrimVar (ST s :: * -> *) :: * -> * #

Methods

primitive :: (State# (PrimState (ST s)) -> (#VoidRep, PtrRepLifted, State# (PrimState (ST s)), a#)) -> ST s a #

primThrow :: Exception e => e -> ST s a #

unPrimMonad :: ST s a -> State# (PrimState (ST s)) -> (#VoidRep, PtrRepLifted, State# (PrimState (ST s)), a#) #

primVarNew :: a -> ST s (PrimVar (ST s) a) #

primVarRead :: PrimVar (ST s) a -> ST s a #

primVarWrite :: PrimVar (ST s) a -> a -> ST s () #

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

Constructors

LE 

Fields

Instances

Eq a => Eq (LE a) # 

Methods

(==) :: LE a -> LE a -> Bool #

(/=) :: LE a -> LE a -> Bool #

(ByteSwap a, Ord a) => Ord (LE a) # 

Methods

compare :: LE a -> LE a -> Ordering #

(<) :: LE a -> LE a -> Bool #

(<=) :: LE a -> LE a -> Bool #

(>) :: LE a -> LE a -> Bool #

(>=) :: LE a -> LE a -> Bool #

max :: LE a -> LE a -> LE a #

min :: LE a -> LE a -> LE a #

Show a => Show (LE a) # 

Methods

showsPrec :: Int -> LE a -> ShowS #

show :: LE a -> String #

showList :: [LE a] -> ShowS #

PrimType a => PrimType (LE a) # 

Methods

primSizeInBytes :: Proxy * (LE a) -> Size8 #

primBaUIndex :: ByteArray# -> Offset (LE a) -> LE a #

primMbaURead :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset (LE a) -> prim (LE a) #

primMbaUWrite :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset (LE a) -> LE a -> prim () #

primAddrIndex :: Addr# -> Offset (LE a) -> LE a #

primAddrRead :: PrimMonad prim => Addr# -> Offset (LE a) -> prim (LE a) #

primAddrWrite :: PrimMonad prim => Addr# -> Offset (LE a) -> LE a -> prim () #

StorableFixed (LE Word16) # 

Methods

size :: proxy (LE Word16) -> Size Word8 #

alignment :: proxy (LE Word16) -> Size Word8 #

StorableFixed (LE Word32) # 

Methods

size :: proxy (LE Word32) -> Size Word8 #

alignment :: proxy (LE Word32) -> Size Word8 #

StorableFixed (LE Word64) # 

Methods

size :: proxy (LE Word64) -> Size Word8 #

alignment :: proxy (LE Word64) -> Size Word8 #

Storable (LE Word16) # 

Methods

peek :: Ptr (LE Word16) -> IO (LE Word16) #

poke :: Ptr (LE Word16) -> LE Word16 -> IO () #

Storable (LE Word32) # 

Methods

peek :: Ptr (LE Word32) -> IO (LE Word32) #

poke :: Ptr (LE Word32) -> LE Word32 -> IO () #

Storable (LE Word64) # 

Methods

peek :: Ptr (LE Word64) -> IO (LE Word64) #

poke :: Ptr (LE Word64) -> LE Word64 -> IO () #

toLE :: ByteSwap a => a -> LE a #

Convert a value in cpu endianess to little endian

fromLE :: ByteSwap a => LE a -> a #

Convert from a little endian value to the cpu endianness

newtype BE a #

Big Endian value

Constructors

BE 

Fields

Instances

Eq a => Eq (BE a) # 

Methods

(==) :: BE a -> BE a -> Bool #

(/=) :: BE a -> BE a -> Bool #

(ByteSwap a, Ord a) => Ord (BE a) # 

Methods

compare :: BE a -> BE a -> Ordering #

(<) :: BE a -> BE a -> Bool #

(<=) :: BE a -> BE a -> Bool #

(>) :: BE a -> BE a -> Bool #

(>=) :: BE a -> BE a -> Bool #

max :: BE a -> BE a -> BE a #

min :: BE a -> BE a -> BE a #

Show a => Show (BE a) # 

Methods

showsPrec :: Int -> BE a -> ShowS #

show :: BE a -> String #

showList :: [BE a] -> ShowS #

PrimType a => PrimType (BE a) # 

Methods

primSizeInBytes :: Proxy * (BE a) -> Size8 #

primBaUIndex :: ByteArray# -> Offset (BE a) -> BE a #

primMbaURead :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset (BE a) -> prim (BE a) #

primMbaUWrite :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset (BE a) -> BE a -> prim () #

primAddrIndex :: Addr# -> Offset (BE a) -> BE a #

primAddrRead :: PrimMonad prim => Addr# -> Offset (BE a) -> prim (BE a) #

primAddrWrite :: PrimMonad prim => Addr# -> Offset (BE a) -> BE a -> prim () #

StorableFixed (BE Word16) # 

Methods

size :: proxy (BE Word16) -> Size Word8 #

alignment :: proxy (BE Word16) -> Size Word8 #

StorableFixed (BE Word32) # 

Methods

size :: proxy (BE Word32) -> Size Word8 #

alignment :: proxy (BE Word32) -> Size Word8 #

StorableFixed (BE Word64) # 

Methods

size :: proxy (BE Word64) -> Size Word8 #

alignment :: proxy (BE Word64) -> Size Word8 #

Storable (BE Word16) # 

Methods

peek :: Ptr (BE Word16) -> IO (BE Word16) #

poke :: Ptr (BE Word16) -> BE Word16 -> IO () #

Storable (BE Word32) # 

Methods

peek :: Ptr (BE Word32) -> IO (BE Word32) #

poke :: Ptr (BE Word32) -> BE Word32 -> IO () #

Storable (BE Word64) # 

Methods

peek :: Ptr (BE Word64) -> IO (BE Word64) #

poke :: Ptr (BE Word64) -> BE Word64 -> IO () #

toBE :: ByteSwap a => a -> BE a #

Convert a value in cpu endianess to big endian

fromBE :: ByteSwap a => BE a -> a #

Convert from a big endian value to the cpu endianness

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

Minimal complete definition

integralUpsize

Methods

integralUpsize :: a -> b #

Instances

IntegralUpsize Int8 Int # 

Methods

integralUpsize :: Int8 -> Int #

IntegralUpsize Int8 Int16 # 

Methods

integralUpsize :: Int8 -> Int16 #

IntegralUpsize Int8 Int32 # 

Methods

integralUpsize :: Int8 -> Int32 #

IntegralUpsize Int8 Int64 # 

Methods

integralUpsize :: Int8 -> Int64 #

IntegralUpsize Int8 Integer # 
IntegralUpsize Int16 Int # 

Methods

integralUpsize :: Int16 -> Int #

IntegralUpsize Int16 Int32 # 
IntegralUpsize Int16 Int64 # 
IntegralUpsize Int16 Integer # 
IntegralUpsize Int32 Int # 

Methods

integralUpsize :: Int32 -> Int #

IntegralUpsize Int32 Int64 # 
IntegralUpsize Int32 Integer # 
IntegralUpsize Int64 Integer # 
IntegralUpsize Word8 Integer # 
IntegralUpsize Word8 Word # 

Methods

integralUpsize :: Word8 -> Word #

IntegralUpsize Word8 Word16 # 
IntegralUpsize Word8 Word32 # 
IntegralUpsize Word8 Word64 # 
IntegralUpsize Word8 Natural # 
IntegralUpsize Word16 Integer # 
IntegralUpsize Word16 Word # 
IntegralUpsize Word16 Word32 # 
IntegralUpsize Word16 Word64 # 
IntegralUpsize Word16 Natural # 
IntegralUpsize Word32 Integer # 
IntegralUpsize Word32 Word # 
IntegralUpsize Word32 Word64 # 
IntegralUpsize Word32 Natural # 
IntegralUpsize Word64 Integer # 
IntegralUpsize Word64 Natural # 

class IntegralDownsize a b where #

Downsize an integral value

Minimal complete definition

integralDownsizeCheck

Methods

integralDownsize :: a -> b #

integralDownsize :: a ~ b => a -> b #

integralDownsizeCheck :: a -> Maybe b #

Instances

IntegralDownsize Int Int8 # 
IntegralDownsize Int Int16 # 
IntegralDownsize Int Int32 # 
IntegralDownsize Integer Int8 # 
IntegralDownsize Integer Int16 # 
IntegralDownsize Integer Int32 # 
IntegralDownsize Integer Int64 # 
IntegralDownsize Integer Word8 # 
IntegralDownsize Integer Word16 # 
IntegralDownsize Integer Word32 # 
IntegralDownsize Integer Word64 # 
IntegralDownsize Integer Natural # 
IntegralDownsize Word16 Word8 # 
IntegralDownsize Word32 Word8 # 
IntegralDownsize Word32 Word16 # 
IntegralDownsize Word64 Word8 # 
IntegralDownsize Word64 Word16 # 
IntegralDownsize Word64 Word32 # 
IntegralDownsize Natural Word8 # 
IntegralDownsize Natural Word16 # 
IntegralDownsize Natural Word32 # 
IntegralDownsize Natural Word64 # 

class IntegralCast a b where #

Cast an integral value to another value that have the same representional size

Methods

integralCast :: a -> b #

integralCast :: a ~ b => a -> b #