on master help sign in
Remove Except as it's needed in pure code for handling Error
commit453705564996c248d828cfe563c3e69f30f26e5b authorAndrzej Rybczak <andrzej@rybczak.net> dateFri 2 Jul 2021, 17:37 (5 years ago) parent36968f4
6 files changed+12−35
src/Effectful.hs−6 src/Effectful/Error.hs+2−2 src/Effectful/Internal/Monad.hs+3−16 src/Effectful/Monad.hs−4 tests/ErrorTests.hs+1−1 tests/StateTests.hs+6−6
src/Effectful.hs−6
@@ -15,15 +15,9 @@ module Effectful
1515 , runEff
1616
1717 -- ** Operations with side effects
18−
19− -- *** Arbitrary I/O
2018 , IOE
2119 , runIOE
2220
23− -- *** Runtime exceptions
24− , Except
25− , runExcept
26−
2721 -- * Building 'Effect' handlers
2822
2923 -- ** Basic handlers
src/Effectful/Error.hs+2−2
@@ -3,7 +3,7 @@
33The 'Error' effect provided by this module is a suitable replacement for the
44'Control.Monad.Except.ExceptT' monad transformer found in the @mtl@ library. It
55is __not__ intended to be a general mechanism for catching errors, that's what
6−the 'Except' effect is for.
6+functions from the "Control.Monad.Catch" module are for.
77
88For example, if you want to catch an unchecked exception like
99'Control.Exception.SomeException' or 'Control.Exception.ErrorCall' you could use
@@ -14,7 +14,7 @@ For example, if you want to catch an unchecked exception like
1414 let boom :: Eff es String
1515 boom = error "BOOM!"
1616 in
17− runIOE . runExcept $ boom `E.catch` \(e :: ErrorCall) -> pure "caught some error"
17+ runIOE $ boom `E.catch` \(e :: ErrorCall) -> pure "caught some error"
1818:}
1919"caught some error"
2020
src/Effectful/Internal/Monad.hs+3−16
@@ -25,10 +25,6 @@ module Effectful.Internal.Monad
2525 , IOE
2626 , runIOE
2727
28− -- * Except
29− , Except
30− , runExcept
31−
3228 -- * Low-level helpers
3329
3430 -- ** Running
@@ -178,19 +174,10 @@ instance MonadFix (Eff es) where
178174----------------------------------------
179175-- Exception
180176
181−-- | Handle runtime exceptions via 'E.MonadThrow', 'E.MonadCatch' and
182−-- 'E.MonadMask'.
183−data Except :: Effect where
184− Except :: Except m r
185−
186−-- | Introduce the ability to handle runtime exceptions.
187−runExcept :: IOE :> es => Eff (Except : es) a -> Eff es a
188−runExcept = evalEffect (IdE Except)
189−
190−instance Except :> es => E.MonadThrow (Eff es) where
177+instance E.MonadThrow (Eff es) where
191178 throwM = unsafeEff_ . throwIO
192179
193−instance Except :> es => E.MonadCatch (Eff es) where
180+instance E.MonadCatch (Eff es) where
194181 catch m handler = unsafeEff $ \es -> do
195182 size <- sizeEnv es
196183 unEff m es `catch` \e -> do
@@ -198,7 +185,7 @@ instance Except :> es => E.MonadCatch (Eff es) where
198185 unEff (handler e) es
199186 {-# INLINABLE catch #-}
200187
201−instance Except :> es => E.MonadMask (Eff es) where
188+instance E.MonadMask (Eff es) where
202189 mask k = unsafeEff $ \es -> mask $ \restore ->
203190 unEff (k $ \m -> unsafeEff $ restore . unEff m) es
204191
src/Effectful/Monad.hs−4
@@ -10,10 +10,6 @@ module Effectful.Monad
1010 -- * Arbitrary I/O
1111 , IOE
1212 , runIOE
13−
14− -- * Exception handling
15− , Except
16− , runExcept
1713 ) where
1814
1915import Effectful.Internal.Effect
tests/ErrorTests.hs+1−1
@@ -31,5 +31,5 @@ data NestedErr :: Effect where
3131nestedErr :: (HasCallStack, NestedErr :> es) => Eff es ()
3232nestedErr = send NestedErr
3333
34−runNestedErr :: Error String :> es => Eff (NestedErr : es) a -> Eff es a
34+runNestedErr :: Errors '[String] es => Eff (NestedErr : es) a -> Eff es a
3535runNestedErr = interpret $ \NestedErr -> throwError "nested error"
tests/StateTests.hs+6−6
@@ -50,7 +50,7 @@ test_deepStack = runIOE $ do
5050 U.assertEqual "n" 15 n
5151
5252test_exceptions :: Assertion
53−test_exceptions = runIOE . runExcept $ do
53+test_exceptions = runIOE $ do
5454 testTry "exceptions" E.try
5555 testCatch "exceptions" E.catch
5656 testTry "lifted-base" LE.try
@@ -60,8 +60,8 @@ test_exceptions = runIOE . runExcept $ do
6060 where
6161 testTry
6262 :: String
63− -> (forall a es. (IOE :> es, Except :> es) => Eff es a -> Eff es (Either U.Ex a))
64− -> Eff '[Except, IOE] ()
63+ -> (forall a es. IOE :> es => Eff es a -> Eff es (Either U.Ex a))
64+ -> Eff '[IOE] ()
6565 testTry lib tryImpl = do
6666 e <- tryImpl $ runState (0::Int) action
6767 U.assertEqual (lib ++ " - exception caught") e (Left U.Ex)
@@ -70,15 +70,15 @@ test_exceptions = runIOE . runExcept $ do
7070
7171 testCatch
7272 :: String
73− -> (forall a es. (IOE :> es, Except :> es) => Eff es a -> (U.Ex -> Eff es a) -> Eff es a)
74− -> Eff '[Except, IOE] ()
73+ -> (forall a es. IOE :> es => Eff es a -> (U.Ex -> Eff es a) -> Eff es a)
74+ -> Eff '[IOE] ()
7575 testCatch lib catchImpl = do
7676 s <- execState (0::Int) $ do
7777 _ <- (evalState () action) `catchImpl` \U.Ex -> modify @Int (+4)
7878 modify @Int (+8)
7979 U.assertEqual (lib ++ " - state correctly updated") s 13
8080
81− action :: (State Int :> es, Except :> es) => Eff es ()
81+ action :: State Int :> es => Eff es ()
8282 action = do
8383 modify @Int (+1)
8484 _ <- E.throwM U.Ex