Safe Haskell | None |
---|

Generic heap with reference counting. This module provides relatively low-level interface to the heap data structure, while keeping its internal representation hidden and consistent.

- type Ref = Int
- refDoc :: Ref -> Doc
- data Heap a
- emptyHeap :: Heap a
- at :: Show a => Heap a -> Ref -> a
- alloc :: a -> Heap a -> (Ref, Heap a)
- hasGarbage :: Heap a -> Bool
- dealloc :: Heap a -> (Ref, Heap a)
- update :: Ref -> a -> Heap a -> Heap a
- incRefCount :: Ref -> Heap a -> Heap a
- decRefCount :: Ref -> Heap a -> Heap a
- heapDoc :: Show a => Heap a -> Doc

# Documentation

alloc :: a -> Heap a -> (Ref, Heap a)Source

`alloc`

`v h`

: choose a free reference in heap `h`

and store value `v`

in there; return the reference and the updated heap

hasGarbage :: Heap a -> BoolSource

Does the heap have any garbage?

dealloc :: Heap a -> (Ref, Heap a)Source

Collect some garbage reference in the heap and return that reference and the new heap; the heap must have garbage

update :: Ref -> a -> Heap a -> Heap aSource

`update`

`r v h`

: set the value at reference `r`

to `v`

in `h`

;
`r`

must be present in `h`

incRefCount :: Ref -> Heap a -> Heap aSource

`incRefCount`

`r h`

: increase reference count of `r`

in `h`

;
`r`

must be present in `h`

decRefCount :: Ref -> Heap a -> Heap aSource

`decRefCount`

`r h`

: decrease reference count of `r`

in `h`

;
`r`

must be present in `h`