Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
exceptions
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Glasgow Haskell Compiler
Packages
exceptions
Commits
1a312c87
Commit
1a312c87
authored
1 year ago
by
Janek Spaderna
Committed by
Ryan Scott
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix haddock markup in example code snippets
parent
94d5979b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Control/Monad/Catch.hs
+30
-34
30 additions, 34 deletions
src/Control/Monad/Catch.hs
with
30 additions
and
34 deletions
src/Control/Monad/Catch.hs
+
30
−
34
View file @
1a312c87
...
...
@@ -270,21 +270,19 @@ class MonadCatch m => MonadMask m where
-- this method. The @StateT@ implementation demonstrates most of the
-- subtleties:
--
-- @
-- generalBracket acquire release use = StateT $ \s0 -> do
-- ((b, _s2), (c, s3)) <- generalBracket
-- (runStateT acquire s0)
-- (\(resource, s1) exitCase -> case exitCase of
-- ExitCaseSuccess (b, s2) -> runStateT (release resource (ExitCaseSuccess b)) s2
--
-- -- In the two other cases, the base monad overrides @use@'s state
-- -- changes and the state reverts to @s1@.
-- ExitCaseException e -> runStateT (release resource (ExitCaseException e)) s1
-- ExitCaseAbort -> runStateT (release resource ExitCaseAbort) s1
-- )
-- (\(resource, s1) -> runStateT (use resource) s1)
-- return ((b, c), s3)
-- @
-- > generalBracket acquire release use = StateT $ \s0 -> do
-- > ((b, _s2), (c, s3)) <- generalBracket
-- > (runStateT acquire s0)
-- > (\(resource, s1) exitCase -> case exitCase of
-- > ExitCaseSuccess (b, s2) -> runStateT (release resource (ExitCaseSuccess b)) s2
-- >
-- > -- In the two other cases, the base monad overrides `use`'s state
-- > -- changes and the state reverts to `s1`.
-- > ExitCaseException e -> runStateT (release resource (ExitCaseException e)) s1
-- > ExitCaseAbort -> runStateT (release resource ExitCaseAbort) s1
-- > )
-- > (\(resource, s1) -> runStateT (use resource) s1)
-- > return ((b, c), s3)
--
-- The @StateT s m@ implementation of @generalBracket@ delegates to the @m@
-- implementation of @generalBracket@. The @acquire@, @use@, and @release@
...
...
@@ -318,25 +316,23 @@ class MonadCatch m => MonadMask m where
-- take priority. Here is an implementation for @ExceptT@ which demonstrates
-- how to do this.
--
-- @
-- generalBracket acquire release use = ExceptT $ do
-- (eb, ec) <- generalBracket
-- (runExceptT acquire)
-- (\eresource exitCase -> case eresource of
-- Left e -> return (Left e) -- nothing to release, acquire didn't succeed
-- Right resource -> case exitCase of
-- ExitCaseSuccess (Right b) -> runExceptT (release resource (ExitCaseSuccess b))
-- ExitCaseException e -> runExceptT (release resource (ExitCaseException e))
-- _ -> runExceptT (release resource ExitCaseAbort))
-- (either (return . Left) (runExceptT . use))
-- return $ do
-- -- The order in which we perform those two 'Either' effects determines
-- -- which error will win if they are both 'Left's. We want the error from
-- -- 'release' to win.
-- c <- ec
-- b <- eb
-- return (b, c)
-- @
-- > generalBracket acquire release use = ExceptT $ do
-- > (eb, ec) <- generalBracket
-- > (runExceptT acquire)
-- > (\eresource exitCase -> case eresource of
-- > Left e -> return (Left e) -- nothing to release, `acquire` didn't succeed
-- > Right resource -> case exitCase of
-- > ExitCaseSuccess (Right b) -> runExceptT (release resource (ExitCaseSuccess b))
-- > ExitCaseException e -> runExceptT (release resource (ExitCaseException e))
-- > _ -> runExceptT (release resource ExitCaseAbort))
-- > (either (return . Left) (runExceptT . use))
-- > return $ do
-- > -- The order in which we perform those two `Either` effects determines
-- > -- which error will win if they are both `Left`s. We want the error from
-- > -- `release` to win.
-- > c <- ec
-- > b <- eb
-- > return (b, c)
--
-- @since 0.9.0
generalBracket
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment