packages feed

general-allocate 0.2.2.0 → 0.2.3.0

raw patch · 3 files changed

+22/−2 lines, 3 filesdep +exceptions

Dependencies added: exceptions

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for general-allocate +## 0.2.3.0 -- 2024-01-12++* `MonadWith` instance for `CatchT`+ ## 0.2.2.0 -- 2024-01-11  * Allow newer versions of some dependencies
general-allocate.cabal view
@@ -1,6 +1,6 @@ cabal-version:      3.0 name:               general-allocate-version:            0.2.2.0+version:            0.2.3.0 license:            Apache-2.0 license-file:       LICENSE author:             Shea Levy@@ -54,6 +54,7 @@     , primitive        ^>= { 0.7, 0.8, 0.9 }     , resourcet        ^>= { 1.3 }     , safe-exceptions  ^>= { 0.1 }+    , exceptions       ^>= { 0.10 }     , transformers     ^>= { 0.5, 0.6 }       -- At transformers >= 0.6, remove the Monad (t m) constraint on MonadAllocate AllocateViaLift 
src/Control/Monad/With.hs view
@@ -28,7 +28,8 @@ module Control.Monad.With where  import Control.Exception.Safe-import Control.Monad+import Control.Monad.Catch.Pure (CatchT (..))+import qualified Control.Monad.Catch.Pure as Catch import Control.Monad.Except import qualified Control.Monad.RWS.Lazy as L import Control.Monad.RWS.Strict@@ -295,6 +296,20 @@      where       restore' ∷ ∀ x. ExceptT e m x → ExceptT e m x       restore' = ExceptT . restore . runExceptT++instance (Monad m, ∀ x y. Coercible x y ⇒ Coercible (m x) (m y)) ⇒ MonadWith (CatchT m) where+  stateThreadingGeneralWith (GeneralAllocate allocA) go =+    CatchT $+      runCatchT (allocA id) >>= \case+        Left e → pure $ Left e+        Right (GeneralAllocated a releaseA) →+          runCatchT (go a) >>= \case+            Left e → runCatchT $ do+              _ ← releaseA $ ReleaseFailure e+              Catch.throwM e+            Right b → runCatchT $ do+              c ← releaseA $ ReleaseSuccess b+              pure (b, c)  instance MonadWith m ⇒ MonadWith (IdentityT m) where   type WithException (IdentityT m) = WithException m