
\subsection{Identifier generator}

Generates unique elements without recycling of identifiers.

\begin{haskelllisting}

> module Haskore.General.IdGeneratorSimple where

> import Control.Monad.State(State,evalState,modify,get,when)

\end{haskelllisting}

The generator is a simple state monad.

\begin{haskelllisting}

> type T i a = State i a

> run :: i -> T i a -> a
> run = flip evalState

\end{haskelllisting}

Reserve a new id.

\begin{haskelllisting}

> alloc :: (Enum i) => T i i
> alloc =
>    do newId <- get
>       modify succ
>       return newId

\end{haskelllisting}

Unreserve an id.
In this implementation it performs essentially nothing.

\begin{haskelllisting}

> free :: (Ord i) => i -> T i ()
> free oldId =
>    do freeId <- get
>       when (freeId <= oldId)
>            (error "IdGeneratorSimple.free: freed unreserved id")

\end{haskelllisting}
