Created
April 29, 2022 21:37
-
-
Save carymrobbins/ea549b4df313a7b736e378879a1fe319 to your computer and use it in GitHub Desktop.
Example lifted functions from context: https://hackage.haskell.org/package/context
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ContextLifted where | |
import Control.Monad.Catch (MonadMask) | |
import Control.Monad.IO.Class | |
import qualified Context | |
import qualified Context.Internal | |
import qualified Control.Monad.Catch as Monad.Catch | |
adjust :: (MonadIO m, MonadMask m) => Context.Store ctx -> (ctx -> ctx) -> m a -> m a | |
adjust store f action = do | |
adjustedContext <- liftIO $ Context.mines store f | |
use store adjustedContext action | |
use :: (MonadIO m, MonadMask m) => Context.Store ctx -> ctx -> m a -> m a | |
use store context = | |
Monad.Catch.bracket_ | |
(liftIO $ Context.Internal.push store context) | |
(liftIO $ Context.Internal.pop store) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment