Copyright | (C) 2015 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 |
- 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#)
- 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)
- 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 ()
- 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
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
destruct :: Struct t => t s -> SmallMutableArray# s Any Source
construct :: Struct t => SmallMutableArray# s Any -> t s Source
unsafeCoerceStruct :: (Struct x, Struct y) => x s -> y s Source
pattern Struct :: () => Struct t => SmallMutableArray# s (Any *) -> t 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
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) |
Precomposable k k (Slot k k) Source |
class Precomposable t where Source
We can compose slots to get a nested slot or field accessor
Precomposable k * (Field k) Source | |
Precomposable k k (Slot k k) Source |
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
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) |
Precomposable k * (Field k) Source |
Store the reference in the nth slot in the nth argument, treated as a MutableByteArray
:: (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
Modifiers
modifyField :: (Struct x, PrimMonad m) => Field x a -> x (PrimState m) -> (a -> a) -> m () Source
modifyField' :: (Struct x, PrimMonad m) => Field x a -> x (PrimState m) -> (a -> a) -> m () Source