diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2022-07-17 21:51:30 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2022-07-17 22:32:55 +0200 |
commit | 479b63d8c30c0bc6e6475882d7fb573db5dad1f9 (patch) | |
tree | af2ebc889628de1b7c8dfdb3ed64d5733ba00bb4 /src/State.hs | |
parent | 36eb3a419ec9d0434f55456090e2845d4ac20b58 (diff) |
MonadStorage for context with Storage instance
Diffstat (limited to 'src/State.hs')
-rw-r--r-- | src/State.hs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/State.hs b/src/State.hs index 358d958..e112aca 100644 --- a/src/State.hs +++ b/src/State.hs @@ -2,7 +2,7 @@ module State ( LocalState(..), SharedState, SharedType(..), SharedTypeID, mkSharedTypeID, - MonadHead(..), + MonadStorage(..), MonadHead(..), loadLocalStateHead, updateLocalState, updateLocalState_, @@ -81,9 +81,15 @@ instance SharedType (Maybe ComposedIdentity) where sharedTypeID _ = mkSharedTypeID "0c6c1fe0-f2d7-4891-926b-c332449f7871" -class MonadHead a m where +class Monad m => MonadStorage m where + getStorage :: m Storage + +class MonadStorage m => MonadHead a m where updateLocalHead :: (Stored a -> IO (Stored a, b)) -> m b +instance Monad m => MonadStorage (ReaderT (Head a) m) where + getStorage = asks $ refStorage . headRef + instance (HeadType a, MonadIO m) => MonadHead a (ReaderT (Head a) m) where updateLocalHead f = do h <- ask |