| Copyright | Jeremy Groven |
|---|---|
| License | BSD3 |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.StableTree.Persist
Description
Logic for dealing with the actual persistence of Stable Trees. The key
exports here are Error, Store, load, and store. A user needs to
implement the loadTree, loadValue, storeTree and storeValue parts of
Store, and make an appropriate Error type to report storage errors, and
then the load and store functions can just do their thing. If necessary,
a user can also implement Serialize for custom data types.
- class Error e where
- stableTreeError :: Text -> e
- load :: (Monad m, Error e, Ord k, Serialize k, Serialize v) => (a -> ObjectID -> m (Either e (a, Fragment k v))) -> a -> ObjectID -> m (Either e (a, StableTree k v))
- load' :: (Monad m, Error e, Ord k, Serialize k, Serialize v) => (ObjectID -> m (Either e (Fragment k v))) -> ObjectID -> m (Either e (StableTree k v))
- store :: (Monad m, Error e, Ord k) => (a -> ObjectID -> Fragment k v -> m (Either e a)) -> a -> StableTree k v -> m (Either e a)
- store' :: (Monad m, Error e, Ord k) => (ObjectID -> Fragment k v -> m (Maybe e)) -> StableTree k v -> m (Either e ObjectID)
Documentation
Things go wrong with end-user storage, but things can also go wrong with
reconstructing tree values. Implement stableTreeError to allow load and
store to report their own errors.
Methods
stableTreeError :: Text -> e Source
load :: (Monad m, Error e, Ord k, Serialize k, Serialize v) => (a -> ObjectID -> m (Either e (a, Fragment k v))) -> a -> ObjectID -> m (Either e (a, StableTree k v)) Source
load' :: (Monad m, Error e, Ord k, Serialize k, Serialize v) => (ObjectID -> m (Either e (Fragment k v))) -> ObjectID -> m (Either e (StableTree k v)) Source
store :: (Monad m, Error e, Ord k) => (a -> ObjectID -> Fragment k v -> m (Either e a)) -> a -> StableTree k v -> m (Either e a) Source
Record the tree into storage. This works like a fold, where the function takes an accumulating state and each tree fragment to store, while returning either an error message (which will abort the loop immediately) or the next state for the accumulator.
Any fragment referring to other fragments (FragmentBranch fragments) will
be given to the fold only after all their children have been given to the
fold. Exact ordering beyond that is not guaranteed, but the current
behaviour is post-order depth-first traversal.