cleff-0.1.0.0: Fast and concise extensible effects
Safe HaskellNone
LanguageHaskell2010

Data.Mem

Description

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

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

Instances details
Eq (MemPtr f a) Source #

Pointer equality.

Instance details

Defined in Data.Mem

Methods

(==) :: MemPtr f a -> MemPtr f a -> Bool #

(/=) :: MemPtr f a -> MemPtr f a -> Bool #

Ord (MemPtr f a) Source #

An arbitrary total order on the pointers.

Instance details

Defined in Data.Mem

Methods

compare :: MemPtr f a -> MemPtr f a -> Ordering #

(<) :: MemPtr f a -> MemPtr f a -> Bool #

(<=) :: MemPtr f a -> MemPtr f a -> Bool #

(>) :: MemPtr f a -> MemPtr f a -> Bool #

(>=) :: MemPtr f a -> MemPtr f a -> Bool #

max :: MemPtr f a -> MemPtr f a -> MemPtr f a #

min :: MemPtr f a -> MemPtr f a -> MemPtr f a #

empty :: Mem f '[] Source #

Create a Mem with no 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) \).

read :: forall e es f. Elem e es => Mem f es -> f e Source #

Read a pointer. \( 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) \).

append :: forall e es f. MemPtr f e -> f e -> Mem f es -> Mem f (e ': es) Source #

Add a new pointer to the array. \( O(n) \).

update :: forall es es' f. Mem f es' -> Mem f es -> Mem f es Source #

Use the memory of LHS as a newer version for the memory of RHS. \( O(1) \).