Skip to content

Instantly share code, notes, and snippets.

@carymrobbins
Created April 29, 2022 21:37
Show Gist options
  • Save carymrobbins/ea549b4df313a7b736e378879a1fe319 to your computer and use it in GitHub Desktop.
Save carymrobbins/ea549b4df313a7b736e378879a1fe319 to your computer and use it in GitHub Desktop.
Example lifted functions from context: https://hackage.haskell.org/package/context
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