io-storage-0.3: A key-value store in the IO monad.

Safe Haskell | None
Language | Haskell98

System.IO.Storage

Description

Conceptually, this library provides a way to arbitrarily extend the global state represented by the IO monad. Viewed another way, this library provides a basic facility for setting and retrieving values from global variables.

The interface takes the form of a very basic key-value store, with multiple different stores made available through the `withStore` function. Stores are referenced by arbitrary strings, and keys within those stores are treated likewise. The `putValue`, `getValue`, and `delValue` functions allow you to store, retrieve, and delete data from the store.

Internally, data is stored within an IORef which is created using the 'unsafePerformIO hack', but this is hidden within the library so that it can easily be modified if and when a more `proper` solution is implemented.

Synopsis

- withStore :: String -> IO a -> IO a
- putValue :: Typeable a => String -> String -> a -> IO ()
- getValue :: Typeable a => String -> String -> IO (Maybe a)
- getDefaultValue :: Typeable a => String -> String -> a -> IO a
- delValue :: String -> String -> IO ()

# Documentation

withStore :: String -> IO a -> IO a Source #

Create a named key-value store, and then execute the given IO action within its extent. Calls to `withStore` can be nested, and calling it again with the name of a data-store that has already been initialized will cause the original to be shadowed for the duration of the call to `withStore`.

putValue :: Typeable a => String -> String -> a -> IO () Source #

Put a value into the given data-store.

getValue :: Typeable a => String -> String -> IO (Maybe a) Source #

Get a value from the given data-store, if it exists. If it doesn't exist, obviously, `Nothing` will be returned.

getDefaultValue :: Typeable a => String -> String -> a -> IO a Source #

Get a value from the given store, with a default if it doesn't exist.

delValue :: String -> String -> IO () Source #

Delete a value from the given data-store.