Safe Haskell | None |
---|---|
Language | Haskell2010 |
Mem
is a data structure that is a simulation of an array of thread-local pointers. This structure supports:
- \( O(n) \) creation of a new pointer;
- \( O(n) \) changing the pointer in an array cell;
- \( O(1) \) modification of the memory a pointer points to;
- \( O(1) \) read.
This is an internal module and its API may change even between minor versions. Therefore you should be extra careful if you're to depend on this module.
Synopsis
- data Mem (f :: k -> Type) (es :: [k])
- data MemPtr (f :: k -> Type) (a :: k)
- empty :: Mem f '[]
- adjust :: forall es' es f. (Rec (MemPtr f) es -> Rec (MemPtr f) es') -> Mem f es -> Mem f es'
- alloca :: forall e es f. Mem f es -> (# MemPtr f e, Mem f es #)
- read :: forall e es f. Elem e es => Mem f es -> f e
- write :: forall e es f. MemPtr f e -> f e -> Mem f es -> Mem f es
- replace :: forall e es f. Elem e es => MemPtr f e -> f e -> Mem f es -> Mem f es
- append :: forall e es f. MemPtr f e -> f e -> Mem f es -> Mem f (e ': es)
- update :: forall es es' f. Mem f es' -> Mem f es -> Mem f es
Documentation
data Mem (f :: k -> Type) (es :: [k]) Source #
A simulated array of thread-local pointers. This means for each array cell, you can either change the pointer or change the memory the pointer points to.
Note that like real memory, any of the operations provided is not generally safe and it is your responsibility to ensure the correctness of your calls.
data MemPtr (f :: k -> Type) (a :: k) Source #
The representation of a pointer in a Mem
.
Instances
Eq (MemPtr f a) Source # | Pointer equality. |
Ord (MemPtr f a) Source # | An arbitrary total order on the pointers. |
adjust :: forall es' es f. (Rec (MemPtr f) es -> Rec (MemPtr f) es') -> Mem f es -> Mem f es' Source #
Adjust the array of pointers.
alloca :: forall e es f. Mem f es -> (# MemPtr f e, Mem f es #) Source #
Allocate a new address. \( O(1) \).
write :: forall e es f. MemPtr f e -> f e -> Mem f es -> Mem f es Source #
Write to the memory a pointer points to. \( O(1) \).
replace :: forall e es f. Elem e es => MemPtr f e -> f e -> Mem f es -> Mem f es Source #
Replace a pointer with a new one. \( O(n) \).