HMap-1.1.3: Fast heterogeneous maps and unconstrained typeable like functionality.

Safe HaskellNone

Data.HKey

Contents

Synopsis

Documentation

data HKey s a Source

The datatype of Keys.

x
The scope of this key. This can either be T for top-level keys created with createKey or an existential type for keys introduced by withKey (or with the Key monad KeyM).
a
The type of things that can be sorted at this key.

For example, Key T Int is a top-level key that can be used to store values of type Int in a heterogenous map.

withKey :: (forall x. HKey x a -> b) -> bSource

O(1). Scopes a key to the given function The key cannot escape the function (because of the existential type).

The implementation actually *creates* a key, but because the key cannot escape the given function f, there is no way to observe that if we run withKey f twice, that it will get a different key the second time.

data T Source

The scope of top-level keys.

createKey :: IO (HKey T a)Source

O(1). Create a new top-level key.

Key Monad

type KeyM s a = KeyT s Identity aSource

A monad that can be used to create keys Keys cannot escape the monad, analogous to the ST Monad. Can be used instead of the withKey function if you need an statically unknown number of keys.

getKey :: KeyT s m (HKey s a)Source

Obtain a key in the key monad

runKeyT :: forall m a. Monad m => (forall s. KeyT s m a) -> m aSource

Run a key monad. Existential type makes sure keys cannot escape.