Throwing an exception in STM without rolling back state?
Tom Ellis <[email protected]>
| Newsgroups | gmane.comp.lang.haskell.cafe |
|---|---|
| Message-ID | <Z2E3VxW3F3YQrDwL@cloudinit-builder> |
Dear Cafe,
Is it possible to throw an exception in STM without rolling back
state? (See program below for an demonstration that throwing an
exception does roll back state.)
I'm having a great deal of success using exceptions in my effect
system Bluefin, to simulate early return and jumps:
* https://hackage.haskell.org/package/bluefin-0.0.14.0/docs/Bluefin-EarlyReturn.html
* https://hackage.haskell.org/package/bluefin-0.0.14.0/docs/Bluefin-Jump.html
I'm interested in making a Bluefin interface to STM too, but the
value of that would be significantly diminished if all exceptions roll
back state.
Instead I would like to be able to say "throwing this exception
_shouldn't_ roll back state". Is that possible? If not in practice,
is it possible in theory, if I were to modify the RTS somehow?
Thanks,
Tom
{-# LANGUAGE GHC2021 #-}
import GHC.Conc
import GHC.Exception
data MyEx = MyEx deriving Show
instance Exception MyEx
-- > main
-- False
main = do
r <- atomically $ do
v <- newTVar False
catchSTM @MyEx
(do
writeTVar v True
-- same with throw MyEx`
throwSTM MyEx
)
(\_ -> pure ())
readTVar v
print r
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.