Final bikeshedding call: Fixing Control.Exception.bracket

Simon Marlow marlowsd at gmail.com
Thu Nov 13 10:44:07 UTC 2014


On 13/11/2014 07:47, Merijn Verstraaten wrote:
>
>> On 12 Nov 2014, at 23:33, Bardur Arantsson <spam at scientician.net> wrote:
>>
>> Is the code for this available for inspection somewhere? (I realize it
>> might change based on the outcome of this "poll", but...)
>
> There's no complete patch, but I believe the outline has been sketched before, anyway to repeat it. The current implementation of bracket is as follows:
>
> bracket
>          :: IO a
>          -> (a -> IO b)
>          -> (a -> IO c)
>          -> IO c
> bracket before after thing =
>    mask $ \restore -> do
>      a <- before
>      r <- restore (thing a) `onException` after a
>      _ <- after a
>      return r
>
> A new version would look like:
>
> bracket before after thing =
>    mask $ \restore -> do
>      let atomicAfter = uninterruptibleMask . after
>      a <- before
>      r <- restore (thing a) `onException` atomicAfter a
>      _ <- atomicAfter a
>      return r
>
> Slightly different versions are possible and the other relevant bracketing functions mentioned in this thread can be treated similarly.

Since we would need this for catch too, the sensible thing to do (if we 
decide to go ahead with this) would be to change the implementation of 
catch in the RTS from masking the exception handler to 
uninterruptibleMask.  That would mean that at least for catch there 
would be no additional overhead, and it would make the modifications to 
the other operations simpler in some cases.

Cheers,
Simon




More information about the Libraries mailing list