Add runFailIO

This commit is contained in:
Andrzej Rybczak 2022-01-12 23:56:13 +01:00
parent 5902cfe476
commit db61b5a324

View File

@ -2,11 +2,13 @@
module Effectful.Fail
( Fail(..)
, runFail
, runFailIO
) where
import Effectful.Dispatch.Dynamic
import Effectful.Error.Static
import Effectful.Internal.Monad
import Effectful.Internal.Monad (Fail(..))
import Effectful.Monad
-- | Run the 'Fail' effect via 'Error'.
runFail :: Eff (Fail : es) a -> Eff es (Either String a)
@ -14,3 +16,8 @@ runFail = reinterpret eff $ \_ -> \case
Fail msg -> throwError msg
where
eff = fmap (either (Left . snd) Right) . runError
-- | Run the 'Fail' effect by using the 'MonadFail' instance for 'IO'.
runFailIO :: IOE :> es => Eff (Fail : es) a -> Eff es a
runFailIO = interpret $ \_ -> \case
Fail msg -> liftIO $ fail msg