Skip to content

Add UnliftIO variant #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 10, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Better type signatures
  • Loading branch information
parsonsmatt committed Mar 9, 2022
commit 141c82b98ba78ce11913c860e0a1125ade4aac46
20 changes: 11 additions & 9 deletions src/Control/Exception/Annotated/UnliftIO.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# language ExplicitForAll #-}

-- | This module presents the same interface as
-- "Control.Exception.Annotated", but uses 'MonadUnliftIO' instead of
-- 'MonadCatch' or 'MonadThrow'.
Expand Down Expand Up @@ -58,28 +60,28 @@ import GHC.Stack
--
-- @since 0.1.2.0
throwWithCallStack
:: (MonadIO m, Exception e, HasCallStack)
:: forall e m a. (MonadIO m, Exception e, HasCallStack)
=> e -> m a
throwWithCallStack = liftIO . Catch.throwWithCallStack

-- | Like 'Catch.throw', but uses 'MonadIO' instead of 'MonadThrow'.
--
-- @since 0.1.2.0
throw :: (MonadIO m, Exception e) => e -> m a
throw :: forall e m a. (MonadIO m, Exception e) => e -> m a
throw = liftIO . Catch.throw

-- | Like 'Catch.checkpoint', but uses 'MonadUnliftIO' instead of 'MonadCatch'.
--
-- @since 0.1.2.0
checkpoint :: (MonadUnliftIO m) => Annotation -> m a -> m a
checkpoint :: forall m a. (MonadUnliftIO m) => Annotation -> m a -> m a
checkpoint ann action = withRunInIO $ \runInIO ->
liftIO $ Catch.checkpoint ann (runInIO action)

-- | Like 'Catch.checkpointMany', but uses 'MonadUnliftIO' instead of
-- 'MonadCatch'.
--
-- @since 0.1.2.0
checkpointMany :: (MonadUnliftIO m) => [Annotation] -> m a -> m a
checkpointMany :: forall m a. (MonadUnliftIO m) => [Annotation] -> m a -> m a
checkpointMany anns action =
withRunInIO $ \runInIO ->
liftIO $ Catch.checkpointMany anns (runInIO action)
Expand All @@ -89,7 +91,7 @@ checkpointMany anns action =
--
-- @since 0.1.2.0
checkpointCallStackWith
:: (MonadUnliftIO m, HasCallStack)
:: forall m a. (MonadUnliftIO m, HasCallStack)
=> [Annotation] -> m a -> m a
checkpointCallStackWith anns action =
withRunInIO $ \runInIO ->
Expand All @@ -99,7 +101,7 @@ checkpointCallStackWith anns action =
--
-- @since 0.1.2.0
catch
:: (MonadUnliftIO m, Exception e)
:: forall e m a. (MonadUnliftIO m, Exception e)
=> m a
-> (e -> m a)
-> m a
Expand All @@ -111,7 +113,7 @@ catch action handler =
--
-- @since 0.1.2.0
tryAnnotated
:: (MonadUnliftIO m, Exception e)
:: forall e m a. (MonadUnliftIO m, Exception e)
=> m a
-> m (Either (AnnotatedException e) a)
tryAnnotated action =
Expand All @@ -122,7 +124,7 @@ tryAnnotated action =
--
-- @since 0.1.2.0
try
:: (MonadUnliftIO m, Exception e)
:: forall e m a. (MonadUnliftIO m, Exception e)
=> m a
-> m (Either e a)
try action =
Expand All @@ -133,7 +135,7 @@ try action =
--
-- @since 0.1.2.0
catches
:: MonadUnliftIO m
:: forall m a. MonadUnliftIO m
=> m a
-> [Handler m a]
-> m a
Expand Down