Copyright | (C) 2015-2017 Edward Kmett |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Unsafe |
Language | Haskell2010 |
Synopsis
- data NullPointerException = NullPointerException
- data Dict p where
- st :: PrimMonad m => ST (PrimState m) a -> m a
- class Struct t where
- data Object s = Object {}
- coerceF :: Dict (Coercible a b) -> a -> b
- coerceB :: Dict (Coercible a b) -> b -> a
- destruct :: Struct t => t s -> SmallMutableArray# s Any
- construct :: Struct t => SmallMutableArray# s Any -> t s
- unsafeCoerceStruct :: (Struct x, Struct y) => x s -> y s
- eqStruct :: Struct t => t s -> t s -> Bool
- pattern Struct :: Struct t => SmallMutableArray# s Any -> t s
- alloc :: (PrimMonad m, Struct t) => Int -> m (t (PrimState m))
- data Box = Box Null
- data Null = Null
- isNil :: Struct t => t s -> Bool
- pattern Nil :: Struct t => t s
- writeSmallMutableArraySmallArray# :: SmallMutableArray# s Any -> Int# -> SmallMutableArray# s Any -> State# s -> State# s
- readSmallMutableArraySmallArray# :: SmallMutableArray# s Any -> Int# -> State# s -> (# State# s, SmallMutableArray# s Any #)
- writeMutableByteArraySmallArray# :: SmallMutableArray# s Any -> Int# -> MutableByteArray# s -> State# s -> State# s
- readMutableByteArraySmallArray# :: SmallMutableArray# s Any -> Int# -> State# s -> (# State# s, MutableByteArray# s #)
- casSmallMutableArraySmallArray# :: SmallMutableArray# s Any -> Int# -> SmallMutableArray# s Any -> SmallMutableArray# s Any -> State# s -> (# State# s, Int#, SmallMutableArray# s Any #)
- data Slot x y = Slot (forall s. SmallMutableArray# s Any -> State# s -> (# State# s, SmallMutableArray# s Any #)) (forall s. SmallMutableArray# s Any -> SmallMutableArray# s Any -> State# s -> State# s) (forall s. SmallMutableArray# s Any -> SmallMutableArray# s Any -> SmallMutableArray# s Any -> State# s -> (# State# s, Int#, SmallMutableArray# s Any #))
- class Precomposable t where
- slot :: Int -> Slot s t
- get :: (PrimMonad m, Struct x, Struct y) => Slot x y -> x (PrimState m) -> m (y (PrimState m))
- set :: (PrimMonad m, Struct x, Struct y) => Slot x y -> x (PrimState m) -> y (PrimState m) -> m ()
- cas :: (PrimMonad m, Struct x, Struct y) => Slot x y -> x (PrimState m) -> y (PrimState m) -> y (PrimState m) -> m (Bool, y (PrimState m))
- data Field x a = Field (forall s. SmallMutableArray# s Any -> State# s -> (# State# s, a #)) (forall s. SmallMutableArray# s Any -> a -> State# s -> State# s)
- field :: Int -> Field s a
- unboxedField :: Prim a => Int -> Int -> Field s a
- initializeUnboxedField :: (PrimMonad m, Struct x) => Int -> Int -> Int -> x (PrimState m) -> m (MutableByteArray (PrimState m))
- getField :: (PrimMonad m, Struct x) => Field x a -> x (PrimState m) -> m a
- setField :: (PrimMonad m, Struct x) => Field x a -> x (PrimState m) -> a -> m ()
- modifyField :: (Struct x, PrimMonad m) => Field x a -> x (PrimState m) -> (a -> a) -> m ()
- modifyField' :: (Struct x, PrimMonad m) => Field x a -> x (PrimState m) -> (a -> a) -> m ()
Documentation
>>>
import Control.Monad.Primitive
data NullPointerException Source #
Instances
Exception NullPointerException Source # | |
Defined in Data.Struct.Internal | |
Show NullPointerException Source # | |
Defined in Data.Struct.Internal showsPrec :: Int -> NullPointerException -> ShowS # show :: NullPointerException -> String # showList :: [NullPointerException] -> ShowS # |
A Dict
reifies an instance of the constraint p
into a value.
st :: PrimMonad m => ST (PrimState m) a -> m a Source #
Run an ST calculation inside of a PrimMonad. This lets us avoid dispatching everything through the PrimMonad
dictionary.
An instance for Struct
t
is a witness to the machine-level
equivalence of t
and Object
.
Nothing
unsafeCoerceStruct :: (Struct x, Struct y) => x s -> y s Source #
alloc :: (PrimMonad m, Struct t) => Int -> m (t (PrimState m)) Source #
Allocate a structure made out of n
slots. Initialize the structure before proceeding!
Tony Hoare's billion dollar mistake
isNil :: Struct t => t s -> Bool Source #
Predicate to check if a struct is Nil
.
>>>
isNil (Nil :: Object (PrimState IO))
True>>>
o <- alloc 1 :: IO (Object (PrimState IO))
>>>
isNil o
False
Faking SmallMutableArrayArray#s
writeSmallMutableArraySmallArray# :: SmallMutableArray# s Any -> Int# -> SmallMutableArray# s Any -> State# s -> State# s Source #
readSmallMutableArraySmallArray# :: SmallMutableArray# s Any -> Int# -> State# s -> (# State# s, SmallMutableArray# s Any #) Source #
writeMutableByteArraySmallArray# :: SmallMutableArray# s Any -> Int# -> MutableByteArray# s -> State# s -> State# s Source #
readMutableByteArraySmallArray# :: SmallMutableArray# s Any -> Int# -> State# s -> (# State# s, MutableByteArray# s #) Source #
casSmallMutableArraySmallArray# :: SmallMutableArray# s Any -> Int# -> SmallMutableArray# s Any -> SmallMutableArray# s Any -> State# s -> (# State# s, Int#, SmallMutableArray# s Any #) Source #
Field Accessors
A Slot
is a reference to another unboxed mutable object.
Slot (forall s. SmallMutableArray# s Any -> State# s -> (# State# s, SmallMutableArray# s Any #)) (forall s. SmallMutableArray# s Any -> SmallMutableArray# s Any -> State# s -> State# s) (forall s. SmallMutableArray# s Any -> SmallMutableArray# s Any -> SmallMutableArray# s Any -> State# s -> (# State# s, Int#, SmallMutableArray# s Any #)) |
class Precomposable t where Source #
We can compose slots to get a nested slot or field accessor
get :: (PrimMonad m, Struct x, Struct y) => Slot x y -> x (PrimState m) -> m (y (PrimState m)) Source #
Get the value from a Slot
set :: (PrimMonad m, Struct x, Struct y) => Slot x y -> x (PrimState m) -> y (PrimState m) -> m () Source #
Set the value of a Slot
cas :: (PrimMonad m, Struct x, Struct y) => Slot x y -> x (PrimState m) -> y (PrimState m) -> y (PrimState m) -> m (Bool, y (PrimState m)) Source #
Compare-and-swap the value of the slot. Takes the expected old value, the new value and returns if it succeeded and the value found.
A Field
is a reference from a struct to a normal Haskell data type.
Field (forall s. SmallMutableArray# s Any -> State# s -> (# State# s, a #)) (forall s. SmallMutableArray# s Any -> a -> State# s -> State# s) |
Store the reference to the Haskell data type in a normal field
Store the reference in the nth slot in the nth argument, treated as a MutableByteArray
initializeUnboxedField Source #
:: (PrimMonad m, Struct x) | |
=> Int | slot |
-> Int | elements |
-> Int | element size |
-> x (PrimState m) | struct |
-> m (MutableByteArray (PrimState m)) |
Initialized the mutable array used by unboxedField
. Returns the array
after storing it in the struct to help with initialization.
getField :: (PrimMonad m, Struct x) => Field x a -> x (PrimState m) -> m a Source #
Get the value of a field in a struct
setField :: (PrimMonad m, Struct x) => Field x a -> x (PrimState m) -> a -> m () Source #
Set the value of a field in a struct