on master help sign in
Prefer Control.Exception to Control.Monad.Catch for IO
568ccb2Andrzej Rybczak
effectful.cabal+1−1
@@ -23,7 +23,7 @@ source-repository head
23 location: https://github.com/arybczak/effectful.git
23 location: https://github.com/arybczak/effectful.git
24
24
25common language
25common language
26− ghc-options: -Wall
26+ ghc-options: -Wall -Wcompat
27
27
28 default-language: Haskell2010
28 default-language: Haskell2010
29
29
src/Effectful/Internal/Monad.hs+13−10
@@ -43,8 +43,8 @@ module Effectful.Internal.Monad
43
43
44import Control.Applicative (liftA2)
44import Control.Applicative (liftA2)
45import Control.Concurrent (myThreadId)
45import Control.Concurrent (myThreadId)
46+import Control.Exception
46import Control.Monad.Base
47import Control.Monad.Base
47−import Control.Monad.Catch
48import Control.Monad.Fix
48import Control.Monad.Fix
49import Control.Monad.IO.Class
49import Control.Monad.IO.Class
50import Control.Monad.IO.Unlift
50import Control.Monad.IO.Unlift
@@ -52,6 +52,7 @@ import Control.Monad.Trans.Control
52import Data.Unique
52import Data.Unique
53import GHC.Magic (oneShot)
53import GHC.Magic (oneShot)
54import System.IO.Unsafe (unsafeDupablePerformIO)
54import System.IO.Unsafe (unsafeDupablePerformIO)
55+import qualified Control.Monad.Catch as E
55
56
56import Effectful.Internal.Effect
57import Effectful.Internal.Effect
57import Effectful.Internal.Env
58import Effectful.Internal.Env
@@ -149,17 +150,18 @@ instance MonadFix (Eff es) where
149----------------------------------------
150----------------------------------------
150-- Exception
151-- Exception
151
152
152−instance MonadThrow (Eff es) where
153+instance E.MonadThrow (Eff es) where
153− throwM = unsafeEff_ . throwM
154+ throwM = unsafeEff_ . throwIO
154
155
155−instance MonadCatch (Eff es) where
156+instance E.MonadCatch (Eff es) where
156 catch m handler = unsafeEff $ \es -> do
157 catch m handler = unsafeEff $ \es -> do
157 size <- sizeEnv es
158 size <- sizeEnv es
158 unEff m es `catch` \e -> do
159 unEff m es `catch` \e -> do
159 checkSizeEnv size es
160 checkSizeEnv size es
160 unEff (handler e) es
161 unEff (handler e) es
162+ {-# INLINABLE catch #-}
161
163
162−instance MonadMask (Eff es) where
164+instance E.MonadMask (Eff es) where
163 mask k = unsafeEff $ \es -> mask $ \restore ->
165 mask k = unsafeEff $ \es -> mask $ \restore ->
164 unEff (k $ \m -> unsafeEff $ restore . unEff m) es
166 unEff (k $ \m -> unsafeEff $ restore . unEff m) es
165
167
@@ -171,11 +173,12 @@ instance MonadMask (Eff es) where
171 resource <- unEff acquire es
173 resource <- unEff acquire es
172 b <- restore (unEff (use resource) es) `catch` \e -> do
174 b <- restore (unEff (use resource) es) `catch` \e -> do
173 checkSizeEnv size es
175 checkSizeEnv size es
174− _ <- unEff (release resource $ ExitCaseException e) es
176+ _ <- unEff (release resource $ E.ExitCaseException e) es
175− throwM e
177+ throwIO e
176 checkSizeEnv size es
178 checkSizeEnv size es
177− c <- unEff (release resource $ ExitCaseSuccess b) es
179+ c <- unEff (release resource $ E.ExitCaseSuccess b) es
178 pure (b, c)
180 pure (b, c)
181+ {-# INLINABLE generalBracket #-}
179
182
180----------------------------------------
183----------------------------------------
181-- Fail
184-- Fail
@@ -196,7 +199,7 @@ runFail m = unsafeEff $ \es0 -> mask $ \release -> do
196
199
197instance Fail :> es => MonadFail (Eff es) where
200instance Fail :> es => MonadFail (Eff es) where
198 fail msg = readerEffectM $ \(IdE (Fail tag)) -> unsafeEff_ $ do
201 fail msg = readerEffectM $ \(IdE (Fail tag)) -> unsafeEff_ $ do
199− throwM $ FailEx tag msg
202+ throwIO $ FailEx tag msg
200
203
201--------------------
204--------------------
202
205
@@ -212,7 +215,7 @@ tryFailIO tag m =
212 (Right <$> m) `catch` \err@(FailEx etag msg) -> do
215 (Right <$> m) `catch` \err@(FailEx etag msg) -> do
213 if tag == etag
216 if tag == etag
214 then pure $ Left msg
217 then pure $ Left msg
215− else throwM err
218+ else throwIO err
216
219
217----------------------------------------
220----------------------------------------
218-- IO
221-- IO
src/Effectful/Interpreter.hs+1−1
@@ -16,7 +16,7 @@ module Effectful.Interpreter
16 , reinterpretIO
16 , reinterpretIO
17 ) where
17 ) where
18
18
19−import Control.Monad.Catch
19+import Control.Exception
20import GHC.Stack
20import GHC.Stack
21
21
22import Effectful.Internal.Effect
22import Effectful.Internal.Effect
src/Effectful/Writer.hs+1−1
@@ -8,7 +8,7 @@ module Effectful.Writer
8 , listens
8 , listens
9 ) where
9 ) where
10
10
11−import Control.Monad.Catch
11+import Control.Exception
12
12
13import Effectful.Internal.Effect
13import Effectful.Internal.Effect
14import Effectful.Internal.Env
14import Effectful.Internal.Env
src/Effectful/Writer/MVar.hs+1−1
@@ -8,7 +8,7 @@ module Effectful.Writer.MVar
8 ) where
8 ) where
9
9
10import Control.Concurrent.MVar
10import Control.Concurrent.MVar
11−import Control.Monad.Catch
11+import Control.Exception
12
12
13import Effectful.Internal.Effect
13import Effectful.Internal.Effect
14import Effectful.Internal.Env
14import Effectful.Internal.Env