foundation-0.0.13: 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

primShiftToBytes :: Proxy ty -> Int

get the shift size

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

return the element stored at a specific index

primMbaURead

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

primMbaUWrite

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

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

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

unLE :: a
 

Instances

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

unBE :: a
 

Instances

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 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

Evaluation

class NormalForm a where

Data that can be fully evaluated in Normal Form

Methods

toNormalForm :: a -> ()

Instances

NormalForm Bool 
NormalForm Char 
NormalForm Double 
NormalForm Float 
NormalForm Int 
NormalForm Int8 
NormalForm Int16 
NormalForm Int32 
NormalForm Int64 
NormalForm Integer 
NormalForm Word 
NormalForm Word8 
NormalForm Word16 
NormalForm Word32 
NormalForm Word64 
NormalForm () 
NormalForm Natural 
NormalForm CChar 
NormalForm CSChar 
NormalForm CUChar 
NormalForm CShort 
NormalForm CUShort 
NormalForm CInt 
NormalForm CUInt 
NormalForm CLong 
NormalForm CULong 
NormalForm CLLong 
NormalForm CULLong 
NormalForm CFloat 
NormalForm CDouble 
NormalForm String 
NormalForm IPv4 
NormalForm IPv6 
NormalForm UUID 
NormalForm a => NormalForm [a] 
NormalForm (Ptr a) 
NormalForm a => NormalForm (Maybe a) 
NormalForm (CountOf a) 
NormalForm (Offset a) 
NormalForm a => NormalForm (BE a) 
NormalForm a => NormalForm (LE a) 
NormalForm a => NormalForm (Array a) 
NormalForm (Block ty) 
NormalForm (UArray ty) 
NormalForm (ChunkedUArray ty) 
(NormalForm l, NormalForm r) => NormalForm (Either l r) 
(NormalForm a, NormalForm b) => NormalForm (a, b) 
(NormalForm a, NormalForm b) => NormalForm (These a b) 
(NormalForm a, NormalForm b) => NormalForm (Tuple2 a b) 
(NormalForm a, NormalForm b, NormalForm c) => NormalForm (a, b, c) 
(NormalForm a, NormalForm b, NormalForm c) => NormalForm (Tuple3 a b c) 
(NormalForm a, NormalForm b, NormalForm c, NormalForm d) => NormalForm (a, b, c, d) 
(NormalForm a, NormalForm b, NormalForm c, NormalForm d) => NormalForm (Tuple4 a b c d) 
(NormalForm a, NormalForm b, NormalForm c, NormalForm d, NormalForm e) => NormalForm (a, b, c, d, e) 
(NormalForm a, NormalForm b, NormalForm c, NormalForm d, NormalForm e, NormalForm f) => NormalForm (a, b, c, d, e, f) 
(NormalForm a, NormalForm b, NormalForm c, NormalForm d, NormalForm e, NormalForm f, NormalForm g) => NormalForm (a, b, c, d, e, f, g) 
(NormalForm a, NormalForm b, NormalForm c, NormalForm d, NormalForm e, NormalForm f, NormalForm g, NormalForm h) => NormalForm (a, b, c, d, e, f, g, h) 

force :: NormalForm a => a -> a

deepseq :: NormalForm a => a -> b -> b

These

data These a b

Either a or b or both.

Constructors

This a 
That b 
These a b 

Instances

Bifunctor These 
Functor (These a) 
(Eq a, Eq b) => Eq (These a b) 
(Ord a, Ord b) => Ord (These a b) 
(Show a, Show b) => Show (These a b) 
(NormalForm a, NormalForm b) => NormalForm (These a b) 

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