[Haskell-cafe] The implementation of Control.Exception.bracket
Leon Smith
leon.p.smith at gmail.com
Mon Jan 31 15:17:16 CET 2011
There is a common idiom used in Control.Concurrent libraries, as
embodied in the implementation of bracket:
http://www.haskell.org/ghc/docs/7.0-latest/html/libraries/base-4.3.0.0/src/Control-Exception-Base.html#bracket
bracket before after thing =
mask $ \restore -> do
a <- before
r <- restore (thing a) `onException` after a
_ <- after a
return r
Is there any particular reason why bracket is not implemented as:
bracket before after thing =
mask $ \restore -> do
a <- before
r <- restore (thing a) `finally` after a
return r
Is there some subtle semantic difference? Is there a performance
difference? It seems like a trivial thing, but I am genuinely
curious.
Best,
Leon
More information about the Haskell-Cafe
mailing list