Proposal: Add throwSTM and generalize catchSTM
aslatter at gmail.com
Sun Sep 26 17:24:43 EDT 2010
On Sun, Sep 26, 2010 at 4:21 PM, Antoine Latter <aslatter at gmail.com> wrote:
> On Sun, Sep 26, 2010 at 3:09 PM, Maciej Piechotka <uzytkownik2 at gmail.com> wrote:
>> On Sun, 2010-09-26 at 15:46 -0400, Simon Marlow wrote:
>>> On 26/09/10 13:55, Bas van Dijk wrote:
>>> > On Sun, Sep 26, 2010 at 6:13 PM, Antoine Latter<aslatter at gmail.com> wrote:
>>> >> Your new catchSTM can be written from the old one:
>>> >>> newCatchSTM stm h = catchSTM stm (h . fromJust . fromException . toException)
>>> Agree in principle, but I don't think that implementation works, does
>>> it? If the exception is the wrong type, fromJust will throw an error,
>>> whereas you want to just re-throw the original exception.
>>> > I will make a patch out of this and attach it to the ticket. We'll see
>>> > what the GHC devs think of it.
>>> Fine by me.
>> newCatchSTM stm h
>> = catchSTM stm (\e -> maybe (throwSTM e) f $ fromException e)
> It also would work to copy the GHC.IO version:
>> unSTM (STM stm) = stm
>> catchSTM :: Exception e => STM a -> (e -> STM a) -> STM a
>> catchSTM (STM stm) handler
>> = STM $ catchSTM# stm handler'
>> where handler' e = case fromException e of
>> Just e' -> unSTM (handler e')
>> Nothing -> raiseIO# e
> Although the catchException in GHC.IO uses raise# instead of raiseIO#
> - that may be for a reason. I had thought they were really similar
> underneath the hood, though.
And Bas put that exact code in the ticket two hours ago :-)
So that's a +1 from me. It would be nice to get a Hackage analysis to
get an idea of what will break from this change.
More information about the Libraries