on master help sign in
Prefer Control.Exception to Control.Monad.Catch for IO
commit568ccb26aa28370fe3b6d1eb6571897bf1f6c07c authorAndrzej Rybczak <andrzej@rybczak.net> dateThu 1 Jul 2021, 16:13 (5 years ago) parentfcfd87e
5 files changed+17−14
effectful.cabal+1−1 src/Effectful/Internal/Monad.hs+13−10 src/Effectful/Interpreter.hs+1−1 src/Effectful/Writer.hs+1−1 src/Effectful/Writer/MVar.hs+1−1
effectful.cabal+1−1
@@ -23,7 +23,7 @@ source-repository head
2323 location: https://github.com/arybczak/effectful.git
2424
2525common language
26− ghc-options: -Wall
26+ ghc-options: -Wall -Wcompat
2727
2828 default-language: Haskell2010
2929
src/Effectful/Internal/Monad.hs+13−10
@@ -43,8 +43,8 @@ module Effectful.Internal.Monad
4343
4444import Control.Applicative (liftA2)
4545import Control.Concurrent (myThreadId)
46+import Control.Exception
4647import Control.Monad.Base
47−import Control.Monad.Catch
4848import Control.Monad.Fix
4949import Control.Monad.IO.Class
5050import Control.Monad.IO.Unlift
@@ -52,6 +52,7 @@ import Control.Monad.Trans.Control
5252import Data.Unique
5353import GHC.Magic (oneShot)
5454import System.IO.Unsafe (unsafeDupablePerformIO)
55+import qualified Control.Monad.Catch as E
5556
5657import Effectful.Internal.Effect
5758import Effectful.Internal.Env
@@ -149,17 +150,18 @@ instance MonadFix (Eff es) where
149150----------------------------------------
150151-- Exception
151152
152−instance MonadThrow (Eff es) where
153− throwM = unsafeEff_ . throwM
153+instance E.MonadThrow (Eff es) where
154+ throwM = unsafeEff_ . throwIO
154155
155−instance MonadCatch (Eff es) where
156+instance E.MonadCatch (Eff es) where
156157 catch m handler = unsafeEff $ \es -> do
157158 size <- sizeEnv es
158159 unEff m es `catch` \e -> do
159160 checkSizeEnv size es
160161 unEff (handler e) es
162+ {-# INLINABLE catch #-}
161163
162−instance MonadMask (Eff es) where
164+instance E.MonadMask (Eff es) where
163165 mask k = unsafeEff $ \es -> mask $ \restore ->
164166 unEff (k $ \m -> unsafeEff $ restore . unEff m) es
165167
@@ -171,11 +173,12 @@ instance MonadMask (Eff es) where
171173 resource <- unEff acquire es
172174 b <- restore (unEff (use resource) es) `catch` \e -> do
173175 checkSizeEnv size es
174− _ <- unEff (release resource $ ExitCaseException e) es
175− throwM e
176+ _ <- unEff (release resource $ E.ExitCaseException e) es
177+ throwIO e
176178 checkSizeEnv size es
177− c <- unEff (release resource $ ExitCaseSuccess b) es
179+ c <- unEff (release resource $ E.ExitCaseSuccess b) es
178180 pure (b, c)
181+ {-# INLINABLE generalBracket #-}
179182
180183----------------------------------------
181184-- Fail
@@ -196,7 +199,7 @@ runFail m = unsafeEff $ \es0 -> mask $ \release -> do
196199
197200instance Fail :> es => MonadFail (Eff es) where
198201 fail msg = readerEffectM $ \(IdE (Fail tag)) -> unsafeEff_ $ do
199− throwM $ FailEx tag msg
202+ throwIO $ FailEx tag msg
200203
201204--------------------
202205
@@ -212,7 +215,7 @@ tryFailIO tag m =
212215 (Right <$> m) `catch` \err@(FailEx etag msg) -> do
213216 if tag == etag
214217 then pure $ Left msg
215− else throwM err
218+ else throwIO err
216219
217220----------------------------------------
218221-- IO
src/Effectful/Interpreter.hs+1−1
@@ -16,7 +16,7 @@ module Effectful.Interpreter
1616 , reinterpretIO
1717 ) where
1818
19−import Control.Monad.Catch
19+import Control.Exception
2020import GHC.Stack
2121
2222import Effectful.Internal.Effect
src/Effectful/Writer.hs+1−1
@@ -8,7 +8,7 @@ module Effectful.Writer
88 , listens
99 ) where
1010
11−import Control.Monad.Catch
11+import Control.Exception
1212
1313import Effectful.Internal.Effect
1414import Effectful.Internal.Env
src/Effectful/Writer/MVar.hs+1−1
@@ -8,7 +8,7 @@ module Effectful.Writer.MVar
88 ) where
99
1010import Control.Concurrent.MVar
11−import Control.Monad.Catch
11+import Control.Exception
1212
1313import Effectful.Internal.Effect
1414import Effectful.Internal.Env